63 lines
1.6 KiB
Lua
63 lines
1.6 KiB
Lua
---@module 'obj/Room'
|
|
|
|
---@class Room:Object
|
|
---@field area Area room area
|
|
---@field id string room id
|
|
---@field super Room
|
|
---@field main_canvas love.Canvas
|
|
local Room = Object:extend()
|
|
|
|
---Instantiates room.
|
|
function Room:new()
|
|
self.area = Area(self)
|
|
self.id = UUID()
|
|
self.main_canvas = love.graphics.newCanvas(gw, gh)
|
|
end
|
|
|
|
---Updates room (see [love.update()](lua://love.update))
|
|
---@param dt number delta time
|
|
function Room:update(dt)
|
|
---@diagnostic disable-next-line: undefined-field
|
|
camera.smoother = Camera.smooth.damped(5)
|
|
---@diagnostic disable-next-line: param-type-mismatch
|
|
camera:lockPosition(dt, gw/2, gh/2)
|
|
|
|
self.area:update(dt)
|
|
end
|
|
|
|
---Draws graphics (see [love.draw()](lua://love.draw))
|
|
---**DO NOT OVERRIDE:** use Room:canvasDraw() instead
|
|
function Room:draw()
|
|
love.graphics.setCanvas(self.main_canvas)
|
|
love.graphics.clear()
|
|
camera:attach(0, 0, gw, gh)
|
|
self:canvasDraw()
|
|
camera:detach()
|
|
if DEBUG then
|
|
love.graphics.print('objects: '..#self.area.game_objects,2,gh-16)
|
|
love.graphics.print('DEBUG', 2, 2)
|
|
end
|
|
love.graphics.setCanvas()
|
|
|
|
love.graphics.setColor(COLORS.default)
|
|
love.graphics.setBlendMode('alpha', 'premultiplied')
|
|
love.graphics.draw(self.main_canvas, 0, 0, 0, sx, sy)
|
|
love.graphics.setBlendMode('alpha')
|
|
end
|
|
|
|
---Draw to the canvas
|
|
function Room:canvasDraw()
|
|
self.area:draw()
|
|
end
|
|
|
|
---Destroys room
|
|
function Room:destroy()
|
|
if self.timer then
|
|
self.timer:clear() -- cancel all tweens/after/every
|
|
self.timer = nil
|
|
end
|
|
self.area:destroy()
|
|
self.area = nil
|
|
end
|
|
|
|
return Room
|