bytepath/rooms/Stage.lua
2025-11-11 01:54:07 -03:00

47 lines
1.3 KiB
Lua

---@class Stage:Room
---@field timer Timer
local Stage = Room:extend()
function Stage:new()
Stage.super.new(self)
self.timer = Timer()
-- game objects
self.timer:every(2, function()
local latest_object = self.area:addGameObject('Circle', love.math.random(1, gw), love.math.random(1, gh))
latest_object.timer:after(love.math.random(2, 4), function() latest_object:kill() end)
end)
self.area:addGameObject('Player', gw/2, gh/2)
end
function Stage:update(dt)
Stage.super.update(self, dt)
if input:pressed('action') then
local latest_object = self.area:addGameObject('Circle', love.math.random(1, gw), love.math.random(1, gh), {radius = 15})
end
if input:pressed('right') then
for _, game_object in ipairs(self.area.game_objects) do
game_object:kill()
end
end
if input:pressed('left') then
for _, game_object in ipairs(self.area.game_objects) do
if game_object:is(Circle) then
---@cast game_object Circle
if game_object.mode == "fill" then game_object.mode = "line" else game_object.mode = "fill" end
end
end
end
self.timer:update(dt)
end
function Stage:canvasDraw()
Stage.super.canvasDraw(self)
end
return Stage