Moved game loop from main.lua to specific script, sliced it into parts

This commit is contained in:
lustlion
2022-01-18 13:53:58 +01:00
parent d0e849bf3d
commit 0b18fcd369
5 changed files with 103 additions and 74 deletions

View File

@@ -65,21 +65,9 @@ function love.update(dt)
if editor_mode then
AnimateTiles()
stepEditor()
else
-- GAME STEP
if not do_pause then
SetCollisionFlags(main_Player)
for _, enty in pairs(LoadedEntities) do
enty:Smart()
enty:DoPhysics()
end
AnimateTiles()
Camera:CenterAt(main_Player.pos.x, main_Player.pos.y)
--camera:ScreenAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
end
stepGame()
end
end
@@ -96,7 +84,6 @@ function love.wheelmoved(_, y)
end
function love.keypressed(key)
if key == "escape" then
if do_pause then
do_pause = false
@@ -139,60 +126,13 @@ function love.keypressed(key)
end
function love.draw()
-- saveproof to game resize
if game.width ~= love.graphics.getWidth() or game.height ~= love.graphics.getHeight() then
game.width = love.graphics.getWidth()
game.height = love.graphics.getHeight()
Camera.height = game.height
Camera.width = game.width
Canvas.Darkness:release()
Canvas.Darkness = CreateDarkness()
love.graphics.setCanvas(Canvas.Darkness)
SetDarkness()
love.graphics.setCanvas()
end
-- GAME WORLD
love.graphics.scale(game.scale,game.scale)
love.graphics.setColor(1,1,1,1)
LevelDisplayBackground()
for _, enty in pairs(LoadedEntities) do
enty:HandleAnimation()
if game.width ~= love.graphics.getWidth() or game.height ~= love.graphics.getHeight() then
game.width = love.graphics.getWidth()
game.height = love.graphics.getHeight()
end
LevelDisplayForeground()
-- Save color
local pcr, pcg, pcb, pca = love.graphics.getColor()
love.graphics.setCanvas(Canvas.Darkness)
SetDarkness()
DoLights()
DoBorder()
-- reset to screen
love.graphics.setColor(1,1,1,1)
love.graphics.setCanvas()
love.graphics.scale(1,1)
DrawDarkness()
-- HUD
-- Scale control
textScale = 0.5
--debug
if debug then DebugUI() end
if debug_collision then
love.graphics.setCanvas(Canvas.Darkness)
SetDarkness()
love.graphics.setCanvas()
--DrawDarkness()
DebugColisions()
DebugEntities()
if editor_mode then
drawEditor()
else
drawGame()
end
-- reset color
love.graphics.setColor(pcr,pcg,pcb,pca)
local pcr, pcg, pcb, pca = love.graphics.getColor()
if do_pause then PauseUI() end
love.graphics.setColor(pcr,pcg,pcb,pca)
end