-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.lua
More file actions
107 lines (81 loc) · 2.71 KB
/
game.lua
File metadata and controls
107 lines (81 loc) · 2.71 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
--[[
Filgrim Engine
game.lua
A 2D platformer engine for LÖVE
By Hoover and Phil
]]
-- Globals
game = {}
game.cameras = {}
game.entities = {}
-- Accessors ==================================================================
function game.getCurrentMap()
-- Returns the current map layer the player is on.
end
function game.getCurrentLevel()
-- Returns the current level.
end
function game.getCurrentCamera()
return game.currentCamera
end
-- Level Functions ============================================================
function game.loadLevel(level)
-- Loads a level and switches to it.
end
-- Entity Functions ===========================================================
function game.addEntity(entity)
table.insert(game.entities, entity)
end
function game.removeEntity(entity)
local position = 0
for _, currentEntity in ipairs(game.entities) do
position = position + 1
if game.entities[position] == entity then break end
end
table.remove(game.entities, position)
end
-- Camera Functions ===========================================================
function game.addCamera(camera)
-- Pushes the camera onto the camera stack and makes it the current camera.
if camera:type() ~= "camera" then error("game.addCamera was passed something that was "..camera:type().."!") end
table.insert(game.cameras, camera)
end
function game.removeCamera(camera)
if camera:type() ~= "camera" then error("game.removeCamera was passed something that was "..camera:type().."!") end
local position = 0
for _, currentEntity in ipairs(game.cameras) do
position = position + 1
if game.cameras[position] == camera then break end
end
table.remove(game.cameras, position)
end
function game.setCurrentCamera(camera)
if camera:type() ~= "camera" then error("game.setMainCamera was passed something that was "..camera:type().."!") end
local position = 0
for _, currentEntity in ipairs(game.cameras) do
position = position + 1
if game.cameras[position] == camera then break end
end
game.currentCamera = game.cameras[position]
end
-- General Game Functions =====================================================
function game.init()
-- Initializes basic game state.
-- Set general LÖVE stuff.
love.graphics.setBackgroundColor(127, 127, 127) -- Should this be in Camera?
-- General Game State
game.paused = false
game.showFPS = true
game.currentLevel = nil
-- Set up a default camera.
local windowWidth, windowHeight = love.graphics.getMode()
local defaultCamera = Camera:new(1, 1, util.makeSize(windowWidth, windowHeight), util.makePoint(0, 0), util.makePoint(120, 110), 2)
game.addCamera(defaultCamera)
game.setCurrentCamera(defaultCamera)
end
function game.loadLevel()
-- TODO: Write me.
end
function game.drawUI()
-- TODO: Write me.
end