From 486f2425443ac157b2d9afa5baac5e398969553c Mon Sep 17 00:00:00 2001 From: lustlion Date: Mon, 31 Jan 2022 07:38:15 +0100 Subject: [PATCH] editor fix, camera confined to level --- data/scripts/camera.lua | 18 +++++++----------- data/scripts/editor.lua | 17 ++--------------- main.lua | 2 +- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/data/scripts/camera.lua b/data/scripts/camera.lua index 4062cd2..750e11f 100644 --- a/data/scripts/camera.lua +++ b/data/scripts/camera.lua @@ -4,19 +4,15 @@ Camera = { height = 0 } -function Camera:positionCenterAt(x,y,cx,cy) +function Camera:ConfineToLevel() + self.pos.x = math.max(0,math.min(self.pos.x,LevelData.Width-self.width/game.scale)) + self.pos.y = math.max(0,math.min(self.pos.y,LevelData.Height-self.height/game.scale)) +end + +function Camera:positionCenterAt(x,y) self.pos.x = x-self.width/game.scale/2 self.pos.y = y-self.height/game.scale/2 - if not (cx == nil or cy == nil) then - cx = cx - self.width - cy = cy - self.height - if self.pos.x > cx then self.pos.x = cx end - if self.pos.y > cy then self.pos.y = cy end - if self.pos.x < 0 then self.pos.x = 0 end - if self.pos.y < 0 then self.pos.y = 0 end - end - self.pos.x = math.floor(self.pos.x) - self.pos.y = math.floor(self.pos.y) + self:ConfineToLevel() end function Camera:positionAt(x,y) diff --git a/data/scripts/editor.lua b/data/scripts/editor.lua index 15795c4..425d545 100644 --- a/data/scripts/editor.lua +++ b/data/scripts/editor.lua @@ -127,23 +127,10 @@ function EditorDoEdit() elseif Keybind:HasPressed(Keybind.generic.lshift) then LevelExpandCanvas(math.sign(expand_h),math.sign(expand_v)) - - if expand_h < 0 then - Camera.pos.x = Camera.pos.x - math.sign(expand_h)*tileProperties.scale*tileProperties.width - end - if expand_v < 0 then - Camera.pos.y = Camera.pos.y - math.sign(expand_v)*tileProperties.scale*tileProperties.height - end - + LevelReloadTiles() elseif Keybind:HasPressed(Keybind.generic.lctrl) then LevelReduceCanvas(math.sign(expand_h),math.sign(expand_v)) - - if expand_h < 0 then - Camera.pos.x = Camera.pos.x - math.sign(expand_h)*tileProperties.scale*tileProperties.width - end - if expand_v < 0 then - Camera.pos.y = Camera.pos.y - math.sign(expand_v)*tileProperties.scale*tileProperties.height - end + LevelReloadTiles() end end end diff --git a/main.lua b/main.lua index 2a43e9a..859310b 100644 --- a/main.lua +++ b/main.lua @@ -112,5 +112,5 @@ function love.draw() if menuPage ~= nil then MenuDraw(menuPage) end - love.graphics.print(arrow,10,40) + love.graphics.print(game.scale,10,40) end