consistent naming; moving functions from level.lua to gameworld.lua
This commit is contained in:
@@ -13,6 +13,18 @@ function EditorStep()
|
||||
selecting_tile = 51
|
||||
end
|
||||
end
|
||||
if love.keyboard.isDown('a',"left") then
|
||||
Camera.pos.x = Camera.pos.x - 3*game.scale
|
||||
end
|
||||
if love.keyboard.isDown('d',"right") then
|
||||
Camera.pos.x = Camera.pos.x + 3*game.scale
|
||||
end
|
||||
if love.keyboard.isDown("up", "w") then
|
||||
Camera.pos.y = Camera.pos.y - 3*game.scale
|
||||
end
|
||||
if love.keyboard.isDown("down", "s") then
|
||||
Camera.pos.y = Camera.pos.y + 3*game.scale
|
||||
end
|
||||
end
|
||||
|
||||
function EditorScroll(y)
|
||||
@@ -29,12 +41,87 @@ function EditorScroll(y)
|
||||
end
|
||||
|
||||
function EditorDraw()
|
||||
GameworldDraw()
|
||||
GameworldDrawPrepare()
|
||||
GameworldDrawBackground()
|
||||
GridDisplay()
|
||||
GameworldDrawForeground()
|
||||
GameworldDrawEnd()
|
||||
|
||||
DrawSelectingPaletteTile()
|
||||
if palette then
|
||||
EditorDoPalette()
|
||||
end
|
||||
end
|
||||
|
||||
function EditorDoEdit()
|
||||
if love.mouse.isDown(1) then
|
||||
local vertical = 1+math.floor((mouse.pos.y+Camera.pos.y)/(tileProperties.scale*tileProperties.height))
|
||||
local horizontal = 1+math.floor((mouse.pos.x+Camera.pos.x)/(tileProperties.scale*tileProperties.width))
|
||||
local h, v = GetCanvasSize()
|
||||
|
||||
local expand_h = 0
|
||||
local expand_v = 0
|
||||
|
||||
if horizontal > h then
|
||||
expand_h = horizontal-h
|
||||
elseif horizontal <= 0 then
|
||||
expand_h = horizontal-1
|
||||
end
|
||||
|
||||
if vertical > v then
|
||||
expand_v = math.sign(vertical-v)
|
||||
elseif vertical <= 0 then
|
||||
expand_v = math.sign(vertical-1)
|
||||
end
|
||||
|
||||
if Level[vertical] ~= nil
|
||||
and Level[vertical][horizontal] ~= nil
|
||||
and love.keyboard.isDown("lshift") ~= true
|
||||
and love.keyboard.isDown("lctrl") ~= true
|
||||
then
|
||||
Level[vertical][horizontal] = tile_carrying
|
||||
elseif love.keyboard.isDown("lshift") and not expanded then
|
||||
expanded = true
|
||||
ExpandCanvas(math.sign(expand_h),math.sign(expand_v))
|
||||
|
||||
if expand_h < 0 then
|
||||
Camera.pos.x = Camera.pos.x - expand_h*tileProperties.scale*tileProperties.width
|
||||
end
|
||||
if expand_v < 0 then
|
||||
Camera.pos.y = Camera.pos.y - expand_v*tileProperties.scale*tileProperties.height
|
||||
end
|
||||
|
||||
elseif love.keyboard.isDown("lctrl") and not expanded then
|
||||
expanded = true
|
||||
ReduceCanvas(math.sign(expand_h),math.sign(expand_v))
|
||||
|
||||
if expand_h < 0 then
|
||||
Camera.pos.x = Camera.pos.x - expand_h*tileProperties.scale*tileProperties.width
|
||||
end
|
||||
if expand_v < 0 then
|
||||
Camera.pos.y = Camera.pos.y - expand_v*tileProperties.scale*tileProperties.height
|
||||
end
|
||||
end
|
||||
elseif love.mouse.isDown(1) ~= true then
|
||||
expanded = false
|
||||
end
|
||||
end
|
||||
|
||||
function DrawSelectingPaletteTile()
|
||||
if selecting_tile ~= nil 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
|
||||
|
||||
love.graphics.draw(
|
||||
LevelData.tileset,
|
||||
TileIndex[selecting_tile],
|
||||
mouse_x,
|
||||
mouse_y
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
function EditorDoPalette()
|
||||
|
||||
local width = LevelData.tileset:getPixelWidth()/tileProperties.width
|
||||
@@ -71,17 +158,17 @@ function EditorDoPalette()
|
||||
local mouse_x = love.mouse.getX()
|
||||
local mouse_y = love.mouse.getY()
|
||||
|
||||
if mouse_x > tile_x
|
||||
and mouse_x < tile_x + tileProperties.width + 1
|
||||
and mouse_y > tile_y
|
||||
and mouse_y < tile_y + tileProperties.height + 1
|
||||
if mouse_x > (tile_x) * game.scale
|
||||
and mouse_x < (tile_x + tileProperties.width) * game.scale
|
||||
and mouse_y > (tile_y) * game.scale
|
||||
and mouse_y < (tile_y + tileProperties.height) * game.scale
|
||||
then
|
||||
selecting_tile = position_x + (position_y * width)
|
||||
selecting_tile = position_x + ((position_y-1) * width)
|
||||
|
||||
love.graphics.print(selecting_tile .. " | " .. tile_x .. ", " .. tile_y)
|
||||
else
|
||||
--selecting_tile = nil
|
||||
end
|
||||
else
|
||||
selecting_tile = 0
|
||||
end
|
||||
|
||||
if selecting_tile ~= nil and i == selecting_tile then
|
||||
|
||||
Reference in New Issue
Block a user