-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameState.lua
More file actions
52 lines (41 loc) · 1.05 KB
/
GameState.lua
File metadata and controls
52 lines (41 loc) · 1.05 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
local pg = require('PiroGame/PiroGame');
local debug = require('Debug');
local gs = pg.class('GameState');
function gs:initialize(game)
self.game = game;
self.eventManager = game.eventManager;
self.keySequences = {};
self.keyGroups = {};
end
function gs:activate()
for _, seq in pairs(self.keySequences) do
seq:startListen();
end
end
function gs:deactivate()
for _, seq in pairs(self.keySequences) do
seq:stopListen();
end
end
function gs:addKeySequence(keys, method)
local ks = pg.Input.KeySequence:new(keys, self.game.eventManager);
ks.gameState = self;
ks.activated = method;
table.insert(self.keySequences, ks);
end
function gs:addKeyGroup(keys, method)
local kg = pg.Input.KeyGroup:new(keys);
kg.gameState = self;
kg.update = method;
table.insert(self.keyGroups, kg);
end
function gs:update(dt)
for _, gr in pairs(self.keyGroups) do
if gr:isDown() and type(gr.update) == 'function' then
gr:update(dt);
end
end
end
function gs:draw()
end
return gs;