32 lines
892 B
Lua
32 lines
892 B
Lua
--- @class CharacterGrid : Grid
|
|
--- @field __grid {string: Id|nil}
|
|
local grid = setmetatable({}, require "lib.level.grid.base")
|
|
grid.__index = grid
|
|
|
|
--- Adds a character id to the grid
|
|
--- @param id Id
|
|
function grid:add(id)
|
|
local character = Tree.level.characters[id]
|
|
if not character then return end
|
|
|
|
local centerX, centerY = math.floor(character.logic.mapLogic.position.x + 0.5),
|
|
math.floor(character.logic.mapLogic.position.y + 0.5)
|
|
local sizeX, sizeY = character.logic.mapLogic.size.x, character.logic.mapLogic.size.y
|
|
|
|
for y = centerY, centerY + sizeY - 1 do
|
|
for x = centerX, centerX + sizeX - 1 do
|
|
self.__grid[tostring(Vec3 { x, y })] = character.id
|
|
end
|
|
end
|
|
end
|
|
|
|
--- Generates an empty grid
|
|
--- @return CharacterGrid
|
|
local function new()
|
|
return setmetatable({
|
|
__grid = {}
|
|
}, grid)
|
|
end
|
|
|
|
return { new = new }
|