76 lines
2.2 KiB
Lua

local utils = require "lib.utils.utils"
--- @class Level
--- @field size Vec3
--- @field characters Character[]
--- @field characterGrid CharacterGrid
--- @field selector Selector
--- @field camera Camera
--- @field tileGrid TileGrid
local level = {}
level.__index = level
local path = nil
--- @param type "procedural"|"handmaded"
--- @param template Procedural|Handmaded
local function new(type, template)
local size = Vec3 { 30, 30 } -- magic numbers for testing purposes only
print(type, template, size)
return setmetatable({
size = size,
characters = {},
characterGrid = (require "lib.level.grid.character_grid").new(),
tileGrid = (require "lib.level.grid.tile_grid").new(type, template, size),
selector = (require "lib.level.selector").new(),
camera = (require "lib.level.camera").new(),
}, level)
end
local mposCache = nil
function level:update(dt)
self.characterGrid:reset()
utils.each(self.characters, function(el)
el:update(dt)
end)
if self.characters[self.selector.id] then
local charPos = self.characters[self.selector.id].logic.mapLogic.position:floor()
--- @type Vec3
local mpos = self.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }):floor()
-- ДУШИ здесь больше нет, приводите рыжих обратно
if not path or tostring(mpos) ~= mposCache then
path = require "lib.pathfinder" (charPos, mpos) -- ?????
end
mposCache = tostring(mpos)
-- path = (require "lib.pathfinder")(charPos, mpos)
else
mposCache = nil
end
self.camera:update(dt)
self.selector:update(dt)
end
function level:draw()
self.tileGrid:draw()
--- Это отрисовка пути персонажа к мышке
if self.selector.id and path then
love.graphics.setColor(0.6, 0.75, 0.5)
for p in path:values() do
love.graphics.circle("fill", p.x + 0.45, p.y + 0.45, 0.1)
end
love.graphics.setColor(1, 1, 1)
end
utils.each(self.characters, function(el)
el:draw()
end)
end
return {
new = new
}