[WIP] Treballant en el jefe. Organitzant codi (Ha deixat de funcionar quasi tot)
[FIX] Els warps reutilitzats mantenien l'estat anterior [NEW] Funcio distancia(a, b)
This commit is contained in:
162
data/imp_action.lua
Normal file
162
data/imp_action.lua
Normal file
@@ -0,0 +1,162 @@
|
||||
|
||||
function imp:choose_action() -- antic imp:move
|
||||
if self.mood==self.moods.stop then return self.mood end
|
||||
if DEBUG_FN_NAME then print("choose_action "..self.mood) end
|
||||
local next_action = self.actions.no_action
|
||||
|
||||
-- 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.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
|
||||
|
||||
next_action = self:next_action()
|
||||
|
||||
if self.analisis.target_reached and next_action=="super" then
|
||||
-- print("Super READY!")
|
||||
self.action_event = "super_ready"
|
||||
-- next_action = self:next_action()
|
||||
self:super()
|
||||
end
|
||||
|
||||
if self.old_action~=next_action then
|
||||
self.old_action=next_action
|
||||
-- print(self.old_action)
|
||||
end
|
||||
|
||||
self.action = next_action
|
||||
|
||||
return next_action
|
||||
end
|
||||
|
||||
function imp:next_action()
|
||||
local next_action = self.actions.no_action
|
||||
|
||||
-- Si el blanc està a tir
|
||||
if self.timers.shot<=0 then
|
||||
if h_collision(self, self.shot_target) then
|
||||
next_action = self.actions.shot
|
||||
end
|
||||
end
|
||||
|
||||
if next_action==self.actions.no_action then
|
||||
if self.move_type==self.move_types.free then
|
||||
-- msg_print(10,20,"FREE",true)
|
||||
next_action = self:free_next_action()
|
||||
elseif self.move_type==self.move_types.pattern then
|
||||
-- msg_print(10,20,"PATTERN "..self.action_event,true)
|
||||
next_action=self:pattern_next_action()
|
||||
elseif self.move_type==self.move_types.super then
|
||||
-- msg_print(10,20,"SUPER "..self.action_event,true)
|
||||
end
|
||||
end
|
||||
|
||||
return next_action
|
||||
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"
|
||||
elseif self.target.x+self.target.bb.x<self.x+self.bb.x then
|
||||
action="left"
|
||||
end
|
||||
|
||||
-- Els dos punts de baix pero un poc mes alt que el piso
|
||||
local x1_check = self.x+self.bb.x
|
||||
local x2_check = self.x+self.bb.x+self.bb.w
|
||||
local y_check = self.y+self.bb.h-4
|
||||
-- Tiles on esta
|
||||
local tile_type1, tile_code1= arc_check_tile(x1_check,y_check)
|
||||
local tile_type2, tile_code2= arc_check_tile(x2_check,y_check)
|
||||
|
||||
-- debug
|
||||
local scr_x1, scr_y = viewp:screen_coords( x1_check, y_check )
|
||||
local scr_x2, scr_y = viewp:screen_coords( x2_check, y_check )
|
||||
draw.rect(scr_x1,scr_y,scr_x2-scr_x1,8,2)
|
||||
-- /debug
|
||||
|
||||
--Comprovar si está en target
|
||||
if collision(self, self.target) then
|
||||
self:reset_mood_timer()
|
||||
|
||||
-- Buscar quin es el target
|
||||
local idx = 1
|
||||
for i=1,#self.hot_points do
|
||||
if self.target==self.hot_points[i] then
|
||||
idx= i
|
||||
-- print("TARGET ID= "..self.target.id.." HOT POINT IDX= "..i.." Reached")
|
||||
end
|
||||
end
|
||||
|
||||
-- Canviar a moviment per patro
|
||||
self.path={next=idx, actions={}}
|
||||
action = self:path_next_action()
|
||||
-- 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
|
||||
-- -- print("Next Target 2 "..tile_type1.." "..tile_code1)
|
||||
-- elseif tile_type1~=tiletype.void
|
||||
-- or tile_type2~=tiletype.void then
|
||||
-- action="jump"
|
||||
end
|
||||
|
||||
return action
|
||||
end
|
||||
|
||||
function imp:pattern_next_action()
|
||||
if DEBUG_FN_NAME then print("pattern_next_action") end
|
||||
local pattern_event = self.pattern.actions[self.pattern_point].event
|
||||
|
||||
-- Si no s'ha donat l'event mantindre el moviment
|
||||
if self.action_event~=pattern_event then
|
||||
action = self.actions[self.pattern.actions[self.pattern_point].action]
|
||||
else
|
||||
-- Si s'ha donat l'event avançar el punter del path
|
||||
-- Si no queden accions carregar el següent path
|
||||
if self.pattern_point<#self.pattern.actions then
|
||||
self:pattern_get_next_path()
|
||||
self.pattern_point = 0
|
||||
end
|
||||
|
||||
-- En el path
|
||||
self.pattern_point = self.pattern_point + 1
|
||||
action = self:pattern_action()
|
||||
end
|
||||
self.action_event = ""; -- Action_event processat
|
||||
return action
|
||||
end
|
||||
|
||||
function imp:pattern_action()
|
||||
if DEBUG_FN_NAME then print("pattern_action") end
|
||||
return self.actions[self.path.actions[self.pattern_point].action]
|
||||
end
|
||||
|
||||
|
||||
|
||||
function imp:_moure( foo, name )
|
||||
name = name or "anonymous"
|
||||
print("_moure= "..name)
|
||||
self.moure = foo
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-- function imp:path_next_action()
|
||||
-- if not DEBUG_FN_NAME then print("path_next_action "..from) end
|
||||
-- if #self.paths[self.path.target]>0 then
|
||||
-- -- self:pattern_movement()
|
||||
-- self:reset_target_timer()
|
||||
-- self:next_target()
|
||||
-- action = self:path_action()
|
||||
-- else
|
||||
-- action = self:pattern_recovery()
|
||||
-- print("PNA Recovery "..action)
|
||||
-- end
|
||||
-- return action
|
||||
-- end
|
||||
Reference in New Issue
Block a user