From 7090a6134f09ad67b930fcd4a0d9b8db90d56361 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Mon, 23 Mar 2026 12:17:05 +0100 Subject: [PATCH] - [NEW] Quan li peguen, Morcus pega un botet cap enrere - [NEW] Quan peguen a l'heroi, la momia i la rata peguen la volta --- data/modules/ia/hero.lua | 33 ++++++++++++++++++++++++++++++++- data/modules/ia/mummy.lua | 1 + data/modules/ia/rata.lua | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/data/modules/ia/hero.lua b/data/modules/ia/hero.lua index 29061b4..e21dc9c 100644 --- a/data/modules/ia/hero.lua +++ b/data/modules/ia/hero.lua @@ -49,6 +49,33 @@ function ia.update_hero() end end + -- Si li han pegat... + if sprites.hero.has_been_hit then + if sprites.hero.flipped then + local tx, ty = (sprites.hero.pos.x+3)>>3, (sprites.hero.pos.y+16)>>3 + if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 then + if tx>3, (sprites.hero.pos.y+16)>>3 + if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 then + if tx>rooms.pos.x+19 then + game.change_room(1,0) + else + sprites.hero.pos.x = sprites.hero.pos.x - 1 + end + end + end + sprites.hero.has_been_hit = sprites.hero.has_been_hit - 1 + if sprites.hero.has_been_hit == 0 then + sprites.hero.has_been_hit = nil; + end + end + -- si està en l'animació de disparar, no podem fer res i eixim ja if sprites.hero.shooting then -- A no ser que siga l'ultim frame, en tal cas tornem a estar de peu i au @@ -165,7 +192,7 @@ function ia.update_hero() end end -- ESTIGA COM ESTIGA, SI POLSA ESQUERRA O DRETA... - if not sprites.hero.shooting then + if not sprites.hero.shooting and not sprites.hero.has_been_hit then if key.down(key.LEFT) or pad.down(pad.LEFT) then sprites.hero.flipped = true anim = move_anim @@ -221,6 +248,10 @@ function ia.hero_hit(live) elseif sprites.hero.lives < 4 then sprites.hero.state = templates.DYING sprites.hero.cooldown = 60 + sprites.hero.shooting = false + sprites.set_animation(sprites.hero, "hero_stand") + sprites.hero.jumping = 8 + sprites.hero.has_been_hit = 16 end end diff --git a/data/modules/ia/mummy.lua b/data/modules/ia/mummy.lua index 1471e6a..17751b2 100644 --- a/data/modules/ia/mummy.lua +++ b/data/modules/ia/mummy.lua @@ -8,6 +8,7 @@ function ia.update_mummy(spr) -- Si toca al heroi... if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then sprites.hero.hit() + spr.flipped = not spr.flipped end end diff --git a/data/modules/ia/rata.lua b/data/modules/ia/rata.lua index f4ff14d..48851fe 100644 --- a/data/modules/ia/rata.lua +++ b/data/modules/ia/rata.lua @@ -7,6 +7,7 @@ function ia.update_rata(spr) -- Si toca al heroi... if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then sprites.hero.hit() + spr.flipped = not spr.flipped end end