-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstage.lua
More file actions
48 lines (41 loc) · 1.04 KB
/
stage.lua
File metadata and controls
48 lines (41 loc) · 1.04 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
require ("tilemap")
require("camera")
Stage = class("Stage")
Stage.static.current = nil
--todo (maybe) make this class a singleton
function Stage:initialize()
self.tileMap = nil
self.gameObjects = {}
self.camera = Camera:new()
--Ideally call this when a stage is enabled (if i implement a game state stack)
Stage.static.current = self
end
function Stage:load()
self.tileMap:load()
end
--some factory methods
function Stage:addTileMap(mapLayout, image, tileSize)
local tileMap = TileMap:new(mapLayout, image, tileSize)
self.tileMap = tileMap
return tileMap
end
function Stage:addGameObject()
local gObject = GameObject:new()
table.insert(self.gameObjects, gObject)
return gObject
end
function Stage:update()
for _, gameObject in pairs(self.gameObjects) do
gameObject:update()
end
end
--todo draw layers
function Stage:draw()
self.camera:apply()
self.tileMap:draw()
for _, gameObject in pairs(self.gameObjects) do
gameObject:draw()
end
self.camera:revert()
--ui stuff (either a different camera or just default transformmation)
end