bytepath/obj/Area.lua
2025-11-10 02:52:20 -03:00

39 lines
1 KiB
Lua

---@module 'obj/Area'
---@class Area:Object
---@field room Room
---@field game_objects GameObject[]
local Area = Object:extend()
---Instantiates area
function Area:new(room)
self.room = room
self.game_objects = {}
end
---Updates area
---@param dt number
function Area:update(dt)
for i, game_object in ipairs(self.game_objects) do
if game_object:isDead() then table.remove(self.game_objects, i) end
game_object:update(dt)
end
end
---Draws area
function Area:draw()
for _, game_object in ipairs(self.game_objects) do game_object:draw() end
end
---Adds game object to area
---@param game_object_type string name of game object's class
---@param x number|nil horizontal position
---@param y number|nil vertical position
---@param opts table|nil additional arguments
function Area:addGameObject(game_object_type, x, y, opts)
local game_object = _G[game_object_type](self, x or 0, y or 0, opts or {})
table.insert(self.game_objects, game_object)
return game_object
end
return Area