-- CameraLoader = require 'lib/camera' require "character" local Vec3 = require "lib/vec3" function love.conf(t) t.console = true end Camera = { target = Vec3 {}, position = Vec3 {}, lerp_speed = 5.0, max_offset = 1, -- на сколько метров камера может отдалиться от целевой позиции max_offset_distance = 5 -- на сколько метров надо отвести мышь для максимального отдаления камеры } PIXELS_PER_METER = 100 function Camera:update(dt) if not self.target then return end local mouse_offset = Vec3 { 0, 0, 0 } local offset_distance = 0 local adjusted_target = self.target * (self.max_offset * offset_distance / self.max_offset_distance) local to_target = adjusted_target - self.position self.position = self.position + to_target * (dt * self.lerp_speed) end -- Преобразует вектор мировых координат (в метрах) в вектоор экранных координат (в пикселях) local function worldToScreen(worldPos) return (worldPos - Camera.position) * PIXELS_PER_METER end function love.load() Camera.target = Vec3({}) -- PlayerFaction = Faction -- Hero1 = Character:create("Petya", 10) -- Hero2 = Character:create("Andrysha", 12) -- PlayerFaction.characters = { Hero1, Hero2 } love.window.setMode(1080, 720, { resizable = true, msaa = 4, vsync = true }) end ---@todo Вынести это в свое поле в дереве глобального состояния уровня -- local cameraPos = Vec3({}) -- Camera:lockPosition(cameraPos.x, cameraPos.y, Camera.smooth.damped(10)) function love.update(dt) if love.keyboard.isDown("w") then Camera.target = Camera.target + Vec3({ 0, -dt }) end if love.keyboard.isDown("a") then Camera.target = Camera.target + Vec3({ -dt }) end if love.keyboard.isDown("s") then Camera.target = Camera.target + Vec3({ 0, dt }) end if love.keyboard.isDown("d") then Camera.target = Camera.target + Vec3({ dt }) end Camera:update(dt) end function love.draw() -- Camera:attach() local uiSize = 0.2 local windowWidth = love.graphics.getWidth() local windowHeight = love.graphics.getHeight() * (1 - uiSize) local width = 20 local height = 12 love.graphics.setColor(139 / 255, 195 / 255, 74 / 255, 1) love.graphics.rectangle('fill', worldToScreen(Vec3 {}).x, worldToScreen(Vec3 {}).y, width * PIXELS_PER_METER, height * PIXELS_PER_METER) love.graphics.setColor(244 / 255, 67 / 255, 54 / 255, 1) love.graphics.rectangle('fill', worldToScreen(Vec3 {}).x, worldToScreen(Vec3 {}).y, 1 * PIXELS_PER_METER, 1 * PIXELS_PER_METER) -- if windowWidth / windowHeight > width / height then -- local fieldWidth = windowHeight * width / height -- love.graphics.rectangle('fill', 0.5 * (windowWidth - fieldWidth), 0, -- fieldWidth, windowHeight) -- else -- local fieldHeight = windowWidth * height / width -- love.graphics.rectangle('fill', 0, 0.5 * (windowHeight - fieldHeight), -- windowWidth, fieldHeight) -- end -- Camera:detach() end local Level = {} Level.kakaya_ta_hren = 10 Level.map = {} local v = Vec3({ 0, 1, 2 }) -- Faction -> Character -- calculate_order() -- calculate_order()