47 lines
1.4 KiB
Lua
47 lines
1.4 KiB
Lua
---@class CircleRoom:Room
|
|
---@field timer Timer
|
|
local CircleRoom = Room:extend()
|
|
|
|
function CircleRoom:new()
|
|
CircleRoom.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)
|
|
end
|
|
|
|
function CircleRoom:update(dt)
|
|
CircleRoom.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 CircleRoom:canvasDraw()
|
|
CircleRoom.super.canvasDraw(self)
|
|
love.graphics.setColor(1, 1, 1)
|
|
love.graphics.print('objects: '..#self.area.game_objects,2,2)
|
|
end
|
|
|
|
return CircleRoom
|