[WIP] Treballant en el jefe. Moviment per patró assegurat

This commit is contained in:
2026-04-11 14:09:26 +02:00
parent 2e4453ecdb
commit acbf262ee3

View File

@@ -100,7 +100,9 @@ function imp.new(_hab, _x, _y)
pattern_movement=imp.pattern_movement, -- Pasar a mode de moviment per patró pattern_movement=imp.pattern_movement, -- Pasar a mode de moviment per patró
pattern_next_action=imp.pattern_next_action, -- Següent acció en mode pattern pattern_next_action=imp.pattern_next_action, -- Següent acció en mode pattern
pattern_next_target=imp.pattern_next_target, -- Següent target en mode pattern pattern_next_target=imp.pattern_next_target, -- Següent target en mode pattern
pattern_recovery=imp.pattern_recovery, -- Si per algun motiu perd el mode pattern recuperar-lo
-- Al afegir pattern_recovery el moviment lliure no te sentit (ni es gasta en este moment), se queda ara per si de cas
free_movement=imp.free_movement, -- Pasar a mode de moviment lliure free_movement=imp.free_movement, -- Pasar a mode de moviment lliure
free_next_action=imp.free_next_action, -- Següent acció en mode lliure free_next_action=imp.free_next_action, -- Següent acció en mode lliure
free_next_target=imp.free_next_target, -- Següent target en mode free free_next_target=imp.free_next_target, -- Següent target en mode free
@@ -137,8 +139,8 @@ if DEBUG_FN_NAME then print("fight") end
{next=4, actions= {{action="right" , event="land"}, {next=4, actions= {{action="right" , event="land"},
{action="left" , event="target"}}}, {action="left" , event="target"}}},
{next=4, actions= {{action="right" , event="prefall"}, {next=4, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"}, {action="jumpfwd", event="land"},
{action="left" , event="target"}}}, {action="left" , event="target"}}},
{next=10, actions= {{action="right" , event="prefall"}, {next=10, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"}, {action="jumpfwd", event="land"},
{action="right" , event="target"}}}, {action="right" , event="target"}}},
@@ -152,11 +154,11 @@ if DEBUG_FN_NAME then print("fight") end
{next=5, actions= {{action="right" , event="target"}}} {next=5, actions= {{action="right" , event="target"}}}
} }
self.paths[2] = { self.paths[2] = {
{next=3, actions={{action="left" , event="prefall"}, {next=3, actions= {{action="left" , event="prefall"},
{action="jumpfwd" , event="land"}, {action="jumpfwd", event="land"},
{action="left" , event="target"}}}, {action="left" , event="target"}}},
{next=6, actions={{action="left" , event="land"}, {next=6, actions= {{action="left" , event="land"},
{action="right" , event="target"}}}, {action="right" , event="target"}}},
{next=6, actions= {{action="left" , event="prefall"}, {next=6, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"}, {action="jumpfwd", event="land"},
{action="right" , event="target"}}}, {action="right" , event="target"}}},
@@ -170,7 +172,7 @@ if DEBUG_FN_NAME then print("fight") end
{action="jumpfwd", event="land"}, {action="jumpfwd", event="land"},
{action="left" , event="land"}, {action="left" , event="land"},
{action="right" , event="target"}}}, {action="right" , event="target"}}},
{next=5, actions={{action="left" , event="target"}}} {next=5, actions= {{action="left" , event="target"}}}
} }
self.paths[3] = { self.paths[3] = {
{next=1, actions={{action="left" , event="prefall"}, {next=1, actions={{action="left" , event="prefall"},
@@ -202,9 +204,9 @@ if DEBUG_FN_NAME then print("fight") end
} }
self.paths[6] = { self.paths[6] = {
{next=2, actions={{action="jump", event="target"}}}, {next=2, actions={{action="jump", event="target"}}},
{next=5, actions={{action="left", event="target"}}}, --{next=5, actions={{action="left", event="target"}}},
{next=7, actions={{action="jump", event="target"}}}, --{next=7, actions={{action="jump", event="target"}}},
{next=4, actions={{action="left", event="target"}}} --{next=4, actions={{action="left", event="target"}}}
} }
self.paths[7] = { self.paths[7] = {
{next=5, actions={{action="left" , event="prefall"}, {next=5, actions={{action="left" , event="prefall"},
@@ -240,7 +242,7 @@ if DEBUG_FN_NAME then print("fight") end
{action="jump" , event="target"}}}, {action="jump" , event="target"}}},
{next=6, actions={{action="right" , event="target"}}} {next=6, actions={{action="right" , event="target"}}}
} }
self.paths[11] = {} -- self.paths[11] = {}
self.fight_mode="chase" self.fight_mode="chase"
self:pattern_movement() self:pattern_movement()
@@ -568,6 +570,7 @@ if DEBUG_FN_NAME then print("pattern_next_action") end
-- print(" ACTION 2= "..action) -- print(" ACTION 2= "..action)
end end
end end
self.action_event = ""; -- Action_event processat
-- print(" ACTION ="..action) -- print(" ACTION ="..action)
return action return action
end end
@@ -580,6 +583,7 @@ if DEBUG_FN_NAME then print("pattern_next_target") end
self.path = self.paths[from][next_path_idx] self.path = self.paths[from][next_path_idx]
self.path_curr_action = 1 self.path_curr_action = 1
self.target = self.hot_points[self.path.next] self.target = self.hot_points[self.path.next]
print("Next pattern target => "..self.path.next)
end end
function imp:path_next_action( from ) function imp:path_next_action( from )
@@ -593,8 +597,9 @@ if DEBUG_FN_NAME then print("path_next_action "..from) end
action = self:path_action() action = self:path_action()
-- self.action_event="" -- self.action_event=""
else else
self:free_movement() -- self:free_movement()
action = self:next_action() -- action = self:next_action()
action = self:pattern_recovery()
end end
return action return action
end end
@@ -606,6 +611,49 @@ if DEBUG_FN_NAME then print("free_movement") end
print("Free") print("Free")
end end
function imp:pattern_recovery()
self:pattern_movement()
self:path_reset()
local x_after_4 = false
local x_after_5 = false
local x_after_6 = false
local y_upper_4 = false
local y_upper_5 = false
local y_upper_6 = false
if self.hot_points[4].x<self.x then x_after_4 = true end
if self.hot_points[5].x<self.x then x_after_5 = true end
if self.hot_points[6].x<self.x then x_after_6 = true end
if self.hot_points[4].y>self.y+self.h then y_upper_4 = true end
if self.hot_points[5].y>self.y+self.h then y_upper_5 = true end
if self.hot_points[6].y>self.y+self.h then y_upper_6 = true end
if not y_upper_5 then
-- target 5
self.target = self.hot_points[5]
if not x_after_5 then
-- right target
self.path = {next=5, actions={{action="right",event="target"}}}
else
-- left target
self.path = {next=5, actions={{action="left",event="target"}}}
end
else
if x_after_5 then
--target 4
self.target = self.hot_points[4]
-- left target
self.path = {next=4, actions={{action="left",event="target"}}}
else
--target 6
self.target = self.hot_points[6]
-- right target
self.path = {next=6, actions={{action="right",event="target"}}}
end
end
return self.path.actions[1].action
end
function imp:free_next_action() function imp:free_next_action()
if DEBUG_FN_NAME then print("free_next_action") end if DEBUG_FN_NAME then print("free_next_action") end
-- Moviment horitzontal -- Moviment horitzontal
@@ -900,9 +948,9 @@ end
function imp:next_target(from) function imp:next_target(from)
if self.movement_type=="free" then if self.movement_type=="free" then
action = self:free_next_target() self:free_next_target()
else else
action=self:pattern_next_target( from ) self:pattern_next_target( from )
end end
-- seleccionar mode d'acció -- seleccionar mode d'acció
@@ -938,8 +986,11 @@ if DEBUG_FN_NAME then print("move "..self.fight_mode) end
-- Seleccionar el següent target aleatoriament -- Seleccionar el següent target aleatoriament
self:next_target() self:next_target()
print("Next random target => "..self.target.id) print("Next random target => "..self.target.id)
-- Intentar recuperar el mode per patró
self:pattern_recovery()
end end
if self.flip_wait<=0 then if self.flip_wait<=0 then
@@ -961,7 +1012,6 @@ if DEBUG_FN_NAME then print("move "..self.fight_mode) end
end end
self.action = action self.action = action
self.action_event = ""
return action return action