Mothback/code/game.lua

105 lines
2.0 KiB
Lua

function restartGame()
for _, entity in ipairs(LoadedObjects.Entities) do
if entity.light ~= nil then entity.light:kill() end
entity = nil
end
LoadedObjects.Entities = {}
LoadedObjects.Particles = {}
main_player = Player:new(75,50)
activateSpawns()
end
function stepGame()
setCollisionFlags()
if menu_type == "no" then
for _, particle in pairs(LoadedObjects.Particles) do
particle:doLogic()
end
for _, enty in pairs(LoadedObjects.Entities) do
enty:doLogic()
end
end
for _, particle in pairs(LoadedObjects.Particles) do
particle:doPhysics()
end
for _, enty in pairs(LoadedObjects.Entities) do
enty:doPhysics()
end
animateTiles()
Camera:followPlayer(main_player)
--Camera:positionCenterAt(main_player.pos.x, main_player.pos.y)
--camera:positionAt(main_player.pos.x, main_player.pos.y,game.width,game.height)
if Keybind:checkPressed(Keybind.debug.debug) then
if debug then
debug = false
debug_collision = true
elseif debug_collision then
debug_collision = false
else
debug = true
end
end
if Keybind:checkPressed(Keybind.debug.reposition) then
restartGame()
end
if Keybind:checkPressed(Keybind.debug.reload) then
clearMenu()
menu_type = "dialog"
initMenu("dialog",dialog_sequence.example)
end
if Keybind:checkPressed(Keybind.debug.recording) then
if DemoRecording then
Demo:endRecord()
else
Demo:startRecord()
end
end
if Keybind:checkPressed(Keybind.debug.playback) then
if DemoPlayback then
Demo:endPlayback()
else
Demo:startPlayback()
end
end
end
function drawGame()
-- prepare
startGameworldDraw()
updateGameWorldLights()
-- background
drawGameworldBackground()
drawGameworldLights()
drawGameworldEntitiesBackground()
-- foreground
drawGameworldForeground()
drawGameworldParticles()
drawGameworldEntities()
if LevelData.properties.darkness then
drawGameworldDarkness()
end
-- end
endGameworldDraw()
-- hud
text_size = 1
-- debug
if debug then debugUI() end
if debug_collision then
debugColisions()
debugEntities()
end
end