heroes-of-nerevelon/lib/grid/character.lua
Neckrat af792bd2d5 refactor character & grid again
Co-authored-by: Ivan Yuriev <ivanyr44@gmail.com>
2025-08-09 23:22:34 +03:00

28 lines
1.0 KiB
Lua

local Grid = require "lib.grid.grid"
--- @class CharacterGrid: Grid
local CharacterGrid = setmetatable({}, { __index = Grid })
CharacterGrid.__index = CharacterGrid
function CharacterGrid.new(width, height)
return setmetatable(Grid.new(width, height, nil), CharacterGrid)
end
--- Adds a character id to the grid
--- @param character Character
function CharacterGrid:add(character)
local cx, cy = math.floor(character.logic.mapLogic.position.x), math.floor(character.logic.mapLogic.position.y)
local sx, sy = character.logic.mapLogic.size.x, character.logic.mapLogic.size.y
self:fillRect(cx, cy, sx, sy, character.id)
end
--- Removes a character id from the grid
--- @param character Character
function CharacterGrid:remove(character)
local cx, cy = math.floor(character.logic.mapLogic.position.x), math.floor(character.logic.mapLogic.position.y)
local sx, sy = character.logic.mapLogic.size.x, character.logic.mapLogic.size.y
self:fillRect(cx, cy, sx, sy, nil)
end
return { new = CharacterGrid.new }