diff --git a/data/scripts/editor.lua b/data/scripts/editor.lua index 07f997c..15795c4 100644 --- a/data/scripts/editor.lua +++ b/data/scripts/editor.lua @@ -90,8 +90,8 @@ end function EditorDoEdit() local mouse_x = love.mouse.getX() local mouse_y = love.mouse.getY() - local horizontal = 1 + math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width)) - local vertical = 1 + math.floor(((mouse_y/game.scale) / tileProperties.height) + (Camera.pos.y / tileProperties.height)) + local horizontal = 1+math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width)) + local vertical = 1+math.floor(((mouse_y/game.scale) / tileProperties.height) + (Camera.pos.y / tileProperties.height)) local expand_h = 0 local expand_v = 0 local LevelWidth = LevelGetTileWidth() @@ -151,14 +151,18 @@ end function DrawSelectingPaletteTile() if selecting_tile ~= nil and selecting_tile ~= 0 then - local mouse_x = tileProperties.width * math.floor((love.mouse.getX()/game.scale) / tileProperties.width) - Camera.pos.x % tileProperties.width - local mouse_y = tileProperties.height * math.floor((love.mouse.getY()/game.scale) / tileProperties.height) - Camera.pos.y % tileProperties.height + local mouse_x = love.mouse.getX() + local mouse_y = love.mouse.getY() + local horizontal = math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width)) + local vertical = math.floor(((mouse_y/game.scale) / tileProperties.height) + (Camera.pos.y / tileProperties.height)) + local draw_x = tileProperties.width * horizontal - Camera.pos.x + local draw_y = tileProperties.height * vertical - Camera.pos.y love.graphics.draw( LevelData.tileset, TileIndex[selecting_tile], - mouse_x, - mouse_y + draw_x, + draw_y ) end end diff --git a/data/scripts/level.lua b/data/scripts/level.lua index c3f75fc..0d9a74c 100644 --- a/data/scripts/level.lua +++ b/data/scripts/level.lua @@ -21,6 +21,8 @@ end function LevelExpandCanvas(horizontal,vertical) + local horizontal = horizontal or 0 + local vertical = vertical or 0 local h = LevelGetTileWidth() local v = LevelGetTileHeight() @@ -51,7 +53,7 @@ function LevelExpandCanvas(horizontal,vertical) -- get data from old canvas to new canvas for i = 1, #LevelTiles do for j = 1, #LevelTiles[i] do - ExpandedLevel[i+expand_v][j+expand_h] = InstanceTile(LevelTiles[i][j]) + ExpandedLevel[i+expand_v][j+expand_h] = InstanceTile(LevelTiles[i][j].id) end end @@ -61,6 +63,8 @@ end function LevelReduceCanvas(horizontal,vertical) + local horizontal = horizontal or 0 + local vertical = vertical or 0 local h = LevelGetTileWidth() local v = LevelGetTileHeight() @@ -91,12 +95,14 @@ function LevelReduceCanvas(horizontal,vertical) -- get data from old canvas to new canvas for i = 1, #ExpandedLevel do for j = 1, #ExpandedLevel[i] do - ExpandedLevel[i][j] = InstanceTile(LevelTiles[i+expand_v][j+expand_h]) + ExpandedLevel[i][j] = InstanceTile(LevelTiles[i+expand_v][j+expand_h].id) end end -- use new canvas LevelTiles = ExpandedLevel + + LevelExpandCanvas() end function LevelGetTileData()