Compare commits
2 Commits
6da507378f
...
d5dc2aba5f
| Author | SHA1 | Date | |
|---|---|---|---|
| d5dc2aba5f | |||
| f5f9f3d3dc |
289
data/imp.lua
289
data/imp.lua
@@ -38,67 +38,75 @@ function imp.new(_hab, _x, _y)
|
||||
jump_height=0,
|
||||
jump_in_half_block=0,
|
||||
jump_in_half_block_used = false,
|
||||
max_shoot_cooldown=24,
|
||||
-- max_shoot_cooldown=24,
|
||||
shot_power=1,
|
||||
shot_num_shots=1,
|
||||
shoot_cooldown=25,
|
||||
anim={28,29,28,30},
|
||||
bb={x=8,y=0,w=16,h=32},
|
||||
scene_intro=false,
|
||||
scene_object=false,
|
||||
fight_modes=_fight_modes,
|
||||
mode="stop",
|
||||
mode_cooldown=500,
|
||||
super_cooldown=2000,
|
||||
shot_cooldown=500,
|
||||
action="",
|
||||
movement="",
|
||||
movement_type="",
|
||||
-- scene_intro=false,
|
||||
-- scene_object=false,
|
||||
enabled=true,
|
||||
disable_reason="",
|
||||
can_warp=false,
|
||||
fight=imp.fight,
|
||||
draw=imp.draw,
|
||||
hit=imp.hit,
|
||||
hot_points={},
|
||||
target={},
|
||||
old_target={},
|
||||
path={},
|
||||
paths={},
|
||||
action_event="",
|
||||
path_curr_action=1,
|
||||
analisis={},
|
||||
-- Atributs de jefe
|
||||
movement_type="", -- Mode de moviment {pattern, free}
|
||||
action="", -- Acció a realitzar en el "pad"
|
||||
movement="", -- Cap on es mou independentment de si està "flipat"
|
||||
fight_modes=_fight_modes, -- mode de lluita (Llevar?)
|
||||
fight_mode="stop", -- mode de lluita actiu
|
||||
fight_mode_cooldown=1500, -- cicles fins al canvi de mode
|
||||
super_cooldown=2000, -- cicles fins a Super actiu
|
||||
shot_cooldown=500, -- cicles fina a poder disparar
|
||||
hot_points={}, -- llista de punts del mapa on anar
|
||||
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,
|
||||
-- direccio=imp.direccio,
|
||||
draw=imp.draw,
|
||||
hit=imp.hit,
|
||||
do_jump=imp.do_jump,
|
||||
jump=imp.jump,
|
||||
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,
|
||||
land=imp.land,
|
||||
mode_controller=imp.mode_controller,
|
||||
advance=imp.advance,
|
||||
reduce_cooldown=imp.reduce_cooldown,
|
||||
think=imp.think,
|
||||
move=imp.move,
|
||||
controller_input=imp.controller_input,
|
||||
ia=imp.ia,
|
||||
analyze_env=imp.analyze_env,
|
||||
next_pattern_action=imp.next_pattern_action,
|
||||
pattern_action=imp.pattern_action,
|
||||
reset_mode_cooldown=imp.reset_mode_cooldown,
|
||||
free_movement=imp.free_movement,
|
||||
free_move=imp.free_move,
|
||||
reset_pattern_movement=imp.reset_pattern_movement,
|
||||
pattern_move=imp.pattern_move,
|
||||
next_pattern_target=imp.next_pattern_target,
|
||||
next_free_target=imp.next_free_target,
|
||||
old_action="-"
|
||||
-- Funcions de jefe
|
||||
fight=imp.fight, -- Inicialització per al combat. Crea el punts, carrega els paths, etc.
|
||||
-- chase=imp.chase,
|
||||
-- away=imp.away,
|
||||
move=imp.move, -- Determina el següent moviment a fer (dreta, esq, bot, etc...)
|
||||
super=imp.state_super, -- Entra en mode super poder
|
||||
shot=imp.shot, -- Dispara
|
||||
do_flip=imp.do_flip, -- Orienta a l'imp cap a l'actor
|
||||
-- mode_controller=imp.mode_controller,
|
||||
reduce_cooldown=imp.reduce_cooldown, -- Decrementa els cooldown
|
||||
reset_fight_mode_cooldown=imp.reset_fight_mode_cooldown, -- Asignar un valor a fight_mode_cooldown (per a mantindre una coherència cada volta que es crida)
|
||||
controller_input=imp.controller_input, -- Traduir l'accio en moviment
|
||||
actualitzar_comportament=imp.actualitzar_comportament, -- "Pensar" que fer
|
||||
analyze_env=imp.analyze_env, -- Analitza l'entorn a vore que està pasant
|
||||
|
||||
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.counter=500
|
||||
}
|
||||
@@ -233,7 +241,8 @@ if DEBUG_FN_NAME then print("fight") end
|
||||
}
|
||||
self.paths[11] = {}
|
||||
|
||||
self.mode="chase"
|
||||
self.fight_mode="chase"
|
||||
self:pattern_movement()
|
||||
end
|
||||
|
||||
function imp:draw()
|
||||
@@ -297,7 +306,7 @@ if DEBUG_FN_NAME then print("state_jumping") end
|
||||
-- cap endavant?
|
||||
if self.jumpfwd then self:advance() end
|
||||
|
||||
self:ia()
|
||||
self:actualitzar_comportament()
|
||||
end
|
||||
|
||||
function imp:jump()
|
||||
@@ -375,7 +384,7 @@ if DEBUG_FN_NAME then print("state_walking") end
|
||||
end
|
||||
|
||||
self:advance()
|
||||
self:ia()
|
||||
self:actualitzar_comportament()
|
||||
end
|
||||
|
||||
function imp:state_falling()
|
||||
@@ -398,7 +407,7 @@ if DEBUG_FN_NAME then print("state_falling") end
|
||||
|
||||
-- Caiguent cap endavant?
|
||||
if self.jumpfwd then self:advance() end
|
||||
self:ia()
|
||||
self:actualitzar_comportament()
|
||||
end
|
||||
|
||||
function imp:land ()
|
||||
@@ -470,21 +479,21 @@ if DEBUG_FN_NAME then print("state_normal") end
|
||||
self.step=0
|
||||
self.jumpfwd=false
|
||||
self.jump_height = 0
|
||||
self:ia()
|
||||
self:actualitzar_comportament()
|
||||
end
|
||||
|
||||
function imp:state_super()
|
||||
if DEBUG_FN_NAME then print("state_super") end
|
||||
self.mode = self.fight_modes["super"]
|
||||
self.mode_cooldown=1
|
||||
self.fight_mode = self.fight_modes["super"]
|
||||
self:reset_fight_mode_cooldown(1)
|
||||
self.super_cooldown=2000
|
||||
self.update=imp.state_normal
|
||||
end
|
||||
|
||||
function imp:shot(actor)
|
||||
if DEBUG_FN_NAME then print("shot") end
|
||||
self.mode = self.fight_modes["shot"]
|
||||
self.mode_cooldown=1
|
||||
self.fight_mode = self.fight_modes["shot"]
|
||||
self:reset_fight_mode_cooldown(1)
|
||||
print("FIREBALL!!")
|
||||
self.shot_cooldown = 500
|
||||
end
|
||||
@@ -496,28 +505,28 @@ end
|
||||
|
||||
function imp:reduce_cooldown()
|
||||
if DEBUG_FN_NAME then print("reduce_cooldown") end
|
||||
if self.mode=="stop" then return end
|
||||
if self.fight_mode=="stop" then return end
|
||||
|
||||
self.mode_cooldown = self.mode_cooldown -1
|
||||
self.fight_mode_cooldown = self.fight_mode_cooldown -1
|
||||
self.super_cooldown = self.super_cooldown -1
|
||||
self.shoot_cooldown = self.shoot_cooldown -1
|
||||
end
|
||||
|
||||
function imp:reset_mode_cooldown( value )
|
||||
if DEBUG_FN_NAME then print("reset_mode_cooldown") end
|
||||
value = value or 500
|
||||
self.mode_cooldown = value
|
||||
function imp:reset_fight_mode_cooldown( value )
|
||||
if DEBUG_FN_NAME then print("reset_fight_mode_cooldown") end
|
||||
value = value or 1500
|
||||
self.fight_mode_cooldown = value
|
||||
return value
|
||||
end
|
||||
|
||||
function imp:reset_pattern_movement()
|
||||
if DEBUG_FN_NAME then print("reset_pattern_movement") end
|
||||
function imp:path_reset()
|
||||
if DEBUG_FN_NAME then print("path_reset") end
|
||||
self.path={}
|
||||
self.path_curr_action=1;
|
||||
end
|
||||
|
||||
function imp:pattern_action()
|
||||
if DEBUG_FN_NAME then print("pattern_action") end
|
||||
function imp:path_action()
|
||||
if DEBUG_FN_NAME then print("path_action") end
|
||||
local action = self.path.actions[self.path_curr_action].action
|
||||
-- print("PATTERN");
|
||||
-- print(" TARGET= "..self.path.next)
|
||||
@@ -525,8 +534,15 @@ if DEBUG_FN_NAME then print("pattern_action") end
|
||||
return action
|
||||
end
|
||||
|
||||
function imp:pattern_move()
|
||||
if DEBUG_FN_NAME then print("pattern_move") end
|
||||
function imp:pattern_movement()
|
||||
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
|
||||
-- print(" PATH_EVENT= "..path_event)
|
||||
-- print(" ACTION_EV = "..self.action_event)
|
||||
@@ -540,11 +556,11 @@ if DEBUG_FN_NAME then print("pattern_move") end
|
||||
-- En el path
|
||||
self.path_curr_action = self.path_curr_action + 1
|
||||
-- print(" CURR_ACC= "..self.path_curr_action)
|
||||
action = self:pattern_action()
|
||||
action = self:path_action()
|
||||
-- print(" ACTION 1= "..action)
|
||||
else
|
||||
-- Path acabat, anar al següent
|
||||
action = self:next_pattern_action()
|
||||
action = self:path_next_action()
|
||||
-- print(" ACTION 2= "..action)
|
||||
end
|
||||
end
|
||||
@@ -552,8 +568,8 @@ if DEBUG_FN_NAME then print("pattern_move") end
|
||||
return action
|
||||
end
|
||||
|
||||
function imp:next_pattern_target(from)
|
||||
if DEBUG_FN_NAME then print("next_pattern_target") end
|
||||
function imp:pattern_next_target(from)
|
||||
if DEBUG_FN_NAME then print("pattern_next_target") end
|
||||
-- obtindre uno dels possibles camins des del punt "from" (en el que està)
|
||||
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]
|
||||
end
|
||||
|
||||
function imp:next_pattern_action( from )
|
||||
function imp:path_next_action( from )
|
||||
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
|
||||
self.movement_type = "pattern"
|
||||
self:reset_mode_cooldown()
|
||||
self:pattern_movement()
|
||||
self:reset_fight_mode_cooldown()
|
||||
-- Activar següent target
|
||||
self:next_pattern_target(from)
|
||||
action = self:pattern_action()
|
||||
self:next_target(from)
|
||||
action = self:path_action()
|
||||
-- self.action_event=""
|
||||
else
|
||||
self:free_movement()
|
||||
action = self:free_move()
|
||||
action = self:next_action()
|
||||
end
|
||||
return action
|
||||
end
|
||||
@@ -586,8 +602,8 @@ if DEBUG_FN_NAME then print("free_movement") end
|
||||
print("Free")
|
||||
end
|
||||
|
||||
function imp:free_move()
|
||||
if DEBUG_FN_NAME then print("free_move") end
|
||||
function imp:free_next_action()
|
||||
if DEBUG_FN_NAME then print("free_next_action") end
|
||||
-- Moviment horitzontal
|
||||
if self.target.x+self.target.bb.x>=self.x+self.bb.x then
|
||||
action="right"
|
||||
@@ -611,7 +627,7 @@ if DEBUG_FN_NAME then print("free_move") end
|
||||
|
||||
--Comprovar si está en target
|
||||
if collision(self, self.target) then
|
||||
self:reset_mode_cooldown()
|
||||
self:reset_fight_mode_cooldown()
|
||||
|
||||
-- Buscar quin es el target
|
||||
local idx = 1
|
||||
@@ -623,7 +639,7 @@ if DEBUG_FN_NAME then print("free_move") end
|
||||
end
|
||||
|
||||
-- Canviar a moviment per patro
|
||||
action = self:next_pattern_action(idx)
|
||||
action = self:path_next_action(idx)
|
||||
-- elseif half_collision(self, self.target)
|
||||
-- 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
|
||||
@@ -636,8 +652,8 @@ if DEBUG_FN_NAME then print("free_move") end
|
||||
return action
|
||||
end
|
||||
|
||||
function imp:next_free_target()
|
||||
if DEBUG_FN_NAME then print("next_free_target") end
|
||||
function imp:free_next_target()
|
||||
if DEBUG_FN_NAME then print("free_next_target") end
|
||||
local new_point = math.random(#self.hot_points)
|
||||
if self.target == self.hot_points[new_point] then
|
||||
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)
|
||||
end
|
||||
|
||||
function imp:ia()
|
||||
if DEBUG_FN_NAME then print("ia") end
|
||||
function imp:actualitzar_comportament()
|
||||
if DEBUG_FN_NAME then print("actualitzar_comportament") end
|
||||
self:reduce_cooldown()
|
||||
-- if self.update==imp.state_jumping or self.update==imp.state_falling then
|
||||
-- -- self:think()
|
||||
@@ -830,7 +846,6 @@ if DEBUG_FN_NAME then print("ia") end
|
||||
-- end
|
||||
self:analyze_env()
|
||||
if self.update==imp.state_walking or self.update==imp.state_normal then
|
||||
self:think()
|
||||
self:move()
|
||||
end
|
||||
self:controller_input()
|
||||
@@ -859,29 +874,73 @@ if DEBUG_FN_NAME then print("controller_input") end
|
||||
self.action = ""
|
||||
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
|
||||
|
||||
-- seleccionar mode d'acció
|
||||
--local last_mode=self.fight_mode
|
||||
-- self.fight_mode=self.fight_modes["chase"]
|
||||
if self.fight_mode_cooldown<=0 then
|
||||
self.fight_mode=self.fight_modes[math.random(2)] -- chase o away
|
||||
self:reset_fight_mode_cooldown()
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------
|
||||
-- imp.move()
|
||||
-- imp:move()
|
||||
--
|
||||
-- Cridar en cada iteració per
|
||||
-- a triar l'acció a fer i
|
||||
-- traduir a acció de pad
|
||||
-------------------------------
|
||||
function imp:move( )
|
||||
if DEBUG_FN_NAME then print("move") end
|
||||
if DEBUG_FN_NAME then print("move "..self.fight_mode) end
|
||||
local action = "stay"
|
||||
|
||||
if self.mode=="stop" then return action end
|
||||
|
||||
if self.fight_mode=="stop" then return action end
|
||||
|
||||
-- S'ha acabat el temps per a arribar a un target
|
||||
if self.fight_mode_cooldown <= 0 then
|
||||
-- Canviar a moviment lliure
|
||||
self:free_movement()
|
||||
|
||||
-- Reinicialitzar el patró de moviment i el cooldown
|
||||
self:reset_fight_mode_cooldown()
|
||||
self:path_reset()
|
||||
|
||||
-- Seleccionar el següent target aleatoriament
|
||||
self:next_target()
|
||||
|
||||
print("Next random target => "..self.target.id)
|
||||
end
|
||||
|
||||
if self.fight_mode==self.fight_modes["chase"] then
|
||||
self:do_flip(abad)
|
||||
else
|
||||
self:do_flip(self.target)
|
||||
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
|
||||
action = self:next_action()
|
||||
|
||||
if self.old_action~=action then
|
||||
self.old_action=action
|
||||
@@ -892,40 +951,6 @@ if DEBUG_FN_NAME then print("move") end
|
||||
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
|
||||
if self.mode_cooldown <= 0 then
|
||||
-- Canviar a moviment lliure
|
||||
self:free_movement()
|
||||
|
||||
-- seleccionar mode d'acció
|
||||
local last_mode=self.mode
|
||||
|
||||
-- Reinicialitzar el patró de moviment i el cooldown
|
||||
self:reset_mode_cooldown()
|
||||
self:reset_pattern_movement()
|
||||
|
||||
self.mode=self.fight_modes["chase"]
|
||||
|
||||
-- Seleccionar el següent target aleatoriament
|
||||
self:next_free_target()
|
||||
|
||||
print("Next random target => "..self.target.id)
|
||||
end
|
||||
|
||||
self:do_flip(abad)
|
||||
|
||||
--if imp.wait==6 then
|
||||
-- imp.wait=0
|
||||
@@ -962,5 +987,5 @@ if DEBUG_FN_NAME then print("think") end
|
||||
-- end
|
||||
-- end
|
||||
--
|
||||
--end
|
||||
--end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user