[WIP] Treballant en el jefe. Pareix que se va aclarint, pareix
This commit is contained in:
@@ -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,12 +71,15 @@ 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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user