/
state_ingame.lua
66 lines (40 loc) · 1.14 KB
/
state_ingame.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
-- Rocks-n-Blaster -- #LD48 -- by <weldale@gmail.com>
InGameState = GameState:subclass("InGameState")
function InGameState:initialize()
self.addEntities = {}
end
function InGameState:onActivation(map, mapFile)
self.mapFile = mapFile
self.map = map
gameManager = GameManager:new(self)
end
function InGameState:addEntity(e)
table.insert(self.addEntities, e)
end
function InGameState:draw()
local tx = 160 - (self.map.width * self.map.tileWidth)/2
local ty = 120 - (self.map.height * self.map.tileHeight)/2
love.graphics.translate(tx, ty)
self.map:autoDrawRange(tx, ty)
self.map:draw()
end
function InGameState:update(dt)
self.map:callback("update", dt)
for _,e in ipairs(self.addEntities) do
table.insert(self.map("Objects").objects, e)
end
self.addEntities = {}
end
function InGameState:keypressed(key)
if key == keyconfig.reset then
gameManager:resetMap()
--elseif key == "f11" then
-- gameManager:nextMap()
elseif key == "escape" then
gameStateManager:changeState(MainMenuState, self.mapFile)
end
self.map:callback("keypressed", key)
end
function InGameState:keyreleased(key)
self.map:callback("keyreleased",key)
end