path prototype
This commit is contained in:
@ -743,6 +743,32 @@ function segment:should_step(x, y)
|
||||
return ret
|
||||
end
|
||||
|
||||
path = mknew {
|
||||
loop_idx = 1,
|
||||
current_idx = 1,
|
||||
-- [1..n]: destinations
|
||||
}
|
||||
|
||||
function path:reset()
|
||||
self.loop_idx = 1
|
||||
self.current_idx = 1
|
||||
end
|
||||
|
||||
function path:target_from(fx, fy)
|
||||
return self[self.current_idx]:target_from(fx, fy)
|
||||
end
|
||||
|
||||
function path:update(x, y)
|
||||
local idx = self.current_idx
|
||||
if self[idx]:update(x, y) then
|
||||
if idx == #self then
|
||||
self.current_idx = self.loop_idx
|
||||
return true
|
||||
else
|
||||
self.current_idx = idx+1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-->8
|
||||
-- bullet and gun behaviors
|
||||
|
Reference in New Issue
Block a user