Compare commits

..

No commits in common. "486f2425443ac157b2d9afa5baac5e398969553c" and "e1bfd4f7f5518910d23bfec280d7efd1b84e3363" have entirely different histories.

4 changed files with 35 additions and 28 deletions

View File

@ -4,15 +4,19 @@ Camera = {
height = 0
}
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)
function Camera:positionCenterAt(x,y,cx,cy)
self.pos.x = x-self.width/game.scale/2
self.pos.y = y-self.height/game.scale/2
self:ConfineToLevel()
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)
end
function Camera:positionAt(x,y)

View File

@ -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()
@ -127,10 +127,23 @@ function EditorDoEdit()
elseif Keybind:HasPressed(Keybind.generic.lshift) then
LevelExpandCanvas(math.sign(expand_h),math.sign(expand_v))
LevelReloadTiles()
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
elseif Keybind:HasPressed(Keybind.generic.lctrl) then
LevelReduceCanvas(math.sign(expand_h),math.sign(expand_v))
LevelReloadTiles()
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
end
end
end
@ -138,18 +151,14 @@ end
function DrawSelectingPaletteTile()
if selecting_tile ~= nil and selecting_tile ~= 0 then
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
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
love.graphics.draw(
LevelData.tileset,
TileIndex[selecting_tile],
draw_x,
draw_y
mouse_x,
mouse_y
)
end
end

View File

@ -21,8 +21,6 @@ end
function LevelExpandCanvas(horizontal,vertical)
local horizontal = horizontal or 0
local vertical = vertical or 0
local h = LevelGetTileWidth()
local v = LevelGetTileHeight()
@ -53,7 +51,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].id)
ExpandedLevel[i+expand_v][j+expand_h] = InstanceTile(LevelTiles[i][j])
end
end
@ -63,8 +61,6 @@ end
function LevelReduceCanvas(horizontal,vertical)
local horizontal = horizontal or 0
local vertical = vertical or 0
local h = LevelGetTileWidth()
local v = LevelGetTileHeight()
@ -95,14 +91,12 @@ 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].id)
ExpandedLevel[i][j] = InstanceTile(LevelTiles[i+expand_v][j+expand_h])
end
end
-- use new canvas
LevelTiles = ExpandedLevel
LevelExpandCanvas()
end
function LevelGetTileData()

View File

@ -112,5 +112,5 @@ function love.draw()
if menuPage ~= nil then MenuDraw(menuPage) end
love.graphics.print(game.scale,10,40)
love.graphics.print(arrow,10,40)
end