From 4fc968dcc403512220f98562872cd506b79e0545 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Mon, 23 Jun 2025 19:20:41 +0200 Subject: [PATCH] =?UTF-8?q?-=20[NEW]=20Comence=20a=20implementar=20enemics?= =?UTF-8?q?=20-=20[NEW]=20Sistema=20de=20IA=20b=C3=A0sica?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/animations.lua | 8 ++++ data/game.lua | 4 +- data/rooms_foreground.bin | Bin 905 -> 902 bytes data/sprites.lua | 79 ++++++++++++++++++++++++++++---------- 4 files changed, 70 insertions(+), 21 deletions(-) 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 cd8127479fb2125120b8142da6955736252d60ff..06f2c0fe3da5f4de6a96169089082227bfe0a455 100644 GIT binary patch delta 510 zcmV zmPzKBW}3<6M3_;v-;@|l*;HFfg&E$M7>!BOL|Y;mADkD-X=j}cRka_U6A3YdLVC_Q z(Vl-+u#ln?35t=U-yzx%pba(3kfHlUG$o}BY08kLpAH&orzL;nSpuXF&Hw3Uq?0b% zkfH%7imFAJdS_~_3}MzNO<45_rk_$uN)cvL78F2doE_TgvW%8MDrSk=nk+>U(lDim zS5*YAnA1i?L#ZWj2<>4p9X4)wQwDG@0Q1(nX$9|6ly9abU`x@M`$`mWcku>_Zx9j* zHZXT%`a2Q82seL}P(urEH)Vti*-P)K2e*6MLKSQG>%-|rY*EPBaVilF@{X!)MWm8z zQDbASTNpuaDogE@P((4s&p-zqbO1p29BxHMKQ}T&G?xHI7&8OV^V3IDMD=qjOXP6W zPaC~8L`gfhG*}!J9mUf^6CE}~S38%rL*05?LC-;39R_yYLr>ARbxUJw?9iBdQ#3Wy z!Ac!P$~yZk>fDE4)OF(vHHJ17lv6&%+RTj&5#WSZ1T@-23;nZ0fiHLQygGgT5a!Dv z+AU71liqoAZ!4s@ggpDqP}pH#9tGZ&2VZ&8tShJaL!39%_TEpIF1td`Cl?R^J5qGq AL;wH) delta 513 zcmV+c0{;Dm2Z;x;lL3EK?Fny#dH|C;XxSyx)p&N1V-?J2j;aDseA85`FedLJ`vt$0iZS&lv6&1Mc&HKU8{hai5F2giw~v(AQsI9!1$xR4#nwOS6ug<_~dR_(E^n{q*c^7Y_Y#0RaFz DIkMc- 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