-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.coffee
More file actions
41 lines (35 loc) · 1.02 KB
/
app.coffee
File metadata and controls
41 lines (35 loc) · 1.02 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
port = process.env.PORT || 8080
io = require('socket.io').listen(port)
data = {}
gameOn = false
io.sockets.on 'connection',(socket) ->
io.sockets.emit 'debug', {message: 'received'}
data[socket.id]={player: '',position: [0.0,0.0]}
if data.length is 1
data[socket.id].player = "catch me"
else
data[socket.id].player = "I'll catch you"
data[socket.id].position[0]+=0.0001
data[socket.id].position[1]+=0.0001
console.log "data item:"
console.log data
count = 0
for item of data
count++
console.log count
if count > 1
console.log "emit gameon"
gameOn = true
console.log data
io.sockets.emit 'gameon', data
socket.on 'whoami', () ->
socket.emit 'id',socket.id
socket.on 'newgame', () ->
console.log "new game requested"
socket.emit('ok')
socket.on 'joingame', () ->
console.log "joingame requested"
socket.emit('ok')
socket.on 'position', (position) ->
data[socket.id].position=position
console.log "Position received #{data[socket.id].position}"