[WIP] Treballant en el jefe. Pareix que se va aclarint, pareix

This commit is contained in:
2026-04-16 22:27:13 +02:00
parent 1b812127e2
commit 956603b99c
4 changed files with 74 additions and 33 deletions

View File

@@ -11,6 +11,13 @@ function distancia(a, b)
return r
end
function in_table(tabla, valor)
for _, v in ipairs(tabla) do
if v == valor then return true end
end
return false
end
function collision(a, b)
return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x)
and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w)

View File

@@ -100,8 +100,8 @@ if DEBUG_FN_NAME then print_dbg("choose_action "..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.analisis.going_to_fall then self.action_event="prefall" end
if self.analisis.target_reached then self.action_event="target" end
if self.analisis.going_to_fall then table.insert(self.action_event, "prefall") end
-- if self.analisis.target_reached then self.action_event="target" end
if self.analisis.can_go_altar then self:super_ready() end
-- if self.fight_mode == self.fight_modes["super"] then self.action_event="super" end
-- if self.fight_mode == self.fight_modes["end_super"] then self.action_event="end_super" end
@@ -110,7 +110,7 @@ if DEBUG_FN_NAME then print_dbg("choose_action "..self.mood) end
if self.analisis.target_reached and next_action=="super" then
-- print("Super READY!")
self.action_event = "super_ready"
table.insert(self.action_event, "super_ready")
-- next_action = self:next_action()
self:super()
end
@@ -144,7 +144,7 @@ if DEBUG_FN_NAME then print_dbg("controller_input") end
self.moure~=imp.state_super) and self.action == self.actions.jump then
self:do_jump()
elseif (self.moure~=imp.state_falling and self.moure~=imp.state_jumping and
self.moure~=imp.state_super) and self.action == "jumpfwd" then
self.moure~=imp.state_super) and self.action == self.actions.jumpfwd then
self:do_jump(true)
elseif self.action == self.actions.shot then
self:shot()
@@ -153,6 +153,7 @@ if DEBUG_FN_NAME then print_dbg("controller_input") end
self.moure=imp.state_super
end
self.action = self.actions.no_action
self.action_event = {}
end
-------------------------------
@@ -176,8 +177,8 @@ end
--
-------------------------------
function imp:create_hot_points() --OK
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[1] = point.new(44, 6, 3, 0, 0,"P1")
self.pattern.node[2] = point.new(45, 7, 3, 0, 0,"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")
@@ -284,7 +285,7 @@ function imp:load_pattern_paths() --OK
{target=5, actions={{action="right" , event="prefall"},
{action="jumpfwd" , event="land"},
{action="right" , event="target"}}},
{target=9, actions={{action="right" , event="prefall"},
{target=9, actions={{action="right" , event="land"},
{action="jumpfwd" , event="land"},
{action="right" , event="target"}}},
{target=1, actions={{action="jump" , event="target"}}}
@@ -338,9 +339,13 @@ function imp:next_action()
-- Resta d'accions
if next_action==self.actions.no_action then
if self.move_type==self.move_types.free then
-- FREE
-- next_action = self:free_next_action()
elseif self.move_type==self.move_types.pattern then
if self.pattern:in_target(self) then
-- PATTERN
local in_target = self.pattern:in_target(self)
local action_event_done = in_table(self.action_event, self.pattern:event())
if in_target or action_event_done then
next_action=self.pattern:next_action()
print("TARGET => "..next_action)
else
@@ -348,6 +353,7 @@ function imp:next_action()
print("ON WAY => "..next_action)
end
elseif self.move_type==self.move_types.super then
-- SUPER
--
end
end
@@ -483,7 +489,7 @@ if DEBUG_FN_NAME then print_dbg("state_falling") end
self:_moure(imp.state_normal,"state_normal (states)")
return
end
print_dbg("FALLING!")
-- print_dbg("FALLING!")
-- Seguir caiguent
self.y=self.y+1
self.jump_height = self.jump_height-1
@@ -515,9 +521,9 @@ if DEBUG_FN_NAME then print_dbg("land") end
if can_land then
self.jump_in_half_block_used = false
self.jump_height = 0
self.action_event = "land"
table.insert(self.action_event, "land")
end
if can_land then print_dbg ("LANDED") end
-- if can_land then print_dbg ("LANDED") end
return can_land
end

View File

@@ -9,7 +9,7 @@ require "pattern"
imp = {}
DEBUG_FN_NAME = true
DEBUG_FN_NAME = false
function imp.new(_hab,_x,_y)
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
@@ -29,7 +29,7 @@ function imp.new(_hab,_x,_y)
timers={mood=150,target=250, shot=2500, super=20000, flip_wait=50}, --anterior *_cooldown
move_types={free=0, pattern=1, super=2},
move_type=1, -- anterior movement_type
actions={no_action=0, up=1, down=2, left=4, right=8, jump=16, shot=32, super=64},
actions={no_action=0, up=1, down=2, left=4, right=8, jump=16, shot=32, super=64, jumpfwd=128},
pattern= pattern.new(),
analisis = {}, -- memoria per a guardar el resultat de l'analisis
step_length=1,
@@ -39,6 +39,7 @@ function imp.new(_hab,_x,_y)
max_jump_height=24,
vmove_space = 1,
falling = 0,
action_event = {},
--
moure = noop,
draw=imp.draw,
@@ -63,6 +64,7 @@ function imp.new(_hab,_x,_y)
end
function imp:draw() --OK
self.pattern:draw()
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
-- Modo super
@@ -126,17 +128,13 @@ function imp:update_hit()
if not self.enabled then return end
-- Que pasa quan "mor"
end
cpu_wait = 10
function imp:update_normal()
cpu_wait = cpu_wait -1
if cpu_wait<=0 then
print("-------------------------------------------------")
print("")
-- 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
-- print("TARGET TIMER= "..self.timers.target)
cpu_wait = 1
self:reduce_timers()
-- Ajustar mood (emocions)
@@ -160,6 +158,5 @@ print("")
-- colisions en personatges
-- self:colisions()
end
end
require "imp3-functions"

View File

@@ -17,10 +17,30 @@ function pattern.new()
action = pattern.action,
event = pattern.event,
actions = pattern.actions,
recovery = pattern.recovery
recovery = pattern.recovery,
draw = pattern.draw,
collision = pattern.collision,
}
end
function pattern:draw()
local scr_x = 0
local scr_y = 0
local target = self:target()
for k, v in pairs(self.node) do
scr_x, scr_y = viewp:screen_coords( v.x, v.y )
if self.path_idx==k or target==k then
draw.rectf(scr_x, scr_y, 16, 16, 3)
else
draw.rectf(scr_x, scr_y, 16, 16, 16)
draw.rect(scr_x, scr_y, 16, 16, 3)
end
if target ~= nil and target==k then
draw.rectf(scr_x, scr_y, 16, 16, 2)
end
draw.text(k, scr_x+4, scr_y+4, 14)
end
end
-- Necessite saber quina estrategia aplicar abans de moure al següent target
-- ara aleatori
@@ -51,13 +71,16 @@ end
-- end
function pattern:target()
if not empty_table(self.manual_path) then
print_dbg("MANUAL => "..self.manual_path.target)
-- print_dbg("MANUAL => "..self.manual_path.target)
return self.manual_path.target
else
print_dbg("PATH => "..self.path[self.path_idx][self.target_idx].target)
if #self.path>0 then
-- print_dbg("PATH => "..self.path[self.path_idx][self.target_idx].target)
return self.path[self.path_idx][self.target_idx].target
end
end
return nil
end
-- [OK] Torna la llista d'accions actual
-- function pattern:get_actions ( )
@@ -78,17 +101,17 @@ end
-- end
function pattern:action()
if not empty_table(self.manual_path) then
print_dbg("MANUAL => "..self.manual_path.actions[self.action_idx].action)
-- print_dbg("MANUAL => "..self.manual_path.actions[self.action_idx].action)
return self.manual_path.actions[self.action_idx].action
else
print_dbg("PATH => "..self.path[self.path_idx][self.target_idx].actions[self.action_idx].action)
-- print_dbg("PATH => "..self.path[self.path_idx][self.target_idx].actions[self.action_idx].action)
return self.path[self.path_idx][self.target_idx].actions[self.action_idx].action
end
end
-- [OK] Torna l'event actual
function pattern:event()
print_dbg("")
-- print_dbg("")
if not empty_table(self.manual_path) then
return self.manual_path.actions[self.action_idx].event
else
@@ -142,20 +165,28 @@ end
-- [OK] Torna el node del target actual
function pattern:target_node()
print_dbg(self.node[self:target()])
-- print_dbg(self.node[self:target()])
return self.node[self:target()]
end
-- Comprova si point ha arribat al target (Afegir precissio per si volem que estiga nomes tocar, dins o abans d'eixir?)
function pattern:in_target( area )
if collision( area, self:target_node() ) then
print_dbg("COLLISION")
else
print_dbg("-")
end
return collision( area, self:target_node() )
function pattern:in_target( a )
--if collision( a, self:target_node() ) then
-- print_dbg("COLLISION")
--else
-- print_dbg("-")
--end
return self:collision( a )
end
function pattern:recovery( point, target)
print_dbg("")
end
function pattern:collision( a )
local b = self:target_node()
return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x)
and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w)
and (a.y+a.bb.y+a.bb.h >= b.y+b.bb.y)
and (a.y+a.bb.y+a.bb.h == b.y+b.bb.y+b.bb.h) -- part de baix dels dos
end