Split out start/stop timer for worm

This commit is contained in:
2024-12-04 20:12:12 -06:00
parent 58e1e597f8
commit 1f888d2e2a
2 changed files with 23 additions and 1 deletions

View File

@@ -111,6 +111,10 @@ function Game:enter()
Siren.new(self),
Worm.new(self)
}
for _, enemy in ipairs(self.enemies) do
enemy:enter()
end
end
function Game:update(dt)
@@ -175,6 +179,12 @@ function Game:draw()
end)
end
function Game:exit()
for _, enemy in ipairs(self.enemies) do
enemy:enter()
end
end
function Game:resize(w, h)
self.effect:resize(w, h)
end

View File

@@ -37,11 +37,15 @@ function Worm.new(game)
end
self.timer = Timer.new()
self.timer:every(self.stats.moveDelay, function() self:_move() end)
self.timerHandles = {}
return self
end
function Worm:enter() self:_startMoving() end
function Worm:exit() self:_stopMoving() end
function Worm:update(dt)
self.timer:update(dt)
end
@@ -85,6 +89,14 @@ end
function Worm:getSize() return self.size.w, self.size.h end
function Worm:_startMoving()
self.timerHandles.move = self.timer:every(self.stats.moveDelay, function() self:_move() end)
end
function Worm:_stopMoving()
self.timer:cancel(self.timerHandles.move)
end
function Worm:_findSpawnPoint()
local pos = random.chooseUntil(self.game.env.nodes, function(element)
local distanceToPlayer = vector.dist(element.x, element.y, self.game.player:getPos())