sourcegames/asteroids/Rocks.xtl
1⍝│ Asteroids' rules, a library: asteroids.xtl (scripted), play.xtl (the
2⍝│ game: keys and the clock) and the web page all use these. Built on
3⍝│ lib/Ecs: a world is a matrix, a row per entity slot, and every rule is
4⍝│ a system over every entity at once. The entities come and go all the
5⍝│ time: every shot is spawned and spent, every rock hit is despawned
6⍝│ and its two halves spawned in the slots that freed. Which slots hold
7⍝│ what is only masks (alive, rock, shot), so the churn needs no lists
8⍝│ kept. A game's state is a tuple: (the world, the score, the lives
9⍝│ left, the wave, the seconds played, how it stands: 0 playing, 1 every
10⍝│ wave cleared, 2 no lives left, the seconds the ship cannot be hit).
11
12"ec:" u̲se< "Ecs"
13"sv:" u̲se< "Svg"
14
15⍝━━ The data
16
17⍝│ The layout: where it is (x then y, in tiles, y down), how fast it
18⍝│ moves, the ship's heading (radians, 0 to the right), a rock's size
19⍝│ (1 small to 3 big), a shot's time left, and what it is.
20"h" ᵉᶜc̲omponents< "pos:2 vel:2 dir size life ship rock shot"
21⍝│ A list of numbers from asteroids.toml.
22ʰn̲ums ← { k → 'ˢᵛn̲um e̲ach "asteroids.toml" ⎕L̲IST k }
23FIELD ← ʰn̲ums "field"
24FX ← f̲irst FIELD
25FY ← 2 s̲elect FIELD
26WAVES ← f̲loor ʰn̲ums "waves"
27RADII ← ʰn̲ums "radii"
28SPEEDS ← ʰn̲ums "speeds"
29POINTS ← f̲loor ʰn̲ums "points"
30ship ← ʰn̲ums "ship"
31TURN ← f̲irst ship
32THRUST ← 2 s̲elect ship
33FAST ← 3 s̲elect ship
34DRAG ← 4 s̲elect ship
35LIVES ← f̲loor 5 s̲elect ship
36SAFE ← 6 s̲elect ship
37gun ← ʰn̲ums "gun"
38SHOT ← f̲irst gun
39FLIGHT ← 2 s̲elect gun
40SHOTS ← 3 s̲elect gun
41
42⍝━━ A new game
43
44⍝│ n by 2 from two columns.
45ʰp̲air ← { (a, b) → o̲\ (2 c̲at t̲ally a) r̲eshape a c̲at b }
46⍝│ Angles in radians from a number of degrees.
47ʰr̲adians ← { d → (p̲i @) × (f̲loat d) ÷ 180.0 }
48⍝│ The world with the entities ids at P, moving at V.
49ʰp̲lace ← { W (ids, P, V) → (W ʰs̲etPos (ids, P)) ʰs̲etVel (ids, V) }
50⍝│ A wave of big rocks (wave k says how many): each on a ring around the
51⍝│ middle, flying off in a direction of its own, all drawn at random.
52ʰw̲ave ← { W k →
53 n ← k s̲elect WAVES
54 (spawned, ids) ← W ᵉᶜs̲pawn n
55 a ← ʰr̲adians r̲oll! n r̲eshape 360
56 b ← ʰr̲adians r̲oll! n r̲eshape 360
57 P ← ʰp̲air ((0.5 × FX) + 7.0 × c̲os a, (0.5 × FY) + 7.0 × s̲in a)
58 V ← ʰp̲air ((3 s̲elect SPEEDS) × c̲os b, (3 s̲elect SPEEDS) × s̲in b)
59 ((spawned ʰp̲lace (ids, P, V)) ʰs̲etSize (ids, 3.0)) ʰs̲etRock (ids, 1.0)
60}
61⍝│ The ship put in the middle, still, heading up.
62ʰc̲enter ← { W me → (W ʰp̲lace (me, (0.5 × FX) c̲at 0.5 × FY, 0.0 0.0)) ʰs̲etDir (me, n̲eg 0.5 × p̲i @) }
63⍝ :: (Any a, Num b, Num c, Num d) => a -> (Float, b, Int, c, Float, d, Float)
64⍝│ A new game: the ship in the middle and the first wave of rocks.
65ˡn̲ew ← { z →
66 (spawned, me) ← (ʰw̲orld 64) ᵉᶜs̲pawn 1
67 (((spawned ʰc̲enter me) ʰs̲etShip (me, 1.0)) ʰw̲ave 1, 0, LIVES, 1, 0.0, 0, SAFE)
68}
69
70⍝━━ The systems
71
72⍝│ The ship, the rocks, the shots alive.
73ʰm̲e ← { W → f̲irst w̲here (ᵉᶜa̲live W) ∧ ʰh̲asShip W }
74ʰr̲ocks ← { W → w̲here (ᵉᶜa̲live W) ∧ ʰh̲asRock W }
75ʰs̲hots ← { W → w̲here (ᵉᶜa̲live W) ∧ ʰh̲asShot W }
76⍝│ Every entity moves by its speed, wrapping around the field's edges;
77⍝│ the ship keeps a little less of its speed.
78ʰm̲ove ← { W dt →
79 c ← w̲here ᵉᶜa̲live W
80 P ← (c s̲elect ʰp̲os W) + dt × c s̲elect ʰv̲el W
81 x ← 1 s̲elect₂ P
82 y ← 2 s̲elect₂ P
83 moved ← W ʰs̲etPos (c, ʰp̲air (x − FX × f̲loat f̲loor x ÷ FX, y − FY × f̲loat f̲loor y ÷ FY))
84 me ← ʰm̲e moved
85 moved ʰs̲etVel (me, DRAG × me s̲elect ʰv̲el moved)
86}
87⍝│ Every shot's time runs down; the spent shots go.
88ʰa̲ge ← { W dt →
89 s ← ʰs̲hots W
90 aged ← W ʰs̲etLife (s, (s s̲elect ʰl̲ife W) − dt)
91 aged ᵉᶜd̲espawn ((s s̲elect ʰl̲ife aged) ≤ 0.0) r̲eplicate s
92}
93⍝│ Which of the points P lie within reach of which rocks r (each its
94⍝│ radius plus more): a table, P's rows down, the rocks across.
95ʰw̲ithin ← { W (P, r, more) →
96 R ← r s̲elect ʰp̲os W
97 dx ← (1 s̲elect₂ P) '− t̲able 1 s̲elect₂ R
98 dy ← (2 s̲elect₂ P) '− t̲able 2 s̲elect₂ R
99 reach ← more + (f̲loor r s̲elect ʰs̲ize W) s̲elect RADII
100 ((dx × dx) + dy × dy) < (s̲hape dx) r̲eshape reach × reach
101}
102⍝│ The world without the entities gone, and with the two halves of each
103⍝│ rock of ids (one of them): where it was, a size smaller, flying at the
104⍝│ smaller size's speed, one turned left of its way and one right,
105⍝│ spawned in the first free slots (the ones just freed among them).
106ʰh̲alves ← { W (ids, gone) →
107 0 = t̲ally ids ? W ᵉᶜd̲espawn gone
108 two ← ((t̲ally ids) r̲eshape 2) r̲eplicate ids
109 n ← t̲ally two
110 V ← two s̲elect ʰv̲el W
111 sz ← (two s̲elect ʰs̲ize W) − 1.0
112 a ← 0.7 × 1.0 − 2.0 × f̲loat (r̲ange n) m̲od 2
113 vx ← ((1 s̲elect₂ V) × c̲os a) − (2 s̲elect₂ V) × s̲in a
114 vy ← ((1 s̲elect₂ V) × s̲in a) + (2 s̲elect₂ V) × c̲os a
115 k ← ((f̲loor sz) s̲elect SPEEDS) ÷ 0.001 m̲ax ((vx × vx) + vy × vy) ^ 0.5
116 P ← two s̲elect ʰp̲os W
117 (spawned, kids) ← (W ᵉᶜd̲espawn gone) ᵉᶜs̲pawn n
118 ((spawned ʰp̲lace (kids, P, ʰp̲air (k × vx, k × vy))) ʰs̲etSize (kids, sz)) ʰs̲etRock (kids, 1.0)
119}
120⍝│ Shots that reach a rock: the shots are spent, the rocks go (their
121⍝│ points scored), and the rocks bigger than small leave two halves each,
122⍝│ spawned in the slots just freed. Every shot against every rock at
123⍝│ once.
124ʰs̲hoot ← { W →
125 s ← ʰs̲hots W
126 r ← ʰr̲ocks W
127 0 = (t̲ally s) × t̲ally r ? (W, 0)
128 H ← W ʰw̲ithin (s s̲elect ʰp̲os W, r, 0.0)
129 hit ← ('∨ r̲/₁ H) r̲eplicate r
130 sz ← f̲loor hit s̲elect ʰs̲ize W
131 big ← (sz > 1) r̲eplicate hit
132 (W ʰh̲alves (big, (('∨ r̲/₂ H) r̲eplicate s) c̲at hit), '+ r̲/ 0 c̲at sz s̲elect POINTS)
133}
134⍝│ A rock that reaches the ship, unless it cannot be hit: a life lost,
135⍝│ the ship back in the middle, safe for a while.
136ʰc̲rash ← { (W, lives, safe) →
137 safe > 0.0 ? (W, lives, safe)
138 me ← ʰm̲e W
139 r ← ʰr̲ocks W
140 0 = t̲ally r ? (W, lives, safe)
141 n̲ot '∨ r̲/ r̲avel W ʰw̲ithin (1 2 r̲eshape me s̲elect ʰp̲os W, r, 0.35) ? (W, lives, safe)
142 (W ʰc̲enter me, lives − 1, SAFE)
143}
144⍝│ When the rocks are all gone: the next wave, or, after the last, won.
145ʰn̲ext ← { (W, wave) →
146 0 < t̲ally ʰr̲ocks W ? (W, wave, 0)
147 wave = t̲ally WAVES ? (W, wave, 1)
148 (W ʰw̲ave wave + 1, wave + 1, 0)
149}
150⍝│ How it stands: won 1, no lives left 2, else 0.
151ʰs̲tanding ← { (won, lives) → won = 1 ? 1◆ lives ≤ 0 ? 2◆ 0 }
152⍝ :: (Num a, Num b) => (Float, Int, a, Int, Float, b, Float) -> Float -> (Float, Int, a, Int, Float, b, Float)
153⍝│ A tick of the clock, dt seconds: everything moves, the shots age, the
154⍝│ shots that reach rocks break them, a rock that reaches the ship costs
155⍝│ a life, and a field cleared brings the next wave; each a system over
156⍝│ every entity at once. A game over stays as it is.
157ˡt̲ick ← { (W, sc, lv, wv, t, st, sf) dt →
158 st > 0 ? (W, sc, lv, wv, t, st, sf)
159 flown ← (W ʰm̲ove dt) ʰa̲ge dt
160 (broken, pts) ← ʰs̲hoot flown
161 (crashed, lives, safe) ← ʰc̲rash (broken, lv, 0.0 m̲ax sf − dt)
162 (next, wave, won) ← ʰn̲ext (crashed, wv)
163 (next, sc + pts, lives, wave, t + dt, ʰs̲tanding (won, lives), safe)
164}
165
166⍝━━ Your keys
167
168⍝│ A shot from the ship's nose, at the ship's speed plus the gun's, unless
169⍝│ the most shots are already in flight.
170ʰf̲ire ← { W me →
171 SHOTS ≤ f̲loat t̲ally ʰs̲hots W ? W
172 d ← me s̲elect ʰd̲ir W
173 u ← (c̲os d) c̲at s̲in d
174 (spawned, ids) ← W ᵉᶜs̲pawn 1
175 P ← (me s̲elect ʰp̲os W) + 0.6 × u
176 V ← (me s̲elect ʰv̲el W) + SHOT × u
177 ((spawned ʰp̲lace (ids, P, V)) ʰs̲etLife (ids, FLIGHT)) ʰs̲etShot (ids, 1.0)
178}
179⍝│ The ship's speed with an up key's added along its heading, no faster
180⍝│ than the fastest.
181ʰt̲hrust ← { W me →
182 d ← me s̲elect ʰd̲ir W
183 v ← (me s̲elect ʰv̲el W) + THRUST × (c̲os d) c̲at s̲in d
184 W ʰs̲etVel (me, v × 1.0 m̲in FAST ÷ 0.001 m̲ax ('+ r̲/ v × v) ^ 0.5)
185}
186⍝ :: (Any a, Any b, Any c, Any d, Num e, Any f) => (Float, a, b, c, d, e, f) -> Char -> (Float, a, b, c, d, e, f)
187⍝│ A key: left and right (or a and d) turn the ship, up (or w) thrusts,
188⍝│ the space bar (or f) fires; other keys, and keys after the game is
189⍝│ over, do nothing.
190ˡk̲ey ← { s name →
191 (W, sc, lv, wv, t, st, sf) ← s
192 me ← ʰm̲e W
193 k ← ("LEFT" "RIGHT" "a" "d" "UP" "w" " " "f") i̲ndexOf e̲nclose name
194 (k > 8) ∨ st > 0 ? s
195 k > 6 ? (W ʰf̲ire me, sc, lv, wv, t, st, sf)
196 k > 4 ? (W ʰt̲hrust me, sc, lv, wv, t, st, sf)
197 (W ʰs̲etDir (me, (me s̲elect ʰd̲ir W) + TURN × f̲loat (2 × (k − 1) m̲od 2) − 1), sc, lv, wv, t, st, sf)
198}
199
200⍝━━ What it shows
201
202⍝ :: (Any a, Any b, Any c, Any d, Any e, Any f, Any g) => (a, b, c, d, e, f, g) -> f
203⍝│ 0 playing, 1 every wave cleared, 2 no lives left.
204ˡs̲tatus ← { (W, sc, lv, wv, t, st, sf) → st }
205⍝ :: (Any a, Any c, Any d, Any e) => (a, b, b, b, c, d, e) -> b
206⍝│ The score, the lives left, the wave.
207ˡs̲core ← { (W, sc, lv, wv, t, st, sf) → sc c̲at lv c̲at wv }
208⍝ :: (Num a, Any b, Any c, Any d, Any e, Any f, Any g) => (a, b, c, d, e, f, g) -> Int
209⍝│ How many are alive: the ship, rocks, shots; and the slots in use.
210ˡc̲ounts ← { (W, sc, lv, wv, t, st, sf) → ('+ r̲/ 0 + (ᵉᶜa̲live W) ∧ ʰh̲asShip W) c̲at (t̲ally ʰr̲ocks W) c̲at (t̲ally ʰs̲hots W) c̲at ᵉᶜc̲ount W }
211⍝ :: (Num a, Any b, Any c, Any d, Any e, Any f, Any g) => (a, b, c, d, e, f, g) -> a
212⍝│ The ship: where it is, its heading, and its speed across and down.
213ˡs̲hip ← { (W, sc, lv, wv, t, st, sf) →
214 me ← ʰm̲e W
215 (me s̲elect ʰp̲os W) c̲at (me s̲elect ʰd̲ir W) c̲at me s̲elect ʰv̲el W
216}
217⍝ :: (Num a, Any b, Any c, Any d, Any e, Any f, Any g) => (a, b, c, d, e, f, g) -> a
218⍝│ The rocks: where each is, a row each.
219ˡr̲ocks ← { (W, sc, lv, wv, t, st, sf) → (ʰr̲ocks W) s̲elect ʰp̲os W }
220⍝│ A number of tiles as units of the picture (40 a tile).
221ʰu̲nits ← { x → ˢᵛw̲hole 40.0 × x }
222⍝│ A rock at x, y of radius z; a shot at x, y.
223ʰd̲rawRock ← { (x, y, z) → e̲nclose @ f̲ormat< "<circle class=\"entity\" cx=\"{h:u_nits x}\" cy=\"{h:u_nits y}\" r=\"{h:u_nits z}\" fill=\"#5c636a\" stroke=\"#ced4da\" stroke-width=\"3\"/>" }
224ʰd̲rawShot ← { (x, y) → e̲nclose @ f̲ormat< "<circle class=\"entity\" cx=\"{h:u_nits x}\" cy=\"{h:u_nits y}\" r=\"4\" fill=\"#ffd166\"/>" }
225⍝│ The ship at x, y heading d; faint while it cannot be hit.
226ʰd̲rawShip ← { (x, y, d, safe) →
227 o ← d̲isclose (1 + safe > 0.0) s̲elect "1" "0.45"
228 e̲nclose @ f̲ormat< "<g class=\"entity you\" opacity=\"{o}\" transform=\"translate({h:u_nits x} {h:u_nits y}) rotate({sv:w_hole d * 180.0 / p_i @})\"><polygon points=\"20,0 -14,-12 -8,0 -14,12\" fill=\"#e9ecef\" stroke=\"#4cc9f0\" stroke-width=\"3\"/></g>"
229}
230⍝│ What the top line says.
231ʰs̲ays ← { (sc, lv, wv, t, st) →
232 st = 1 ? @ f̲ormat< "Every wave cleared! Score {sc} | Time {f_loor t} s"
233 st = 2 ? @ f̲ormat< "Game over. Score {sc} | Time {f_loor t} s"
234 @ f̲ormat< "Score {sc} | Lives {lv} | Wave {wv} of {t_ally WAVES} | Time {f_loor t} s | Arrows, space"
235}
236⍝ :: (Num d, Num e) => (Float, a, b, c, d, e, Float) -> Char
237⍝│ The picture, as SVG text: the field (what crosses an edge cut off),
238⍝│ the rocks, the shots and the ship, and the top line above.
239ˡd̲raw ← { (W, sc, lv, wv, t, st, sf) →
240 v ← 0.0 0.0 c̲at (40.0 × FX) c̲at 60.0 + 40.0 × FY
241 r ← ʰr̲ocks W
242 R ← r s̲elect ʰp̲os W
243 z ← (f̲loor r s̲elect ʰs̲ize W) s̲elect RADII
244 rocks ← '{ i → ʰd̲rawRock (i s̲elect 1 s̲elect₂ R, i s̲elect 2 s̲elect₂ R, i s̲elect z) } e̲ach r̲ange t̲ally r
245 S ← (ʰs̲hots W) s̲elect ʰp̲os W
246 shots ← '{ i → ʰd̲rawShot (i s̲elect 1 s̲elect₂ S, i s̲elect 2 s̲elect₂ S) } e̲ach r̲ange t̲ally S
247 me ← ˡs̲hip (W, sc, lv, wv, t, st, sf)
248 you ← ʰd̲rawShip (f̲irst me, 2 s̲elect me, 3 s̲elect me, sf)
249 clip ← e̲nclose @ f̲ormat< "<clipPath id=\"field\"><rect width=\"{h:u_nits FX}\" height=\"{h:u_nits FY}\"/></clipPath><g transform=\"translate(0 60)\" clip-path=\"url(#field)\">"
250 top ← (20.0, 42.0, 30.0) ˢᵛw̲ords ʰs̲ays (sc, lv, wv, t, st)
251 v ˢᵛp̲icture (v ˢᵛr̲ect "fill=\"#0b0c1a\"") c̲at clip c̲at rocks c̲at shots c̲at you c̲at (e̲nclose "</g>") c̲at top
252}
ᵉᶜc̲omponents< expands to
ʰw̲orld ← { n → (n c̲at 19) r̲eshape 0.0 } ʰp̲os ← { W → (3 4) s̲elect₂ W } ʰh̲asPos ← { W → 0 < 2 s̲elect₂ W } ʰs̲etPos ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 2) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (2 3 4) '= t̲able r̲ange 19 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 3) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropPos ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 2 = r̲ange 19 } ʰv̲el ← { W → (6 7) s̲elect₂ W } ʰh̲asVel ← { W → 0 < 5 s̲elect₂ W } ʰs̲etVel ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 2) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (5 6 7) '= t̲able r̲ange 19 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 3) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropVel ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 5 = r̲ange 19 } ʰd̲ir ← { W → (9) s̲elect₂ W } ʰh̲asDir ← { W → 0 < 8 s̲elect₂ W } ʰs̲etDir ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (8 9) '= t̲able r̲ange 19 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropDir ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 8 = r̲ange 19 } ʰs̲ize ← { W → (11) s̲elect₂ W } ʰh̲asSize ← { W → 0 < 10 s̲elect₂ W } ʰs̲etSize ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (10 11) '= t̲able r̲ange 19 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropSize ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 10 = r̲ange 19 } ʰl̲ife ← { W → (13) s̲elect₂ W } ʰh̲asLife ← { W → 0 < 12 s̲elect₂ W } ʰs̲etLife ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (12 13) '= t̲able r̲ange 19 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropLife ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 12 = r̲ange 19 } ʰs̲hip ← { W → (15) s̲elect₂ W } ʰh̲asShip ← { W → 0 < 14 s̲elect₂ W } ʰs̲etShip ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (14 15) '= t̲able r̲ange 19 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropShip ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 14 = r̲ange 19 } ʰr̲ock ← { W → (17) s̲elect₂ W } ʰh̲asRock ← { W → 0 < 16 s̲elect₂ W } ʰs̲etRock ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (16 17) '= t̲able r̲ange 19 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropRock ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 16 = r̲ange 19 } ʰs̲hot ← { W → (19) s̲elect₂ W } ʰh̲asShot ← { W → 0 < 18 s̲elect₂ W } ʰs̲etShot ← { W (ids, v) → i ← r̲avel ids V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v R ← f̲loat (r̲ange t̲ally W) '= t̲able i C ← f̲loat (18 19) '= t̲able r̲ange 19 M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C } ʰd̲ropShot ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 18 = r̲ange 19 }
f̲ormat< expands to
("<circle class=\"entity\" cx=\"" c̲at (f̲ormat (ʰu̲nits x)) c̲at "\" cy=\"" c̲at (f̲ormat (ʰu̲nits y)) c̲at "\" r=\"" c̲at (f̲ormat (ʰu̲nits z)) c̲at "\" fill=\"#5c636a\" stroke=\"#ced4da\" stroke-width=\"3\"/>")
f̲ormat< expands to
("<circle class=\"entity\" cx=\"" c̲at (f̲ormat (ʰu̲nits x)) c̲at "\" cy=\"" c̲at (f̲ormat (ʰu̲nits y)) c̲at "\" r=\"4\" fill=\"#ffd166\"/>")
f̲ormat< expands to
("<g class=\"entity you\" opacity=\"" c̲at (f̲ormat (o)) c̲at "\" transform=\"translate(" c̲at (f̲ormat (ʰu̲nits x)) c̲at " " c̲at (f̲ormat (ʰu̲nits y)) c̲at ") rotate(" c̲at (f̲ormat (ˢᵛw̲hole d × 180.0 ÷ p̲i @)) c̲at ")\"><polygon points=\"20,0 -14,-12 -8,0 -14,12\" fill=\"#e9ecef\" stroke=\"#4cc9f0\" stroke-width=\"3\"/></g>")
f̲ormat< expands to
("Every wave cleared! Score " c̲at (f̲ormat (sc)) c̲at " | Time " c̲at (f̲ormat (f̲loor t)) c̲at " s")
f̲ormat< expands to
("Game over. Score " c̲at (f̲ormat (sc)) c̲at " | Time " c̲at (f̲ormat (f̲loor t)) c̲at " s")
f̲ormat< expands to
"Score " c̲at (f̲ormat (sc)) c̲at " | Lives " c̲at (f̲ormat (lv)) c̲at " | Wave " c̲at (f̲ormat (wv)) c̲at " of " c̲at (f̲ormat (t̲ally WAVES)) c̲at " | Time " c̲at (f̲ormat (f̲loor t)) c̲at " s | Arrows, space"
f̲ormat< expands to
("<clipPath id=\"field\"><rect width=\"" c̲at (f̲ormat (ʰu̲nits FX)) c̲at "\" height=\"" c̲at (f̲ormat (ʰu̲nits FY)) c̲at "\"/></clipPath><g transform=\"translate(0 60)\" clip-path=\"url(#field)\">")