-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
92 lines (74 loc) · 2.05 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--[[
Filgrim Engine
main.lua
A 2D platformer engine for LÖVE
By Hoover and Phil
]]
-- Modules
require("utilities")
require("philgrim_debug")
require("game")
require("camera")
require("map")
require("entity")
require("character")
require("player")
-- Löve's General Callback Functions ==========================================
function love.load(arg)
--if arg[#arg] == "-debug" then require("mobdebug").start() end
print("Loading...")
game.init()
--game.loadLevel("titleSequence")
-- Set up our map and test entity.
-- TODO: Remove for release.
debug.createDebugMap()
debug.createTestEntity()
end
function love.focus(f)
if not f then
game.paused = true
print(love.graphics.getCaption().." lost focus!")
else
game.paused = false
print(love.graphics.getCaption().." gained focus!")
end
end
function love.quit()
print("Quitting...")
end
-- Love's Game Loop Callbacks =================================================
function love.update(dt)
-- Don't do anything if we're paused.
if game.paused then return end
local camera = game.getCurrentCamera()
-- Updates all the entities in the level. Pass in the deltaTime value.
for _, currentEntity in ipairs(game.entities) do
currentEntity:update(dt)
end
-- Update camera position.
camera:trackEntity(debug.testEntity)
-- Update the map.
for _, currentMap in ipairs(game.maps) do
currentMap:update(camera)
end
end
function love.draw()
-- Store the current graphics state.
love.graphics.push()
-- Scale the view.
love.graphics.scale(game.currentCamera:getScale())
-- Draw the map layers, from back to front.
-- TODO: This needs to take the map z order into account. And what about entities?
for _, currentMap in ipairs(game.maps) do
currentMap:draw(game.currentCamera)
end
for _, currentEntity in ipairs(game.entities) do
currentEntity:draw(game.currentCamera)
end
-- Restore the previous graphics state.
love.graphics.pop()
-- Draw any UI here.
game.drawUI()
-- Draw any debug crap here.
if game.showFPS then love.graphics.print("FPS: "..love.timer.getFPS(), 15, 20) end
end