-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrounds.easel
More file actions
175 lines (146 loc) · 4.93 KB
/
rounds.easel
File metadata and controls
175 lines (146 loc) · 4.93 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
pub accumulator owner.HighestElapsedDuration = 0
pub prop owner.PlayerLevel = 1
const LevelMsg = [
null, // Level 0 won't ever be displayed
"Keep going. Let's see how long you can last!",
"Level 2. Seems beginner's luck is on your side!",
"Level 3! Unexpected.",
"Level 4. Bet you won't make it to the next level!",
"Level 5. Let's make things a bit harder for you.",
"Level 6. I can't wait to watch you fail.",
"Level 7. It won't be long until you're out.",
"Level 8. Surprising.",
"Level 9. You'll never make it to double digits!",
"Level 10. How are you doing this???",
"Level 11. I don't think you're capable of any more.",
"Level 12. Go on, make your parents proud.",
"Level 13. Don't worry, it'll be over soon!",
"Level 14. Astounding.",
"Level 15. I never thought you'd make it this far.",
"Level 16. It cannot be!",
"Level 17. Humans always give up.",
"Level 18. Surely you have reached your limit!",
"Level 19. You'll never reach level 20!",
"Level 20. This can't be!",
]
pub fn this.LevelDisplayer([owner]) {
BottomContent {
VStack(padding=1) {
P(fontSize=1.3) {
with PlayerLevel {
%(LevelMsg[PlayerLevel] ?? "Level " + PlayerLevel + ". What???")
}
}
}
}
}
pub fn owner.SubmitHighScore(elapsed) -> isNewHighScore {
if elapsed > HighestElapsedDuration {
HighestElapsedDuration(overwrite=elapsed, showOnLeaderboard=true)
return true
} else {
return false
}
}
pub await fn owner.PlayTutorial {
await Subspawn round {
DiceManipulator
await SpawnNDice(diceNumbers=[5], perNumber=1)
await SpawnNDice(diceNumbers=[6], perNumber=5)
BottomContent {
VStack(padding=1) {
P(fontSize=1.3) {
"Place 5 matching dice along the bottom row"
}
}
}
while AllDice.Length > 1 {
await AllDice
}
Expire
}
}
pub await fn owner.PlayOneRound() -> elapsed {
let duration = 0s
await Subspawn round {
PlayerLevel = 1
DiceManipulator
LevelDisplayer
TopContent {
VStack(padding=1) {
with Tick(1s) {
let totalSeconds = Floor(duration / 1s)
H1 {
let seconds = totalSeconds % 60
let minutes = Floor(totalSeconds / 60)
%(minutes + (seconds < 10 ? ":0" : ":") + seconds)
}
}
}
}
on Tick {
// We count the ticks manually to avoid the exploit where players
// would put their computer to sleep while the clock was ticking up
duration += 1
}
await SpawnNDice(diceNumbers=[1,2,3], perNumber=5)
on Tick {
use spawnInterval = 3s * 0.95 ** PlayerLevel
let diceNumber1 = Floor(1 + 6 * Random)
let diceNumber2 = Floor(1 + 5 * Random)
if diceNumber2 == diceNumber1 {
diceNumber2 += 1
}
await SpawnNDice(diceNumbers=[diceNumber1,diceNumber2], perNumber=5, spawnInterval=)
}
with AllDice {
if !HasEnoughMatchingDice(5) {
await SpawnNDice(diceNumbers=[Floor(1+6*Random)], perNumber=5)
}
}
// Too many dice? Game over
while AllDice.Length < 40 {
await AllDice
}
// Expire dice in a different lifespan so it can outlive the round
Spawn {
for dice in AllDice.OrderBy(|x| x.Pos.Y) {
dice.Expire
await Tick(0.1s)
}
Expire
}
Expire
}
return duration
}
pub await fn owner.GameOverDialog(elapsed, isNewHighScore) {
await Subspawn {
OverlayContent {
VStack(align=Align:Center, gap=1) {
Standout {
FlyInWords("Game over!")
}
P {
"Better luck next time, human!"
}
P {
"You lasted: "
Span(bold=true) { %(Round(elapsed / 1s) + " seconds") }
}
if isNewHighScore {
P(color=#e580ff, bold=true) {
"New high score!"
}
}
await Tick(3s)
HStack(align=Align:Center, animate=Animate:FlyFromBottom) {
RaisedButton(PressIntent<playAgain>, backgroundColor=Color:Primary) { "Play Again" }
RaisedButton(HomePage, backgroundColor=Color:Secondary) { "High Scores" }
}
}
}
await Pressed<playAgain>
Expire
}
}