Moved game loop from main.lua to specific script, sliced it into parts
This commit is contained in:
@@ -18,3 +18,5 @@ require "data/scripts/objects"
|
||||
require "data/scripts/debug"
|
||||
require "data/scripts/keybind"
|
||||
require "data/scripts/pause"
|
||||
-- game loop
|
||||
require "data/scripts/game"
|
||||
|
||||
@@ -4,7 +4,7 @@ Camera = {
|
||||
height = 0
|
||||
}
|
||||
|
||||
function Camera:CenterAt(x,y,cx,cy)
|
||||
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
|
||||
if not (cx == nil or cy == nil) then
|
||||
@@ -19,7 +19,7 @@ function Camera:CenterAt(x,y,cx,cy)
|
||||
self.pos.y = math.floor(self.pos.y)
|
||||
end
|
||||
|
||||
function Camera:ScreenAt(x,y)
|
||||
function Camera:positionAt(x,y)
|
||||
self.pos.x = math.floor(x/self.width)*self.width
|
||||
self.pos.y = math.floor(y/self.height)*self.height
|
||||
end
|
||||
|
||||
87
data/scripts/game.lua
Normal file
87
data/scripts/game.lua
Normal file
@@ -0,0 +1,87 @@
|
||||
function stepEditor()
|
||||
AnimateTiles()
|
||||
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()
|
||||
end
|
||||
|
||||
function drawGame()
|
||||
-- saveproof to game resize
|
||||
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()
|
||||
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()
|
||||
local pcr, pcg, pcb, pca = love.graphics.getColor()
|
||||
|
||||
love.graphics.scale(game.scale,game.scale)
|
||||
love.graphics.setColor(1,1,1,1)
|
||||
LevelDisplayBackground()
|
||||
for _, enty in pairs(LoadedEntities) do
|
||||
enty:HandleAnimation()
|
||||
end
|
||||
LevelDisplayForeground()
|
||||
|
||||
love.graphics.setColor(pcr, pcg, pcb, pca)
|
||||
end
|
||||
|
||||
function gameworldLighting()
|
||||
-- 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
|
||||
Reference in New Issue
Block a user