-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathflappy-hitler.js
More file actions
57 lines (49 loc) · 1.61 KB
/
Copy pathflappy-hitler.js
File metadata and controls
57 lines (49 loc) · 1.61 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
53
54
55
56
57
module.exports.handleFlappyEvent = (data, game) => {
return;
if (!io.sockets.adapter.rooms[game.general.uid]) {
return;
}
const roomSockets = Object.keys(io.sockets.adapter.rooms[game.general.uid].sockets).map(sockedId => io.sockets.connected[sockedId]);
const updateFlappyRoom = newData => {
roomSockets.forEach(sock => {
if (sock) {
sock.emit('flappyUpdate', newData);
}
});
};
updateFlappyRoom(data);
if (data.type === 'startFlappy') {
game.flappyState = {
controllingLibUser: '',
controllingFascistUser: '',
liberalScore: 0,
fascistScore: 0,
pylonDensity: 1.3,
flapDistance: 1,
pylonOffset: 1.3,
passedPylonCount: 0
};
game.general.status = 'FLAPPY HITLER: 0 - 0';
io.sockets.in(game.general.uid).emit('gameUpdate', game);
game.flappyState.pylonGenerator = setInterval(() => {
const offset = Math.floor(Math.random() * 50 * game.flappyState.pylonOffset);
const newData = {
type: 'newPylon',
pylonType: 'normal',
offset
};
updateFlappyRoom(newData);
}, 1500 * game.flappyState.pylonDensity)[Symbol.toPrimitive]();
}
if (data.type === 'collision') {
game.flappyState[`${data.team}Score`]++;
clearInterval(game.flappyState.pylonGenerator);
// game.general.status = 'FLAPPY HITLER: x - x';
// io.sockets.in(game.general.uid).emit('gameUpdate', game);
}
if (data.type === 'passedPylon') {
game.flappyState.passedPylonCount++;
game.general.status = `FLAPPY HITLER: ${game.flappyState.liberalScore} - ${game.flappyState.fascistScore} (${game.flappyState.passedPylonCount})`;
io.sockets.in(game.general.uid).emit('gameUpdate', game);
}
};