From 5622392f4145958c2c06369f13885252d26159fa Mon Sep 17 00:00:00 2001 From: JailGamer Date: Sun, 19 Apr 2026 15:56:33 +0200 Subject: [PATCH] [WIP] Treballant en el jefe. Implementant chase i avoid --- data/abad.lua | 2 +- data/imp3-functions.lua | 36 ++++++++++++++++++++------- data/imp3.lua | 17 +++++++------ data/main.lua | 1 + data/pattern.lua | 55 +++++++++++++++++++++++++++++++++++++++-- data/stage1.lua | 3 +++ 6 files changed, 94 insertions(+), 20 deletions(-) diff --git a/data/abad.lua b/data/abad.lua index 7a177d3..a90d81e 100644 --- a/data/abad.lua +++ b/data/abad.lua @@ -133,7 +133,7 @@ end function abad_hurt(howmuch) - -- howmuch = 0 + howmuch = 0 if abad.hurting == 0 and abad.respawning==0 then sound.play(audio_abad_hit) abad.energia=abad.energia-howmuch diff --git a/data/imp3-functions.lua b/data/imp3-functions.lua index 8542e56..f9eb7e8 100644 --- a/data/imp3-functions.lua +++ b/data/imp3-functions.lua @@ -15,7 +15,7 @@ end -- ------------------------------- function imp:reduce_timers() - if self.mood==self.moods.stop then return end + if self.mood=="stop" then return end if DEBUG_FN_NAME then print_dbg("reduce_timers") end for key, val in pairs(self.timers) do @@ -37,13 +37,13 @@ end -- ------------------------------- function imp:reset_timer( timer ) - if self.mood == self.moods.stop then return end + if self.mood == "stop" then return end if DEBUG_FN_NAME then print_dbg("reduce_timers") end local time = 0 if timer=="mood" then time = 150 elseif timer=="target" then time = 350 elseif timer=="shot" then time = 100 - elseif timer=="super" then time = 200 + elseif timer=="super" then time = 600 elseif timer=="super_wait" then time = 200 elseif timer=="flip_wait" then time = 50 end @@ -55,7 +55,7 @@ end -- ------------------------------- function imp:analyze_env() --OK - if self.mood==self.moods.stop then return end + if self.mood=="stop" then return end if DEBUG_FN_NAME then print_dbg("analyze_env") end -- Distancia fins a l'abad local r = distancia(self,abad) @@ -180,10 +180,10 @@ end -- ------------------------------- function imp:choose_action() -- antic imp:move -if DEBUG_FN_NAME then print_dbg("choose_action "..self.mood.." / "..self.moods.stop) end - -- if self.mood==self.moods.stop then return self.mood end +if DEBUG_FN_NAME then print_dbg("choose_action "..self.mood.." / ".."stop") end + -- if self.mood=="stop" then return self.mood end -- Si no te ganes de fer res, no moure - if self.mood==self.moods.stop then return self.actions.no_action end + if self.mood=="stop" then return self.actions.no_action end local next_action = self:next_action() @@ -513,6 +513,14 @@ function imp:next_action() next_action = "shot" end + -- anar a fer el super + if self.timers.super<=0 then + self.pattern:set_target_mode(PATTERN_CHASE,self.pattern.node[1]) + else + self.pattern:set_target_mode(self.mood,abad) + end + + -- fer el super if self.timers.super<=0 and self:check_action_event("super_ready") then if self.xmax_distance then + max_distance = d + next_target_max = k + end + if min_distance==-1 and d>=0 then min_distance=d+1 end + if d=0 then + min_distance = d + next_target_min = k + end + end + -- asignar target segons el mode + if self.target_mode==PATTERN_CHASE then + self.target_idx = next_target_min + elseif self.target_mode==PATTERN_AVOID then + self.target_idx = next_target_max + else + self.target_idx = math.random(#self.path[self.path_idx]) + end + + end + self.action_idx = 1 end diff --git a/data/stage1.lua b/data/stage1.lua index 6a937cd..ae248ea 100644 --- a/data/stage1.lua +++ b/data/stage1.lua @@ -66,6 +66,9 @@ function stages.stage1_init() table.insert( actors, caco.new(61,3,2,false) ) table.insert( actors, zombie.new(2, 3, 3,false) ) + table.insert( actors, zombie.new(2, 4, 3,true) ) + table.insert( actors, zombie.new(2, 5, 3,false) ) + table.insert( actors, zombie.new(3, 3, 3,true) ) table.insert( actors, zombie.new(28, 3, 3,false) ) table.insert( actors, zombie.new(32, 3, 3,false) ) table.insert( actors, zombie.new(44, 3, 3,false) )