-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame-select.js
93 lines (92 loc) · 2.29 KB
/
game-select.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const game = {
map: {
// 'select': 'SELECT SCREEN',
'meteor-collect': 'Meteor Collect',
'galaxy-diner': 'Galaxy Diner',
'cosmic-dash': 'Cosmic Dash',
'wave-rider': 'Wave Rider',
'slurp': 'Slurp'
},
starMin: 30,
starMinRadius: 0.005,
starMaxRadius: 0.05,
activate: (players, state) => {
const games = Object.entries(game.map)
const chunk = 1 / games.length
const angleChunk = global.tau * chunk
const angleOffset = global.tau * -0.25
const gameMenuRadius = 0.5
Object.assign(
state,
{
stars: [],
startCircles: games.map(([id, label], index, list) => {
const angle = (index * angleChunk) + angleOffset
return global.createActivityCircle({
id,
label,
x: (Math.cos(angle) * gameMenuRadius),
y: (Math.sin(angle) * gameMenuRadius) + 0.3,
ticksToActivate: 3 * global.ticksPerSecond
})
})
}
)
game.changeModeToIntro(players, state)
},
changeModeToIntro: (players, state) => {
const now = Date.now()
state.mode = 'intro'
state.ships.forEach(ship => {
ship.score = ''
players[ship.id].lastActiveTime = now
})
game.populateInitialStars(state)
},
populateInitialStars: (state) => {
while (state.stars.length < game.starMin) {
state.stars.push(game.createStar(state))
}
},
createStar: (state) => {
const radius = global.rangeRand(
game.starMinRadius,
game.starMaxRadius
)
return {
id: state.stars.length,
x: global.rangeRand(-1, 1),
y: global.rangeRand(-1, 1),
yVel: radius * -0.05,
xVel: 0,
radius: radius
}
},
tickGame: (now, players, state) => {
global.tickPlayers(now, players, state)
game.tickStars(now, state)
state.startCircles.forEach(item => {
let startGame = global.circleSelectCountdown(
now,
item,
players,
state,
true
)
if (startGame) {
delete state.startCircles
delete state.stars
state.events.emit('end', item.id)
}
})
return state
},
tickStars: (now, state) => {
state.stars.forEach(item => {
item.x += item.xVel
item.y += item.yVel
global.wrap(item)
})
}
}
module.exports = game