-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.easel
More file actions
156 lines (133 loc) · 4.9 KB
/
main.easel
File metadata and controls
156 lines (133 loc) · 4.9 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
pub const CameraAspectRatio = 16/9
pub const VBoundaryRadius = 30
pub const HBoundaryRadius = VBoundaryRadius * CameraAspectRatio
pub accumulator owner.BestPollenPerMinute
pub game fn World.Main() {
Camera(@(0,0), radius=VBoundaryRadius, aspectRatio=CameraAspectRatio)
ButtonRemap(Tap, Click)
Music(@beelines.mp3, loop=true)
Toolbar {
VolumeToggle
}
SpawnEachPlayer owner {
HasPlayedBefore = true
BeeSwarmControls
TopTransmission {
InsetPanel {
P {
Span(bold=true, color=#b0f) {
TouchscreenOnly { "Tap and drag" }
NonTouchscreenOnly { "Click and drag" }
}
" to guide your bees and help them collect the pollen more efficiently. "
}
}
}
loop {
await PlayOneRound
}
}
}
await fn PlayOneRound([owner]) {
await Spawn {
PollenCollected = 0
SolidBackground(color=#243, priority=1)
repeat 5 {
Subspawn unit {
Bee
}
}
repeat 100 {
Subspawn flower {
Flower
}
}
let initialPollenCount = QueryCount(filter=Category:Pollen)
use start = Tick
// During game HUD
await Subspawn {
BottomContent {
VStack(align=Align:Center) {
with Tick(1s) {
let duration = (Tick - start).Max(1)
P { %(FormatDuration(duration)) }
// Use Max(0.5) so that the number only goes up for the first half a minute (to be encouraging)
P(bold=true) { %((PollenCollected / (duration/1m).Max(0.5)).FormatWithDecimals(1) + " pollen per minute") }
}
}
}
BottomContent {
VStack {
with PollenCollected {
Panel(use width=50, zStack=true, height=2) {
let pollenRemaining = initialPollenCount - PollenCollected
ZOverlay(align=Align:Left) {
Panel(width = width * (PollenCollected / initialPollenCount), backgroundColor=#fc0) {
Blank(height=1)
}
}
ZOverlay {
%(pollenRemaining + " pollen remaining")
}
}
}
Blank(height=1)
}
}
while PollenCollected < initialPollenCount {
await PollenCollected
}
Expire
}
// Post-game HUD
let duration = (Tick - start).Max(1)
let pollenPerMinute = PollenCollected / (duration/1m)
let isHighScore = false
if pollenPerMinute > BestPollenPerMinute {
isHighScore = true
BestPollenPerMinute(overwrite=pollenPerMinute, showOnLeaderboard=true)
}
await Subspawn {
OverlayContent {
VStack(align=Align:Center) {
H1(fontSize=4) {
FlyInWords("All pollen collected!")
}
InsetPanel(align=Align:Center) {
P {
"Pollen collected: "
Span(bold=true) { %(PollenCollected) }
}
P {
"Time taken: "
Span(bold=true) { %(FormatDuration(duration)) }
}
P {
"Pollen collection rate: "
Span(bold=true) {
%(pollenPerMinute.FormatWithDecimals(1))
" pollen per minute"
}
}
if isHighScore {
P(bold=true, color=#e580ff) { "New high score!" }
}
}
HStack(align=Align:Center) {
RaisedButton(HomePage, backgroundColor=Color:Secondary) { "High Scores" }
RaisedButton(PressIntent<playAgain>, backgroundColor=Color:Primary) { "Play Again" }
}
}
}
await Pressed<playAgain>
Expire
}
Expire
}
}
pub fn FormatDuration(duration) -> string {
let totalSeconds = duration / 1s
let seconds = Floor(totalSeconds % 60)
let minutes = Floor(totalSeconds / 60)
return seconds > 0 ? minutes + "m " + seconds + "s" : minutes + "m"
}