diff --git a/data/animations.lua b/data/animations.lua index 823bc6a..2d2be1a 100644 --- a/data/animations.lua +++ b/data/animations.lua @@ -33,4 +33,12 @@ animations = { { frame={x=48,y=0,w=16,h=17}, wait=4, reversed=true } } }, + ["mummy_walk"] = { + cycle = {1,2,1,3}, + frames = { + { frame={x=0,y=24,w=16,h=17}, wait=4 }, + { frame={x=16,y=24,w=16,h=17}, wait=4 }, + { frame={x=32,y=24,w=16,h=17}, wait=4 } + } + }, } \ No newline at end of file diff --git a/data/game.lua b/data/game.lua index 0b6b64d..da7504d 100644 --- a/data/game.lua +++ b/data/game.lua @@ -18,7 +18,7 @@ game = { -- Pintar el mapa i sprites rooms.draw() sprites.update() - sprites.update_hero() + --sprites.update_hero() if key.press(key.ESCAPE) or key.press(key.F9) then editor.enable() @@ -29,6 +29,7 @@ game = { game.chg_adv.x = x game.chg_adv.y = y game.chg_step = 8 + sprites.pause_ia = true app.push(game.update_change_room) end, @@ -48,6 +49,7 @@ game = { sprites.update() game.chg_step = game.chg_step - 1 if game.chg_step == 0 then + sprites.pause_ia = false app.pop() end end diff --git a/data/rooms_foreground.bin b/data/rooms_foreground.bin index cd81274..06f2c0f 100644 Binary files a/data/rooms_foreground.bin and b/data/rooms_foreground.bin differ diff --git a/data/sprites.lua b/data/sprites.lua index b2d90e4..5be3bc1 100644 --- a/data/sprites.lua +++ b/data/sprites.lua @@ -3,19 +3,32 @@ require "animations" sprites = { hero = nil, list = {}, + pause_ia = false, init = function() sprites.hero = { pos = { x=28, y=4*12*8+71 }, size= { w=16, h=17 }, bbo = { left=0, top=0, right=0, bottom=0 }, - flipped = false, - jumping = 0, - animation = "hero_stand", - stairs = false, current_frame = 1, - current_wait = 1 + current_wait = 1, + flipped = false, + animation = "hero_stand", + ia = sprites.update_hero, + jumping = 0, + stairs = false } + local mummy = { + pos = { x=100, y=4*12*8+71 }, + size = { w=16,h=17 }, + bbo = { left=0, top=0, right=0, bottom=0 }, + current_frame = 1, + current_wait = 1, + flipped = true, + animation = "mummy_walk", + ia = sprites.update_mummy + } + table.insert(sprites.list, mummy) end, set_animation=function(sprite, animation) @@ -35,27 +48,51 @@ sprites = { end, update = function() + if not sys.beat() then return end sprites.update_sprite(sprites.hero) + for i,v in ipairs(sprites.list) do + sprites.update_sprite(v) + end + if not sprites.pause_ia then + sprites.hero.ia() + for i,v in ipairs(sprites.list) do + v.ia(v) + end + end end, update_sprite = function(sprite) - if sys.beat() then - sprite.current_wait = sprite.current_wait - 1 - if sprite.current_wait == 0 then - if sprite.current_frame < #animations[sprite.animation].cycle then - sprite.current_frame = sprite.current_frame + 1 - else - sprite.current_frame = 1 - end - local cycle = animations[sprite.animation].cycle[sprite.current_frame] - sprite.current_wait = animations[sprite.animation].frames[cycle].wait + sprite.current_wait = sprite.current_wait - 1 + if sprite.current_wait == 0 then + if sprite.current_frame < #animations[sprite.animation].cycle then + sprite.current_frame = sprite.current_frame + 1 + else + sprite.current_frame = 1 + end + local cycle = animations[sprite.animation].cycle[sprite.current_frame] + sprite.current_wait = animations[sprite.animation].frames[cycle].wait + end + end, + + update_mummy = function(spr) + if spr.flipped then + local tx, ty = (spr.pos.x+3)>>3, (spr.pos.y+16)>>3 + if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 and map.tile(tx,ty+1) > 0 then + spr.pos.x = spr.pos.x - 1 + else + spr.flipped = not spr.flipped + end + else + local tx, ty = (spr.pos.x+12)>>3, (spr.pos.y+16)>>3 + if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 and map.tile(tx,ty+1) > 0 then + spr.pos.x = spr.pos.x + 1 + else + spr.flipped = not spr.flipped end end end, update_hero = function() - if not sys.beat() then return end - -- Update hero local anim = "hero_stand" local move_anim = "hero_walk" @@ -68,7 +105,7 @@ sprites = { --draw.rect(tx1<<3,ty<<3,8,8,8) --draw.rect(tx2<<3,ty<<3,8,8,28) if map.tile(tx1,ty) == 0 and map.tile(tx2,ty) == 0 then - if ty 1 then sprites.hero.pos.y = sprites.hero.pos.y - 1 end @@ -87,7 +124,7 @@ sprites = { anim = move_anim local tx1, tx2, ty = (sprites.hero.pos.x+4)>>3, (sprites.hero.pos.x+11)>>3, (sprites.hero.pos.y)>>3 if map.tile(tx1,ty) < 16 or map.tile(tx2,ty) < 16 then - if ty