-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.lua
53 lines (44 loc) · 1.24 KB
/
player.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
local class = require 'ext.class'
local table = require 'ext.table'
local vec3f = require 'vec-ffi.vec3f'
local Player = class()
-- keys to record
Player.gameKeyNames = table{
'up',
'down',
'left',
'right',
}
-- all keys to capture via sdl events
Player.keyNames = table(Player.gameKeyNames):append{
'pause',
}
Player.gameKeySet = Player.gameKeyNames:mapi(function(k)
return true, k
end):setmetatable(nil)
function Player:init(args)
self.index = args.index
local app = assert(args.app)
self.app = app
self.color = vec3f(app.cfg.colors[self.index])
self.keyPress = {}
self.keyPressLast = {}
for _,k in ipairs(self.keyNames) do
self.keyPress[k] = false
self.keyPressLast[k] = false
end
self.pieceTex = app:makeTexWithBlankImage(app.pieceSize)
--[[ don't need to hold onto image
self.pieceTex.data = nil
self.pieceTex.image = nil
--]]
-- ...nah, still needed by:
-- - App:updatePieceTex for calculating pieceColMin and pieceColMax
-- - SandModel:testPieceMerge and SandModel:mergePiece
-- give pieces an outline so you can tell players apart
self.pieceOutlineTex = app:makeTexWithBlankImage(app.pieceOutlineSize)
-- don't need to hold onto image
self.pieceOutlineTex.data = nil
self.pieceOutlineTex.image = nil
end
return Player