Mothback/data/scripts/game.lua

167 lines
3.5 KiB
Lua
Raw Normal View History

function stepEditor()
2022-01-18 19:24:49 +00:00
palette = palette or false
AnimateTiles()
2022-01-18 19:24:49 +00:00
if love.keyboard.isDown("tab") and not pressed then
if palette then palette = false else palette = true end
local pressed = true
else
pressed = false
end
end
function stepGame()
-- GAME STEP
if not do_pause then
SetCollisionFlags(main_Player)
for _, enty in pairs(LoadedEntities) do
enty:Smart()
enty:DoPhysics()
end
AnimateTiles()
Camera:positionCenterAt(main_Player.pos.x, main_Player.pos.y)
--camera:positionAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
end
end
function drawEditor()
if game.width ~= love.graphics.getWidth() or game.height ~= love.graphics.getHeight() then
Camera.height = game.height
Camera.width = game.width
Canvas.Darkness:release()
Canvas.Darkness = CreateDarkness()
love.graphics.setCanvas(Canvas.Darkness)
SetDarkness()
love.graphics.setCanvas()
end
gameworldDraw()
2022-01-18 19:24:49 +00:00
if palette then
paletteDraw()
end
end
function drawGame()
gameworldDraw()
gameworldLighting()
-- HUD
textScale = 0.5
--debug
if debug then DebugUI() end
if debug_collision then
DebugColisions()
DebugEntities()
end
-- reset color
if do_pause then PauseUI() end
end
function gameworldDraw()
2022-01-18 13:02:56 +00:00
-- resize proof
if game_resize then
Camera.height = game.height
Camera.width = game.width
end
local pcr, pcg, pcb, pca = love.graphics.getColor()
love.graphics.scale(game.scale,game.scale)
love.graphics.setColor(1,1,1,1)
LevelDisplayBackground()
2022-01-18 13:02:56 +00:00
for _, enty in pairs(LoadedEntities) do
enty:HandleAnimation()
end
LevelDisplayForeground()
love.graphics.setColor(pcr, pcg, pcb, pca)
end
function gameworldLighting()
2022-01-18 13:02:56 +00:00
if game_resize then
Canvas.Darkness:release()
Canvas.Darkness = CreateDarkness()
love.graphics.setCanvas(Canvas.Darkness)
SetDarkness()
love.graphics.setCanvas()
end
-- work on lighting canvas
love.graphics.setCanvas(Canvas.Darkness)
SetDarkness()
DoLights()
DoBorder()
-- apply to game canvas
love.graphics.setColor(1,1,1,1)
love.graphics.setCanvas()
love.graphics.scale(1,1)
DrawDarkness()
end
2022-01-18 19:24:49 +00:00
function paletteDraw()
local width = LevelData.tileset:getPixelWidth()/tileProperties.width
local height = LevelData.tileset:getPixelHeight()/tileProperties.height
local position_x = 1
local position_y = 1
for i = 1, #TileIndex-width-1 do
love.graphics.draw(
LevelData.tileset,
TileIndex[i],
position_x * tileProperties.width*2,
(--[[p_scroll +]]position_y) * tileProperties.height*2,
0,
2,
2
)
position_x = position_x + 1
if position_x > width then
position_x = position_x - width
position_y = position_y + 1
end
end
love.graphics.rectangle(
"line",
tileProperties.width*2,
(--[[p_scroll +]] 1) * tileProperties.height*2,
2*LevelData.tileset:getPixelWidth(),
2*LevelData.tileset:getPixelHeight()
)
end
--[[
function DrawSelectingPaletteTile()
if selecting_tile ~= nil then
local width = TileProperties.tileset:getPixelWidth()/TileProperties.width
local height = TileProperties.tileset:getPixelHeight()/TileProperties.height
local positionx = 1
local positiony = 1
for i = 1, #Tile-12 do
if i == selecting_tile then
love.graphics.rectangle(
"line",
positionx * TileProperties.width*2,
(p_scroll + positiony) * TileProperties.height*2,
TileProperties.width*2-1,
TileProperties.height*2-1
)
end
positionx = positionx + 1
if positionx > width then
positionx = positionx - width
positiony = positiony + 1
end
end
end
end]]