-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
47 lines (44 loc) · 1.31 KB
/
index.js
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
var stream = require('stream')
var inherits = require('inherits')
var GameController = require('./gamecontroller/gamecontroller.js').GameController
module.exports = function(opts) {
return new TouchControls(opts)
}
function TouchControls(opts) {
var self = this
this.readable = true
this.controller = GameController
this.controller.init( {
left: {
dpad: {
up: {
touchStart: function() { self.emit('command', 'moveForward', true) },
touchEnd: function() { self.emit('command', 'moveForward', false) }
},
right: {
touchStart: function() { self.emit('command', 'moveRight', true) },
touchEnd: function() { self.emit('command', 'moveRight', false) }
},
down: {
touchStart: function() { self.emit('command', 'moveBackward', true) },
touchEnd: function() { self.emit('command', 'moveBackward', false) }
},
left: {
touchStart: function() { self.emit('command', 'moveLeft', true) },
touchEnd: function() { self.emit('command', 'moveLeft', false) }
}
}
},
right: {
type: 'joystick',
position: { right: '15%', bottom: '15%' },
joystick: {
touchMove: function( ev ) {
ev.dy = ev.dy * -1 // invert controls
self.emit('data', ev)
}
}
}
})
}
inherits(TouchControls, stream.Stream)