[WIP] Treballant en el jefe. Separat el 'motor' de moviment per patró

This commit is contained in:
2026-04-14 23:41:34 +02:00
parent d477988d10
commit 0c9c31dca2
4 changed files with 234 additions and 56 deletions

View File

@@ -1,3 +1,5 @@
require "pattern"
imp = {}
local DEBUG_FN_NAME = false
@@ -163,19 +165,23 @@ function imp.new(_hab,_x,_y)
timers={mood=150,target=150, shot=2500, super=20000, flip_wait=50}, --anterior *_cooldown
move_types={free=0, pattern=1, super=2},
move_type=1, -- anterior movement_type
paths={}, -- Llista de "camins" a fer des d'un hot_point
-- paths_active = 0, -- Número de path seleccionat
pattern={}, -- Instruccions per a moviment per patró, anterior path
pattern_point=1, -- anterior path_curr_action
target={}, -- Punt al que anar
-- hot_points={}, -- llista de punts del mapa on anar
-- paths={}, -- Llista de "camins" a fer des d'un hot_point
-- -- paths_active = 0, -- Número de path seleccionat
-- pattern={}, -- Instruccions per a moviment per patró, anterior path
-- pattern_point=1, -- anterior path_curr_action
-- target={}, -- Punt al que anar
shot_target=nil, -- a qui disparar
analisis = {}, -- memoria per a guardar el resultat de l'analisis
hot_points={}, -- llista de punts del mapa on anar
step_length=1,
falling = 0,
action_event="", -- Event d'acció que ha passat
jump_height=0,
max_jump_height=24,
pattern= pattern.new(),
vmove_space = 1,
-- funcions
next_frame = imp.staying_next_frame, -- funcio de seleccio del frame
choose_mood = imp.choose_mood,
@@ -207,6 +213,7 @@ function imp.new(_hab,_x,_y)
land = imp.land,
shot = imp.shot,
advance=imp.advance,
jump=imp.jump,
_moure=imp._moure, -- temporal debug
}
@@ -280,12 +287,12 @@ end
function imp:update_normal()
print("-------------------------------------------------")
print("")
if self.pattern.target then print("TARGET= "..self.pattern.target) end
if self.pattern.target then print("ACTIONS= "..#self.pattern.actions) end
--self:reduce_timers()
if self.mood~=self.moods.stop then print("TARGET= "..self.pattern:target()) end
if self.mood~=self.moods.stop then print("ACTIONS= "..#self.pattern:actions()) end
self:reduce_timers()
-- Ajustar mood (emocions)
--self:choose_mood()
self:choose_mood()
-- analisis
self:analyze_env()
@@ -299,10 +306,10 @@ if self.pattern.target then print("ACTIONS= "..#self.pattern.actions) end
self:moure()
-- Logica per a selecció de frame
--self:next_frame()
-- self:next_frame()
-- colisions en personatges
--self:colisions()
-- self:colisions()
end
-- imp.next_frame()
@@ -435,9 +442,11 @@ if DEBUG_FN_NAME then print("analyze_env") end
-- Ha arribat a destí
self.analisis.target_reached = false
if not empty_table(self.target) then
print("TARGET= "..self.pattern:target())
if not empty_table(self.pattern:target_node()) then
-- Target reached
if collision(self, self.target) then self.analisis.target_reached=true end
if self.pattern:in_target(self) then self.analisis.target_reached=true end
-- if collision(self, self.pattern:target_node()) then self.analisis.target_reached=true end
end
end
@@ -468,23 +477,23 @@ if not DEBUG_FN_NAME then print("pattern_get_next_path") end
end
function imp:create_hot_points() --OK
self.hot_points[1] = point.new(44, 5, 1, 0, 8,"P1")
self.hot_points[2] = point.new(45, 8, 1, 0, 8,"P2")
self.hot_points[3] = point.new(44,12, 5, 8, 0,"P3")
self.hot_points[4] = point.new(54, 5, 4, -8, 0,"P4")
self.hot_points[5] = point.new(54,12, 4, 8, 0,"P5")
self.hot_points[6] = point.new(55, 8, 4, 8, 0,"P6")
self.hot_points[7] = point.new(55, 8, 0, 0, 0,"P7")
self.hot_points[8] = point.new(54, 5, 0, 0, 0,"P8")
self.hot_points[9] = point.new(54, 9, 1, 0, 0,"P9")
self.hot_points[10] = point.new(55,4, 1, 0, 0,"P10")
self.pattern.node[1] = point.new(44, 5, 1, 0, 8,"P1")
self.pattern.node[2] = point.new(45, 8, 1, 0, 8,"P2")
self.pattern.node[3] = point.new(44,12, 5, 8, 0,"P3")
self.pattern.node[4] = point.new(54, 5, 4, -8, 0,"P4")
self.pattern.node[5] = point.new(54,12, 4, 8, 0,"P5")
self.pattern.node[6] = point.new(55, 8, 4, 8, 0,"P6")
self.pattern.node[7] = point.new(55, 8, 0, 0, 0,"P7")
self.pattern.node[8] = point.new(54, 5, 0, 0, 0,"P8")
self.pattern.node[9] = point.new(54, 9, 1, 0, 0,"P9")
self.pattern.node[10] = point.new(55, 4, 1, 0, 0,"P10")
-- self.hot_points[11] = abad
-- self.hot_points[11] = point.new(45, 1, 5, 8, 0,"altar-R")
-- self.hot_points[12] = point.new(44,11, 5, 0, 0,"altar-L")
end
function imp:load_pattern_paths() --OK
self.paths[1] = {
self.pattern.path[1] = {
{target=3, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="target"}}},
@@ -505,7 +514,7 @@ function imp:load_pattern_paths() --OK
{action="left" , event="target"}}},
{target=5, actions= {{action="right" , event="target"}}}
}
self.paths[2] = {
self.pattern.path[2] = {
{target=3, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
@@ -526,7 +535,7 @@ function imp:load_pattern_paths() --OK
{action="right" , event="target"}}},
{target=5, actions= {{action="left" , event="target"}}}
}
self.paths[3] = {
self.pattern.path[3] = {
{target=1, actions={{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="prefall"},
@@ -544,23 +553,23 @@ function imp:load_pattern_paths() --OK
{target=6, actions={{action="left" , event="land"},
{action="right" , event="target"}}}
}
self.paths[4] = {
self.pattern.path[4] = {
{target=1, actions={{action="jump" , event="target"}}},
{target=5, actions={{action="right", event="target"}}},
{target=6, actions={{action="right", event="target"}}},
{target=8, actions={{action="jump" , event="target"}}},
}
self.paths[5] = {
self.pattern.path[5] = {
{target=4, actions={{action="left" , event="target"}}},
{target=6, actions={{action="right", event="target"}}}
}
self.paths[6] = {
self.pattern.path[6] = {
{target=2, actions={{action="jump", event="target"}}},
{target=5, actions={{action="left", event="target"}}},
{target=7, actions={{action="jump", event="target"}}},
{target=4, actions={{action="left", event="target"}}}
}
self.paths[7] = {
self.pattern.path[7] = {
{target=5, actions={{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
@@ -569,7 +578,7 @@ function imp:load_pattern_paths() --OK
{action="left" , event="target"}}},
{target=2, actions={{action="jump" , event="target"}}}
}
self.paths[8] = {
self.pattern.path[8] = {
{target=5, actions={{action="right" , event="prefall"},
{action="jumpfwd" , event="land"},
{action="right" , event="target"}}},
@@ -578,7 +587,7 @@ function imp:load_pattern_paths() --OK
{action="right" , event="target"}}},
{target=1, actions={{action="jump" , event="target"}}}
}
self.paths[9] = {
self.pattern.path[9] = {
{target=5, actions={{action="right" , event="target"}}},
{target=1, actions={{action="left" , event="prefall"},
{action="jumpfwd" , event="land"},
@@ -586,7 +595,7 @@ function imp:load_pattern_paths() --OK
{action="jump" , event="target"}}},
{target=4, actions={{action="left" , event="target"}}}
}
self.paths[10] = {
self.pattern.path[10] = {
{target=5, actions={{action="left" , event="target"}}},
{target=2, actions={{action="right" , event="prefall"},
{action="jumpfwd" , event="land"},
@@ -594,10 +603,10 @@ function imp:load_pattern_paths() --OK
{action="jump" , event="target"}}},
{target=6, actions={{action="right" , event="target"}}}
}
self.paths[11] = {
self.pattern.path[11] = {
{target=4, actions={{action="left", event="target"}}}
}
self.paths[12] = {
self.pattern.path[12] = {
{target=6, actions={{action="right", event="target"}}}
}
@@ -608,9 +617,9 @@ if DEBUG_FN_NAME then print("fight") end
self:create_hot_points()
self:load_pattern_paths()
self.target = self.hot_points[6]
self.pattern = {target=6, actions={{action="right",event="target"}}}
print("imp2.lua -> #self.pattern.actions= "..#self.pattern.actions)
self.pattern.manual_target = self.pattern.node[6]
self.pattern.manual_path = {target=6, actions={{action="right",event="target"}}}
self.shot_target = abad
self.mood=self.moods.chase