[WIP] Treballant en el jefe. Arreglos de codi
This commit is contained in:
241
data/imp.lua
241
data/imp.lua
@@ -38,67 +38,75 @@ function imp.new(_hab, _x, _y)
|
|||||||
jump_height=0,
|
jump_height=0,
|
||||||
jump_in_half_block=0,
|
jump_in_half_block=0,
|
||||||
jump_in_half_block_used = false,
|
jump_in_half_block_used = false,
|
||||||
max_shoot_cooldown=24,
|
-- max_shoot_cooldown=24,
|
||||||
shot_power=1,
|
shot_power=1,
|
||||||
shot_num_shots=1,
|
shot_num_shots=1,
|
||||||
shoot_cooldown=25,
|
shoot_cooldown=25,
|
||||||
anim={28,29,28,30},
|
anim={28,29,28,30},
|
||||||
bb={x=8,y=0,w=16,h=32},
|
bb={x=8,y=0,w=16,h=32},
|
||||||
scene_intro=false,
|
-- scene_intro=false,
|
||||||
scene_object=false,
|
-- scene_object=false,
|
||||||
fight_modes=_fight_modes,
|
|
||||||
mode="stop",
|
|
||||||
mode_cooldown=500,
|
|
||||||
super_cooldown=2000,
|
|
||||||
shot_cooldown=500,
|
|
||||||
action="",
|
|
||||||
movement="",
|
|
||||||
movement_type="",
|
|
||||||
enabled=true,
|
enabled=true,
|
||||||
disable_reason="",
|
disable_reason="",
|
||||||
can_warp=false,
|
can_warp=false,
|
||||||
fight=imp.fight,
|
-- Atributs de jefe
|
||||||
draw=imp.draw,
|
movement_type="", -- Mode de moviment {pattern, free}
|
||||||
hit=imp.hit,
|
action="", -- Acció a realitzar en el "pad"
|
||||||
hot_points={},
|
movement="", -- Cap on es mou independentment de si està "flipat"
|
||||||
target={},
|
fight_modes=_fight_modes, -- mode de lluita (Llevar?)
|
||||||
old_target={},
|
mode="stop", -- mode de lluita actiu
|
||||||
path={},
|
mode_cooldown=500, -- cicles fins al canvi de mode
|
||||||
paths={},
|
super_cooldown=2000, -- cicles fins a Super actiu
|
||||||
action_event="",
|
shot_cooldown=500, -- cicles fina a poder disparar
|
||||||
path_curr_action=1,
|
hot_points={}, -- llista de punts del mapa on anar
|
||||||
analisis={},
|
target={}, -- següent punt on anar
|
||||||
|
old_target={}, -- target anterior
|
||||||
|
paths={}, -- Llista de "camins" a fer des d'un hot_point
|
||||||
|
path={}, -- Cami actiu
|
||||||
|
path_curr_action=1, -- Index d'acció dins del cami actiu
|
||||||
|
action_event="", -- Event d'acció que ha passat
|
||||||
|
analisis={}, -- Resultat de la informació extreta de l'entorn
|
||||||
|
old_action="-",
|
||||||
invencible=false,
|
invencible=false,
|
||||||
-- direccio=imp.direccio,
|
-- direccio=imp.direccio,
|
||||||
|
draw=imp.draw,
|
||||||
|
hit=imp.hit,
|
||||||
do_jump=imp.do_jump,
|
do_jump=imp.do_jump,
|
||||||
jump=imp.jump,
|
jump=imp.jump,
|
||||||
state_jumping=imp.state_jumping,
|
state_jumping=imp.state_jumping,
|
||||||
chase=imp.chase,
|
|
||||||
away=imp.away,
|
|
||||||
move=imp.move,
|
|
||||||
super=imp.super,
|
|
||||||
shot=imp.shot,
|
|
||||||
do_flip=imp.do_flip,
|
|
||||||
update=imp.state_normal,
|
update=imp.state_normal,
|
||||||
land=imp.land,
|
land=imp.land,
|
||||||
mode_controller=imp.mode_controller,
|
|
||||||
advance=imp.advance,
|
advance=imp.advance,
|
||||||
reduce_cooldown=imp.reduce_cooldown,
|
-- Funcions de jefe
|
||||||
think=imp.think,
|
fight=imp.fight, -- Inicialització per al combat. Crea el punts, carrega els paths, etc.
|
||||||
move=imp.move,
|
-- chase=imp.chase,
|
||||||
controller_input=imp.controller_input,
|
-- away=imp.away,
|
||||||
ia=imp.ia,
|
move=imp.move, -- Determina el següent moviment a fer (dreta, esq, bot, etc...)
|
||||||
analyze_env=imp.analyze_env,
|
super=imp.state_super, -- Entra en mode super poder
|
||||||
next_pattern_action=imp.next_pattern_action,
|
shot=imp.shot, -- Dispara
|
||||||
pattern_action=imp.pattern_action,
|
do_flip=imp.do_flip, -- Orienta a l'imp cap a l'actor
|
||||||
reset_mode_cooldown=imp.reset_mode_cooldown,
|
-- mode_controller=imp.mode_controller,
|
||||||
free_movement=imp.free_movement,
|
reduce_cooldown=imp.reduce_cooldown, -- Decrementa els cooldown
|
||||||
free_move=imp.free_move,
|
reset_mode_cooldown=imp.reset_mode_cooldown, -- Asignar un valor a mode_cooldown (per a mantindre una coherència cada volta que es crida)
|
||||||
reset_pattern_movement=imp.reset_pattern_movement,
|
controller_input=imp.controller_input, -- Traduir l'accio en moviment
|
||||||
pattern_move=imp.pattern_move,
|
actualitzar_comportament=imp.actualitzar_comportament, -- "Pensar" que fer
|
||||||
next_pattern_target=imp.next_pattern_target,
|
analyze_env=imp.analyze_env, -- Analitza l'entorn a vore que està pasant
|
||||||
next_free_target=imp.next_free_target,
|
|
||||||
old_action="-"
|
path_reset=imp.path_reset, -- Elimina el path actiu
|
||||||
|
path_next_action=imp.path_next_action, -- Següent acció del path actiu
|
||||||
|
path_action=imp.path_action, -- Acció actual del path actiu
|
||||||
|
|
||||||
|
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_target=imp.pattern_next_target, -- Següent target en mode pattern
|
||||||
|
|
||||||
|
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_target=imp.free_next_target, -- Següent target en mode free
|
||||||
|
|
||||||
|
next_action=imp.next_action, -- Següent acció en qualsevol mode de moviment
|
||||||
|
next_target=imp.next_target, -- Següent target en qualsevol mode de moviment
|
||||||
|
|
||||||
-- imp.enabled=false
|
-- imp.enabled=false
|
||||||
-- imp.counter=500
|
-- imp.counter=500
|
||||||
}
|
}
|
||||||
@@ -234,6 +242,7 @@ if DEBUG_FN_NAME then print("fight") end
|
|||||||
self.paths[11] = {}
|
self.paths[11] = {}
|
||||||
|
|
||||||
self.mode="chase"
|
self.mode="chase"
|
||||||
|
self:pattern_movement()
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:draw()
|
function imp:draw()
|
||||||
@@ -297,7 +306,7 @@ if DEBUG_FN_NAME then print("state_jumping") end
|
|||||||
-- cap endavant?
|
-- cap endavant?
|
||||||
if self.jumpfwd then self:advance() end
|
if self.jumpfwd then self:advance() end
|
||||||
|
|
||||||
self:ia()
|
self:actualitzar_comportament()
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:jump()
|
function imp:jump()
|
||||||
@@ -375,7 +384,7 @@ if DEBUG_FN_NAME then print("state_walking") end
|
|||||||
end
|
end
|
||||||
|
|
||||||
self:advance()
|
self:advance()
|
||||||
self:ia()
|
self:actualitzar_comportament()
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:state_falling()
|
function imp:state_falling()
|
||||||
@@ -398,7 +407,7 @@ if DEBUG_FN_NAME then print("state_falling") end
|
|||||||
|
|
||||||
-- Caiguent cap endavant?
|
-- Caiguent cap endavant?
|
||||||
if self.jumpfwd then self:advance() end
|
if self.jumpfwd then self:advance() end
|
||||||
self:ia()
|
self:actualitzar_comportament()
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:land ()
|
function imp:land ()
|
||||||
@@ -470,7 +479,7 @@ if DEBUG_FN_NAME then print("state_normal") end
|
|||||||
self.step=0
|
self.step=0
|
||||||
self.jumpfwd=false
|
self.jumpfwd=false
|
||||||
self.jump_height = 0
|
self.jump_height = 0
|
||||||
self:ia()
|
self:actualitzar_comportament()
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:state_super()
|
function imp:state_super()
|
||||||
@@ -510,14 +519,14 @@ if DEBUG_FN_NAME then print("reset_mode_cooldown") end
|
|||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:reset_pattern_movement()
|
function imp:path_reset()
|
||||||
if DEBUG_FN_NAME then print("reset_pattern_movement") end
|
if DEBUG_FN_NAME then print("path_reset") end
|
||||||
self.path={}
|
self.path={}
|
||||||
self.path_curr_action=1;
|
self.path_curr_action=1;
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:pattern_action()
|
function imp:path_action()
|
||||||
if DEBUG_FN_NAME then print("pattern_action") end
|
if DEBUG_FN_NAME then print("path_action") end
|
||||||
local action = self.path.actions[self.path_curr_action].action
|
local action = self.path.actions[self.path_curr_action].action
|
||||||
-- print("PATTERN");
|
-- print("PATTERN");
|
||||||
-- print(" TARGET= "..self.path.next)
|
-- print(" TARGET= "..self.path.next)
|
||||||
@@ -525,8 +534,15 @@ if DEBUG_FN_NAME then print("pattern_action") end
|
|||||||
return action
|
return action
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:pattern_move()
|
function imp:pattern_movement()
|
||||||
if DEBUG_FN_NAME then print("pattern_move") end
|
if DEBUG_FN_NAME then print("pattern_movement") end
|
||||||
|
self.movement_type = "pattern"
|
||||||
|
|
||||||
|
print("Pattern")
|
||||||
|
end
|
||||||
|
|
||||||
|
function imp:pattern_next_action()
|
||||||
|
if DEBUG_FN_NAME then print("pattern_next_action") end
|
||||||
local path_event = self.path.actions[self.path_curr_action].event
|
local path_event = self.path.actions[self.path_curr_action].event
|
||||||
-- print(" PATH_EVENT= "..path_event)
|
-- print(" PATH_EVENT= "..path_event)
|
||||||
-- print(" ACTION_EV = "..self.action_event)
|
-- print(" ACTION_EV = "..self.action_event)
|
||||||
@@ -540,11 +556,11 @@ if DEBUG_FN_NAME then print("pattern_move") end
|
|||||||
-- En el path
|
-- En el path
|
||||||
self.path_curr_action = self.path_curr_action + 1
|
self.path_curr_action = self.path_curr_action + 1
|
||||||
-- print(" CURR_ACC= "..self.path_curr_action)
|
-- print(" CURR_ACC= "..self.path_curr_action)
|
||||||
action = self:pattern_action()
|
action = self:path_action()
|
||||||
-- print(" ACTION 1= "..action)
|
-- print(" ACTION 1= "..action)
|
||||||
else
|
else
|
||||||
-- Path acabat, anar al següent
|
-- Path acabat, anar al següent
|
||||||
action = self:next_pattern_action()
|
action = self:path_next_action()
|
||||||
-- print(" ACTION 2= "..action)
|
-- print(" ACTION 2= "..action)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -552,8 +568,8 @@ if DEBUG_FN_NAME then print("pattern_move") end
|
|||||||
return action
|
return action
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:next_pattern_target(from)
|
function imp:pattern_next_target(from)
|
||||||
if DEBUG_FN_NAME then print("next_pattern_target") end
|
if DEBUG_FN_NAME then print("pattern_next_target") end
|
||||||
-- obtindre uno dels possibles camins des del punt "from" (en el que està)
|
-- obtindre uno dels possibles camins des del punt "from" (en el que està)
|
||||||
local next_path_idx = math.random(#self.paths[from])
|
local next_path_idx = math.random(#self.paths[from])
|
||||||
|
|
||||||
@@ -562,19 +578,19 @@ if DEBUG_FN_NAME then print("next_pattern_target") end
|
|||||||
self.target = self.hot_points[self.path.next]
|
self.target = self.hot_points[self.path.next]
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:next_pattern_action( from )
|
function imp:path_next_action( from )
|
||||||
from = from or self.path.next
|
from = from or self.path.next
|
||||||
if DEBUG_FN_NAME then print("next_pattern_action "..from) end
|
if DEBUG_FN_NAME then print("path_next_action "..from) end
|
||||||
if #self.paths[from]>0 then
|
if #self.paths[from]>0 then
|
||||||
self.movement_type = "pattern"
|
self:pattern_movement()
|
||||||
self:reset_mode_cooldown()
|
self:reset_mode_cooldown()
|
||||||
-- Activar següent target
|
-- Activar següent target
|
||||||
self:next_pattern_target(from)
|
self:next_target(from)
|
||||||
action = self:pattern_action()
|
action = self:path_action()
|
||||||
-- self.action_event=""
|
-- self.action_event=""
|
||||||
else
|
else
|
||||||
self:free_movement()
|
self:free_movement()
|
||||||
action = self:free_move()
|
action = self:next_action()
|
||||||
end
|
end
|
||||||
return action
|
return action
|
||||||
end
|
end
|
||||||
@@ -586,8 +602,8 @@ if DEBUG_FN_NAME then print("free_movement") end
|
|||||||
print("Free")
|
print("Free")
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:free_move()
|
function imp:free_next_action()
|
||||||
if DEBUG_FN_NAME then print("free_move") end
|
if DEBUG_FN_NAME then print("free_next_action") end
|
||||||
-- Moviment horitzontal
|
-- Moviment horitzontal
|
||||||
if self.target.x+self.target.bb.x>=self.x+self.bb.x then
|
if self.target.x+self.target.bb.x>=self.x+self.bb.x then
|
||||||
action="right"
|
action="right"
|
||||||
@@ -623,7 +639,7 @@ if DEBUG_FN_NAME then print("free_move") end
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Canviar a moviment per patro
|
-- Canviar a moviment per patro
|
||||||
action = self:next_pattern_action(idx)
|
action = self:path_next_action(idx)
|
||||||
-- elseif half_collision(self, self.target)
|
-- elseif half_collision(self, self.target)
|
||||||
-- and tile_type1==tiletype.void
|
-- and tile_type1==tiletype.void
|
||||||
-- and tile_type2==tiletype.void then -- and (self.y>self.target.y or self.y<self.target.y) ) then -- afegir que no hi haja tile per a escalar
|
-- and tile_type2==tiletype.void then -- and (self.y>self.target.y or self.y<self.target.y) ) then -- afegir que no hi haja tile per a escalar
|
||||||
@@ -636,8 +652,8 @@ if DEBUG_FN_NAME then print("free_move") end
|
|||||||
return action
|
return action
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:next_free_target()
|
function imp:free_next_target()
|
||||||
if DEBUG_FN_NAME then print("next_free_target") end
|
if DEBUG_FN_NAME then print("free_next_target") end
|
||||||
local new_point = math.random(#self.hot_points)
|
local new_point = math.random(#self.hot_points)
|
||||||
if self.target == self.hot_points[new_point] then
|
if self.target == self.hot_points[new_point] then
|
||||||
new_point = ((new_point+1)%#self.hot_points)+1
|
new_point = ((new_point+1)%#self.hot_points)+1
|
||||||
@@ -821,8 +837,8 @@ if DEBUG_FN_NAME then print("analyze_env") end
|
|||||||
-- msg_print(10,60,hab2..", "..tx2..", "..ty2, true)
|
-- msg_print(10,60,hab2..", "..tx2..", "..ty2, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function imp:ia()
|
function imp:actualitzar_comportament()
|
||||||
if DEBUG_FN_NAME then print("ia") end
|
if DEBUG_FN_NAME then print("actualitzar_comportament") end
|
||||||
self:reduce_cooldown()
|
self:reduce_cooldown()
|
||||||
-- if self.update==imp.state_jumping or self.update==imp.state_falling then
|
-- if self.update==imp.state_jumping or self.update==imp.state_falling then
|
||||||
-- -- self:think()
|
-- -- self:think()
|
||||||
@@ -830,7 +846,6 @@ if DEBUG_FN_NAME then print("ia") end
|
|||||||
-- end
|
-- end
|
||||||
self:analyze_env()
|
self:analyze_env()
|
||||||
if self.update==imp.state_walking or self.update==imp.state_normal then
|
if self.update==imp.state_walking or self.update==imp.state_normal then
|
||||||
self:think()
|
|
||||||
self:move()
|
self:move()
|
||||||
end
|
end
|
||||||
self:controller_input()
|
self:controller_input()
|
||||||
@@ -859,52 +874,39 @@ if DEBUG_FN_NAME then print("controller_input") end
|
|||||||
self.action = ""
|
self.action = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function imp:next_action()
|
||||||
|
local action = "stay"
|
||||||
|
if self.movement_type=="free" then
|
||||||
|
msg_print(10,20,"FREE",true)
|
||||||
|
action = self:free_next_action()
|
||||||
|
else
|
||||||
|
msg_print(10,20,"PATTERN "..self.action_event,true)
|
||||||
|
action=self:pattern_next_action()
|
||||||
|
end
|
||||||
|
return action
|
||||||
|
end
|
||||||
|
|
||||||
|
function imp:next_target(from)
|
||||||
|
if self.movement_type=="free" then
|
||||||
|
action = self:free_next_target()
|
||||||
|
else
|
||||||
|
action=self:pattern_next_target( from )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------
|
-------------------------------
|
||||||
-- imp.move()
|
-- imp:move()
|
||||||
--
|
--
|
||||||
-- Cridar en cada iteració per
|
-- Cridar en cada iteració per
|
||||||
-- a triar l'acció a fer i
|
-- a triar l'acció a fer i
|
||||||
-- traduir a acció de pad
|
-- traduir a acció de pad
|
||||||
-------------------------------
|
-------------------------------
|
||||||
function imp:move( )
|
function imp:move( )
|
||||||
if DEBUG_FN_NAME then print("move") end
|
if DEBUG_FN_NAME then print("move "..self.mode) end
|
||||||
local action = "stay"
|
local action = "stay"
|
||||||
|
|
||||||
if self.mode=="stop" then return action end
|
if self.mode=="stop" then return 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.movement_type=="free" then
|
|
||||||
msg_print(10,20,"FREE",true)
|
|
||||||
action = self:free_move()
|
|
||||||
else
|
|
||||||
msg_print(10,20,"PATTERN "..self.action_event,true)
|
|
||||||
action=self:pattern_move()
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.old_action~=action then
|
|
||||||
self.old_action=action
|
|
||||||
-- print(self.old_action)
|
|
||||||
end
|
|
||||||
|
|
||||||
self.action = action
|
|
||||||
self.action_event = ""
|
|
||||||
|
|
||||||
return action
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------------
|
|
||||||
-- imp.think()
|
|
||||||
--
|
|
||||||
-- Cridar en cada iteració per
|
|
||||||
-- a determinar que fer
|
|
||||||
-------------------------------
|
|
||||||
function imp:think()
|
|
||||||
if DEBUG_FN_NAME then print("think") end
|
|
||||||
if self.mode=="stop" then return end
|
|
||||||
-- print("SET FIGHT MODE")
|
|
||||||
|
|
||||||
-- S'ha acabat el temps per a arribar a un target
|
-- S'ha acabat el temps per a arribar a un target
|
||||||
if self.mode_cooldown <= 0 then
|
if self.mode_cooldown <= 0 then
|
||||||
-- Canviar a moviment lliure
|
-- Canviar a moviment lliure
|
||||||
@@ -915,17 +917,32 @@ if DEBUG_FN_NAME then print("think") end
|
|||||||
|
|
||||||
-- Reinicialitzar el patró de moviment i el cooldown
|
-- Reinicialitzar el patró de moviment i el cooldown
|
||||||
self:reset_mode_cooldown()
|
self:reset_mode_cooldown()
|
||||||
self:reset_pattern_movement()
|
self:path_reset()
|
||||||
|
|
||||||
self.mode=self.fight_modes["chase"]
|
self.mode=self.fight_modes["chase"]
|
||||||
|
|
||||||
-- Seleccionar el següent target aleatoriament
|
-- Seleccionar el següent target aleatoriament
|
||||||
self:next_free_target()
|
self:next_target()
|
||||||
|
|
||||||
print("Next random target => "..self.target.id)
|
print("Next random target => "..self.target.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
self:do_flip(abad)
|
self:do_flip(abad)
|
||||||
|
|
||||||
|
if self.analisis.going_to_fall then self.action_event="prefall" end
|
||||||
|
if self.analisis.target_reached then self.action_event="target" end
|
||||||
|
|
||||||
|
action = self:next_action()
|
||||||
|
|
||||||
|
if self.old_action~=action then
|
||||||
|
self.old_action=action
|
||||||
|
-- print(self.old_action)
|
||||||
|
end
|
||||||
|
|
||||||
|
self.action = action
|
||||||
|
self.action_event = ""
|
||||||
|
|
||||||
|
return action
|
||||||
|
|
||||||
--if imp.wait==6 then
|
--if imp.wait==6 then
|
||||||
-- imp.wait=0
|
-- imp.wait=0
|
||||||
@@ -962,5 +979,5 @@ if DEBUG_FN_NAME then print("think") end
|
|||||||
-- end
|
-- end
|
||||||
-- end
|
-- end
|
||||||
--
|
--
|
||||||
--end
|
--end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user