sourcegames/tower-defense/Defense.xtl
1⍝│ Tower defense's rules, a library: tower-defense.xtl (scripted),
2⍝│ play.xtl (the game: clicks, keys and the clock) and the web page all
3⍝│ use these. Built on lib/Ecs: the creeps, the towers and their shots
4⍝│ are rows of one world, and every rule is a system over all of them at
5⍝│ once. The game is 2D underneath (a grid of tiles and a road) and
6⍝│ drawn in 2.5D: an isometric god's-eye view, every point of the board
7⍝│ turned into the picture by one linear map (and a click turned back by
8⍝│ its inverse). A game's state is a tuple: (the world, the money, the
9⍝│ lives, the waves begun, the creeps still to come, the seconds to the
10⍝│ next, the tower picked to build, the view (0 the board, 1 the
11⍝│ grimoire), the grimoire's page, the seconds played, how it stands: 0
12⍝│ playing, 1 every wave beaten, 2 no lives left; how fast the game
13⍝│ runs (1, 2 or 4 times), and what the last click or key did).
14
15"ec:" u̲se< "Ecs"
16"sv:" u̲se< "Svg"
17"t:" u̲se< "Text"
18
19⍝━━ The data
20
21⍝│ The layout: where it is (x then y, in tiles), what kind (1 to 3) and
22⍝│ level, how far a creep has come along the road, its hit points, the
23⍝│ seconds it is slowed, a tower's seconds to its next shot, a shot's
24⍝│ target (an entity), damage, splash and chill, and what it is.
25"h" ᵉᶜc̲omponents< "pos:2 kind level prog hp slow cool target dmg area chill tower creep shot"
26⍝│ The map: R rows of C tiles, row by row; the grass as 1s, the road as
27⍝│ 1s.
28rows ← "td.toml" ⎕L̲IST "map"
29cells ← ᵗj̲oin rows
30R ← t̲ally rows
31C ← (t̲ally cells) d̲iv R
32GRASS ← 0 + cells = f̲irst "."
33ROAD ← 1 − GRASS
34⍝│ A distance beyond any on the map.
35FAR ← 1000000
36⍝│ The road's tiles in order, from S to E: every road tile's distance to
37⍝│ E by a flood (each one more than its nearest road neighbor, all at
38⍝│ once, until nothing changes), then the tiles sorted by it, farthest
39⍝│ first. The road is one path, so that order is the way along it.
40ʰs̲hift ← { d k →
41 k > 0 ? (k d̲rop d) c̲at k r̲eshape FAR
42 ((n̲eg k) r̲eshape FAR) c̲at ((t̲ally d) + k) t̲ake d
43}
44COL ← ((r̲ange t̲ally cells) − 1) m̲od C
45ʰf̲lood ← { d →
46 e ← (FAR × GRASS) m̲ax d m̲in 1 + ((FAR × 0 + COL = C − 1) m̲ax d ʰs̲hift 1) m̲in ((FAR × 0 + COL = 0) m̲ax d ʰs̲hift -1) m̲in (d ʰs̲hift C) m̲in d ʰs̲hift n̲eg C
47 '∧ r̲/ e = d ? d
48 ʰf̲lood e
49}
50DIST ← ʰf̲lood FAR × 0 + (r̲ange t̲ally cells) ≠ f̲irst w̲here cells = f̲irst "E"
51PATH ← (g̲rade n̲eg (w̲here ROAD) s̲elect DIST) s̲elect w̲here ROAD
52PX ← 0.5 + f̲loat (PATH − 1) m̲od C
53PY ← 0.5 + f̲loat (PATH − 1) d̲iv C
54⍝│ How long the road is, in tiles.
55LONG ← (t̲ally PATH) − 1
56⍝│ A column of a table from td.toml as numbers.
57ʰc̲ol ← { T j → 'ˢᵛn̲um e̲ach j s̲elect₂ T }
58⍝│ The towers, a row per kind and level (arrow 1 to 3, cannon 1 to 3,
59⍝│ frost 1 to 3).
60TT ← ("td.toml" "tower") ⎕T̲ABLE ("towers" "tower-fields")
61RANGE ← TT ʰc̲ol 2
62DAMAGE ← TT ʰc̲ol 3
63COOLDOWN ← TT ʰc̲ol 4
64SPLASH ← TT ʰc̲ol 5
65CHILL ← TT ʰc̲ol 6
66COST ← f̲loor TT ʰc̲ol 7
67⍝│ The creeps, a row per kind.
68CT ← ("td.toml" "creep") ⎕T̲ABLE ("creeps" "creep-fields")
69HP ← CT ʰc̲ol 2
70SPEED ← CT ʰc̲ol 3
71ARMOR ← CT ʰc̲ol 4
72BOUNTY ← f̲loor CT ʰc̲ol 5
73LEAK ← f̲loor CT ʰc̲ol 6
74LETTERS ← ᵗj̲oin 7 s̲elect₂ CT
75⍝│ The waves, the money and lives at the start, the art switch.
76WAVES ← "td.toml" ⎕L̲IST "waves"
77start ← f̲loor 'ˢᵛn̲um e̲ach "td.toml" ⎕L̲IST "start"
78ART ← "1" m̲atch d̲isclose f̲irst "td.toml" ⎕L̲IST "art"
79⍝│ The pieces' names in the art: the towers by kind and level, then the
80⍝│ creeps (the grimoire's pages are in this order too).
81PIECES ← "arrow-1" "arrow-2" "arrow-3" "cannon-1" "cannon-2" "cannon-3" "frost-1" "frost-2" "frost-3" "runner" "brute" "shield"
82⍝│ A shot's speed, tiles a second; the seconds between creeps.
83SHOT ← 9.0
84GAP ← 1.0
85
86⍝━━ A new game
87
88⍝│ n by 2 from two columns.
89ʰp̲air ← { (a, b) → o̲\ (2 c̲at t̲ally a) r̲eshape a c̲at b }
90⍝│ n rows, each the value v_i, m wide; and n rows each v, m wide.
91ʰr̲ows ← { (v, m) → o̲\ (m c̲at t̲ally v) r̲eshape v }
92ʰc̲ols ← { (v, n) → (n c̲at t̲ally v) r̲eshape v }
93⍝ :: (Any a, Num b, Num c, Num d, Num e, Num f, Num g, Num h) => a -> (Float, Int, Int, b, c, Float, d, e, f, Float, g, h, Char)
94⍝│ A new game: an empty world, the money and lives from td.toml, no wave
95⍝│ begun, the arrow tower picked.
96ˡn̲ew ← { z → (ʰw̲orld 96, f̲irst start, 2 s̲elect start, 0, 0 r̲eshape 0, 0.0, 1, 0, 1, 0.0, 0, 1, "Pick a tower below, click the grass to build it; click a tower to upgrade it (its cost is over it).") }
97
98⍝━━ The systems
99
100⍝│ The creeps, the towers, the shots alive.
101ʰc̲reeps ← { W → w̲here (ᵉᶜa̲live W) ∧ ʰh̲asCreep W }
102ʰt̲owers ← { W → w̲here (ᵉᶜa̲live W) ∧ ʰh̲asTower W }
103ʰs̲hots ← { W → w̲here (ᵉᶜa̲live W) ∧ ʰh̲asShot W }
104⍝│ Where along the road the creeps are, from how far each has come: the
105⍝│ segment it is on and how far along it, every creep at once.
106ʰa̲long ← { p →
107 i ← 0 m̲ax (LONG − 1) m̲in f̲loor p
108 f ← p − f̲loat i
109 x ← ((i + 1) s̲elect PX) + f × ((i + 2) s̲elect PX) − (i + 1) s̲elect PX
110 y ← ((i + 1) s̲elect PY) + f × ((i + 2) s̲elect PY) − (i + 1) s̲elect PY
111 ʰp̲air (x, y)
112}
113⍝│ The next creep of the wave onto the road, when its time has come.
114ʰs̲pawning ← { (W, q, tm) →
115 (0 = t̲ally q) ∨ tm > 0.0 ? (W, q, tm)
116 (spawned, ids) ← W ᵉᶜs̲pawn 1
117 k ← f̲irst q
118 creep ← ((spawned ʰs̲etCreep (ids, 1.0)) ʰs̲etKind (ids, f̲loat k)) ʰs̲etProg (ids, 0.0)
119 fresh ← ((creep ʰs̲etHp (ids, k s̲elect HP)) ʰs̲etSlow (ids, 0.0)) ʰs̲etPos (ids, ʰa̲long 1 r̲eshape 0.0)
120 (fresh, 1 d̲rop q, GAP)
121}
122⍝│ Every creep comes along the road by its speed (half while slowed);
123⍝│ the creeps past E get out, and cost their lives.
124ʰc̲rawl ← { W dt →
125 c ← ʰc̲reeps W
126 0 = t̲ally c ? (W, 0)
127 k ← f̲loor c s̲elect ʰk̲ind W
128 sl ← c s̲elect ʰs̲low W
129 p ← (c s̲elect ʰp̲rog W) + dt × (k s̲elect SPEED) × 1.0 − 0.5 × f̲loat sl > 0.0
130 moved ← ((W ʰs̲etProg (c, p)) ʰs̲etSlow (c, 0.0 m̲ax sl − dt)) ʰs̲etPos (c, ʰa̲long p)
131 out ← p ≥ f̲loat LONG
132 (moved ᵉᶜd̲espawn out r̲eplicate c, '+ r̲/ 0 c̲at out r̲eplicate k s̲elect LEAK)
133}
134⍝│ A tower's row in the towers' table: its kind and level.
135ʰr̲ow ← { W tw → (3 × (f̲loor tw s̲elect ʰk̲ind W) − 1) + f̲loor tw s̲elect ʰl̲evel W }
136⍝│ The towers aim and shoot: every tower against every creep at once (a
137⍝│ table, towers down, creeps across), each ready tower at the creep in
138⍝│ its reach that has come farthest, a shot spawned for each.
139ʰa̲im ← { W dt →
140 tw ← ʰt̲owers W
141 0 = t̲ally tw ? W
142 cool ← 0.0 m̲ax (tw s̲elect ʰc̲ool W) − dt
143 cooled ← W ʰs̲etCool (tw, cool)
144 c ← ʰc̲reeps cooled
145 0 = t̲ally c ? cooled
146 j ← cooled ʰr̲ow tw
147 T ← tw s̲elect ʰp̲os cooled
148 P ← c s̲elect ʰp̲os cooled
149 dx ← (1 s̲elect₂ T) '− t̲able 1 s̲elect₂ P
150 dy ← (2 s̲elect₂ T) '− t̲able 2 s̲elect₂ P
151 reach ← ʰr̲ows (j s̲elect RANGE, t̲ally c)
152 S ← (f̲loat ((dx × dx) + dy × dy) ≤ reach × reach) × ʰc̲ols (1.0 + c s̲elect ʰp̲rog cooled, t̲ally tw)
153 best ← 'm̲ax r̲/₂ S
154 pick ← 'm̲in r̲/₂ (ʰc̲ols (r̲ange t̲ally c, t̲ally tw)) + 1000 × 0 + S < ʰr̲ows (best, t̲ally c)
155 ready ← (cool ≤ 0.0) ∧ best > 0.0
156 n ← '+ r̲/ 0 + ready
157 0 = n ? cooled
158 from ← ready r̲eplicate tw
159 js ← ready r̲eplicate j
160 (spawned, ids) ← cooled ᵉᶜs̲pawn n
161 aimed ← ((spawned ʰs̲etShot (ids, 1.0)) ʰs̲etPos (ids, from s̲elect ʰp̲os spawned)) ʰs̲etTarget (ids, f̲loat (ready r̲eplicate pick) s̲elect c)
162 loaded ← ((aimed ʰs̲etDmg (ids, js s̲elect DAMAGE)) ʰs̲etArea (ids, js s̲elect SPLASH)) ʰs̲etChill (ids, js s̲elect CHILL)
163 loaded ʰs̲etCool (from, js s̲elect COOLDOWN)
164}
165⍝│ Shots that reach their target: every hitting shot against every creep
166⍝│ at once (shots down, creeps across): the target, and with a splash
167⍝│ every creep near where it lands, takes the shot's damage less its
168⍝│ armor (never below 1); a chill slows them.
169ʰi̲mpact ← { W hs →
170 c ← ʰc̲reeps W
171 tg ← f̲loor hs s̲elect ʰt̲arget W
172 I ← tg s̲elect ʰp̲os W
173 P ← c s̲elect ʰp̲os W
174 dx ← (1 s̲elect₂ I) '− t̲able 1 s̲elect₂ P
175 dy ← (2 s̲elect₂ I) '− t̲able 2 s̲elect₂ P
176 area ← ʰr̲ows (hs s̲elect ʰa̲rea W, t̲ally c)
177 H ← (tg '= t̲able c) ∨ (area > 0.0) ∧ ((dx × dx) + dy × dy) ≤ area × area
178 arm ← ʰc̲ols ((f̲loor c s̲elect ʰk̲ind W) s̲elect ARMOR, t̲ally hs)
179 D ← (f̲loat H) × 1.0 m̲ax (ʰr̲ows (hs s̲elect ʰd̲mg W, t̲ally c)) − arm
180 cold ← 'm̲ax r̲/₁ (f̲loat H) × ʰr̲ows (hs s̲elect ʰc̲hill W, t̲ally c)
181 (W ʰs̲etHp (c, (c s̲elect ʰh̲p W) − '+ r̲/₁ D)) ʰs̲etSlow (c, (c s̲elect ʰs̲low W) m̲ax cold)
182}
183⍝│ Every shot flies at its target; shots whose target is gone vanish,
184⍝│ and those that reach it hit (and go).
185ʰf̲ly ← { W dt →
186 all ← ʰs̲hots W
187 0 = t̲ally all ? W
188 alive ← (ᵉᶜa̲live W) ∧ ʰh̲asCreep W
189 ok ← (f̲loor all s̲elect ʰt̲arget W) s̲elect alive
190 kept ← W ᵉᶜd̲espawn (n̲ot ok) r̲eplicate all
191 s ← ok r̲eplicate all
192 0 = t̲ally s ? kept
193 S ← s s̲elect ʰp̲os kept
194 D ← ((f̲loor s s̲elect ʰt̲arget kept) s̲elect ʰp̲os kept) − S
195 far ← ('+ r̲/₂ D × D) ^ 0.5
196 k ← 1.0 m̲in (SHOT × dt) ÷ 0.001 m̲ax far
197 flown ← kept ʰs̲etPos (s, S + D × ʰp̲air (k, k))
198 hs ← (far ≤ SHOT × dt) r̲eplicate s
199 0 = t̲ally hs ? flown
200 (flown ʰi̲mpact hs) ᵉᶜd̲espawn hs
201}
202⍝│ The creeps with no hit points left are beaten: their money is won,
203⍝│ and they go.
204ʰb̲eaten ← { W →
205 c ← ʰc̲reeps W
206 dead ← ((c s̲elect ʰh̲p W) ≤ 0.0) r̲eplicate c
207 (W ᵉᶜd̲espawn dead, '+ r̲/ 0 c̲at (f̲loor dead s̲elect ʰk̲ind W) s̲elect BOUNTY)
208}
209⍝│ How it stands: no lives 2, every wave begun and beaten 1, else 0.
210ʰo̲utcome ← { (lv, wv, q, W) →
211 lv ≤ 0 ? 2
212 (wv = t̲ally WAVES) ∧ (0 = t̲ally q) ∧ 0 = t̲ally ʰc̲reeps W ? 1
213 0
214}
215⍝ :: (Any a, Num b, Any c, Num d, Num e, Any f) => (Float, Int, Int, Int, Int, Float, a, b, c, Float, d, e, f) -> Float -> (Float, Int, Int, Int, Int, Float, a, b, c, Float, d, e, f)
216⍝│ A tick of the clock, dt seconds: the next creep comes, the creeps
217⍝│ come along the road, the towers shoot, the shots fly and hit, the
218⍝│ beaten creeps pay; each a system over every entity at once. While the
219⍝│ grimoire is open the board waits (only the time moves, for its
220⍝│ turning pictures). A game over stays as it is.
221ˡt̲ick ← { s dt →
222 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) ← s
223 st > 0 ? s
224 md = 1 ? (W, mo, lv, wv, q, tm, sel, md, pg, t + dt, st, sp, ms)
225 d ← dt × f̲loat sp
226 (spawned, coming, wait) ← ʰs̲pawning (W, q, tm − d)
227 (crawled, lost) ← spawned ʰc̲rawl d
228 (kept, won) ← ʰb̲eaten (crawled ʰa̲im d) ʰf̲ly d
229 lives ← lv − lost
230 (kept, mo + won, lives, wv, coming, wait, sel, md, pg, t + d, ʰo̲utcome (lives, wv, coming, kept), sp, ms)
231}
232
233⍝━━ Clicks and keys
234
235⍝│ The next wave on its way, when the last is over.
236ʰw̲ave ← { s →
237 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) ← s
238 wv ≥ t̲ally WAVES ? ʰs̲aid (s, "That was the last wave.")
239 (0 < t̲ally q) ∨ 0 < t̲ally ʰc̲reeps W ? ʰs̲aid (s, "Beat this wave first.")
240 (W, mo, lv, wv + 1, LETTERS i̲ndexOf d̲isclose (wv + 1) s̲elect WAVES, 0.0, sel, md, pg, t, st, sp, @ f̲ormat< "Wave {wv + 1} is coming.")
241}
242⍝│ The tower whose box holds the point xy of the picture (the nearest
243⍝│ one when boxes overlap), or 0: every tower's box tested at once.
244ʰt̲owerAt ← { W xy →
245 tw ← ʰt̲owers W
246 0 = t̲ally tw ? 0
247 P ← tw s̲elect ʰp̲os W
248 sx ← ʰs̲x (1 s̲elect₂ P, 2 s̲elect₂ P)
249 sy ← ʰs̲y (1 s̲elect₂ P, 2 s̲elect₂ P, 0.0)
250 z ← ʰb̲oxZ tw s̲elect ʰl̲evel W
251 x ← f̲irst xy
252 y ← 2 s̲elect xy
253 in ← ((a̲bs x − sx) ≤ 18.0) ∧ (y ≤ sy + 10.0) ∧ y ≥ sy − z
254 n̲ot '∨ r̲/ in ? 0
255 (f̲irst g̲rade n̲eg ((f̲loat in) × 1000.0) + '+ r̲/₂ P) s̲elect tw
256}
257⍝│ How tall a tower stands in the picture, by level: its picture, or
258⍝│ its box.
259ʰb̲oxZ ← { l → ART ? (s̲hape l) r̲eshape 0.85 × SPRITE◆ 26.0 + 10.0 × l }
260⍝│ The tower on tile k (a number from 1), or 0.
261ʰo̲n ← { W k →
262 tw ← ʰt̲owers W
263 T ← tw s̲elect ʰp̲os W
264 at ← (1 + (C × f̲loor 2 s̲elect₂ T) + f̲loor 1 s̲elect₂ T) = k
265 f̲irst (at r̲eplicate tw) c̲at 0
266}
267⍝│ A click on tile k: a tower of the kind picked built there (on grass,
268⍝│ if the money is there), or the tower there upgraded (to level 3).
269ʰb̲uild ← { s k →
270 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) ← s
271 k = 0 ? s
272 0 = k s̲elect GRASS ? ʰs̲aid (s, "Towers go on the grass, not the road.")
273 tw ← W ʰo̲n k
274 tw > 0 ? ʰu̲pgrade (s, tw)
275 cost ← (1 + 3 × sel − 1) s̲elect COST
276 cost > mo ? ʰs̲aid (s, @ f̲ormat< "That tower costs {cost}; the money is {mo}.")
277 (spawned, ids) ← W ᵉᶜs̲pawn 1
278 tower ← ((spawned ʰs̲etTower (ids, 1.0)) ʰs̲etKind (ids, f̲loat sel)) ʰs̲etLevel (ids, 1.0)
279 built ← (tower ʰs̲etCool (ids, 0.0)) ʰs̲etPos (ids, (0.5 + f̲loat (k − 1) m̲od C) c̲at 0.5 + f̲loat (k − 1) d̲iv C)
280 (built, mo − cost, lv, wv, q, tm, sel, md, pg, t, st, sp, @ f̲ormat< "Built: {d_isclose (1 + 3 * sel - 1) s_elect 1 s_elect_2 TT} ({cost}). Click it to upgrade.")
281}
282ʰu̲pgrade ← { (s, tw) →
283 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) ← s
284 l ← f̲loor tw s̲elect ʰl̲evel W
285 l ≥ 3 ? ʰs̲aid (s, "That tower is at the top level.")
286 cost ← (1 + (W ʰr̲ow tw)) s̲elect COST
287 cost > mo ? ʰs̲aid (s, @ f̲ormat< "The upgrade costs {cost}; the money is {mo}.")
288 (W ʰs̲etLevel (tw, f̲loat l + 1), mo − cost, lv, wv, q, tm, sel, md, pg, t, st, sp, @ f̲ormat< "Upgraded to {d_isclose (1 + (W h:r_ow tw)) s_elect 1 s_elect_2 TT} (level {l + 1}, {cost}).")
289}
290⍝│ The grimoire's pages: the nine towers by kind and level, then the
291⍝│ three creeps.
292PAGES ← 12
293⍝│ The state with a new message.
294ʰs̲aid ← { (s, m) →
295 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) ← s
296 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, m)
297}
298⍝│ The game run faster: 1, 2, 4 times, then 1 again.
299ʰf̲aster ← { s →
300 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) ← s
301 n ← (1 + (1 2 4 i̲ndexOf sp) m̲od 3) s̲elect 1 2 4
302 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, n, @ f̲ormat< "Speed {n}x.")
303}
304⍝│ The view and the picked tower changed.
305ʰs̲et ← { s (sel, md, pg) →
306 (W, mo, lv, wv, q, tm, a, b, c, t, st, sp, ms) ← s
307 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms)
308}
309⍝│ The board's view: the picture's units of a tile, where tile (0, 0)'s
310⍝│ corner is, the toolbar's buttons and the grimoire's.
311TW ← 32.0
312TH ← 16.0
313OX ← 352.0
314OY ← 96.0
315VIEW ← 0.0 0.0 880.0 600.0
316BAR ← 6 4 r̲eshape 12 532 132 52 156 532 132 52 300 532 132 52 444 532 132 52 588 532 132 52 732 532 136 52.0
317BOOK ← 3 4 r̲eshape 60 520 180 52 260 520 180 52 640 520 180 52.0
318⍝│ The tile under a point of the picture (a number from 1), or 0 off the
319⍝│ map: the inverse of the board's map.
320ʰt̲ile ← { xy →
321 a ← ((f̲irst xy) − OX) ÷ TW
322 b ← ((2 s̲elect xy) − OY) ÷ TH
323 gx ← f̲loor 0.5 × a + b
324 gy ← f̲loor 0.5 × b − a
325 (gx < 0) ∨ (gy < 0) ∨ (gx ≥ C) ∨ gy ≥ R ? 0
326 1 + (C × gy) + gx
327}
328⍝ :: (Any a, Num b, Any c, Num d, Num e) => (Float, Int, a, Int, Int, Float, Int, b, Int, c, d, e, Char) -> Float -> (Float, Int, a, Int, Int, Float, Int, b, Int, c, d, e, Char)
329⍝│ A click at xy (the picture's units): in the grimoire its buttons
330⍝│ (back, next, close; a click outside it closes it too); on the board the toolbar (a tower to build, the
331⍝│ next wave, the speed, the grimoire), a tower (upgrade it: anywhere on
332⍝│ its box, which stands up over the tiles behind it) or a tile (build
333⍝│ there).
334ˡc̲lick ← { s xy →
335 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) ← s
336 st > 0 ? s
337 md = 1 ? ʰb̲ook (s, ʰb̲ookHit xy)
338 b ← BAR ˢᵛh̲it xy
339 (b > 0) ∧ b ≤ 3 ? s ʰs̲et (b, 0, pg)
340 b = 4 ? ʰw̲ave s
341 b = 5 ? ʰf̲aster s
342 b = 6 ? s ʰs̲et (sel, 1, pg)
343 tw ← W ʰt̲owerAt xy
344 tw > 0 ? ʰu̲pgrade (s, tw)
345 s ʰb̲uild ʰt̲ile xy
346}
347⍝│ Which of the grimoire's buttons a click is on (1 back, 2 next, 3
348⍝│ close); a click outside its panel closes it too.
349PANEL ← 1 4 r̲eshape 30 70 820 520.0
350ʰb̲ookHit ← { xy → 0 = PANEL ˢᵛh̲it xy ? 3◆ BOOK ˢᵛh̲it xy }
351ʰb̲ook ← { (s, b) →
352 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) ← s
353 b = 1 ? s ʰs̲et (sel, 1, 1 + (pg + PAGES − 2) m̲od PAGES)
354 b = 2 ? s ʰs̲et (sel, 1, 1 + pg m̲od PAGES)
355 b = 3 ? s ʰs̲et (sel, 0, pg)
356 s
357}
358⍝ :: (Any a, Num b, Any c, Num d, Num e) => (Float, Int, a, Int, Int, Float, Int, b, Int, c, d, e, Char) -> Char -> (Float, Int, a, Int, Int, Float, Int, b, Int, c, d, e, Char)
359⍝│ A key: 1, 2, 3 pick the tower to build (left and right step through
360⍝│ them), the space bar sends the next wave, f runs the game faster (1,
361⍝│ 2, 4 times), g opens or closes the grimoire (left and right turn its
362⍝│ pages there; Enter or x closes it too).
363ˡk̲ey ← { s name →
364 (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) ← s
365 k ← ("1" "2" "3" "LEFT" "RIGHT" " " "g" "f" "Enter" "x") i̲ndexOf e̲nclose name
366 (k > 10) ∨ st > 0 ? s
367 (md = 1) ∧ k ≥ 9 ? s ʰs̲et (sel, 0, pg)
368 k ≥ 9 ? s
369 k = 8 ? ʰf̲aster s
370 k = 7 ? s ʰs̲et (sel, 1 − md, pg)
371 (md = 1) ∧ k = 4 ? ʰb̲ook (s, 1)
372 (md = 1) ∧ k = 5 ? ʰb̲ook (s, 2)
373 md = 1 ? s
374 k = 6 ? ʰw̲ave s
375 k = 4 ? s ʰs̲et (1 + (sel + 1) m̲od 3, md, pg)
376 k = 5 ? s ʰs̲et (1 + sel m̲od 3, md, pg)
377 s ʰs̲et (k, md, pg)
378}
379
380⍝━━ What it shows
381
382⍝ :: (Any a, Any b, Any c, Any d, Any e, Any f, Any g, Any h, Any i, Any j, Any k, Any l, Any m) => (a, b, c, d, e, f, g, h, i, j, k, l, m) -> k
383⍝│ 0 playing, 1 every wave beaten, 2 no lives left.
384ˡs̲tatus ← { (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) → st }
385⍝ :: (Any a, Any c, Any d, Any e, Any f, Any g, Any h, Any i, Any j, Any k) => (a, b, b, b, c, d, e, f, g, h, i, j, k) -> b
386⍝│ The money, the lives, the waves begun.
387ˡs̲core ← { (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) → mo c̲at lv c̲at wv }
388⍝ :: (Num a, Any b, Any c, Any d, Any e, Any f, Any g, Any h, Any i, Any j, Any k, Any l, Any m) => (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Int
389⍝│ How many are alive: towers, creeps, shots.
390ˡc̲ounts ← { (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) → (t̲ally ʰt̲owers W) c̲at (t̲ally ʰc̲reeps W) c̲at t̲ally ʰs̲hots W }
391⍝ :: (Any a, Any b, Any c, Any d, Any e, Any f, Any g, Any h, Any i, Any j, Any k, Any l) => (Float, a, b, c, d, e, f, g, h, i, j, k, l) -> Float
392⍝│ The towers: kind, level and tile (x, y), a row each.
393ˡt̲owers ← { (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) →
394 tw ← ʰt̲owers W
395 P ← f̲loat f̲loor tw s̲elect ʰp̲os W
396 o̲\ (4 c̲at t̲ally tw) r̲eshape (tw s̲elect ʰk̲ind W) c̲at (tw s̲elect ʰl̲evel W) c̲at (1 s̲elect₂ P) c̲at 2 s̲elect₂ P
397}
398⍝ :: Any a => a -> Int
399⍝│ The road as tiles in order (row, column, from 0).
400ˡr̲oad ← { s → o̲\ (2 c̲at t̲ally PATH) r̲eshape ((PATH − 1) d̲iv C) c̲at (PATH − 1) m̲od C }
401⍝│ A point of the board (x, y in tiles, z up in the picture's units) in
402⍝│ the picture: one linear map, every point at once.
403ʰs̲x ← { (x, y) → OX + TW × x − y }
404ʰs̲y ← { (x, y, z) → (OY + TH × x + y) − z }
405⍝│ A polygon through points of the board.
406ʰp̲oly ← { (x, y, z, fill) →
407 sx ← ʰs̲x (x, y)
408 sy ← ʰs̲y (x, y, z)
409 pts ← ᵗj̲oin '{ i → e̲nclose @ f̲ormat< "{sv:w_hole i s_elect sx},{sv:w_hole i s_elect sy} " } e̲ach r̲ange t̲ally x
410 @ f̲ormat< "<polygon points=\"{pts}\" fill=\"{fill}\" stroke=\"#1d1f2b\" stroke-width=\"1\"/>"
411}
412⍝│ The board, drawn once: each tile a diamond, grass or road.
413ʰt̲ileAt ← { k →
414 gx ← f̲loat (k − 1) m̲od C
415 gy ← f̲loat (k − 1) d̲iv C
416 fill ← d̲isclose (1 + k s̲elect ROAD) s̲elect "#3a7d44" "#8d7b5e"
417 e̲nclose ʰp̲oly (gx c̲at (gx + 1.0) c̲at (gx + 1.0) c̲at gx, gy c̲at gy c̲at (gy + 1.0) c̲at gy + 1.0, 0.0 0.0 0.0 0.0, fill)
418}
419BOARD ← ᵗj̲oin 'ʰt̲ileAt e̲ach r̲ange t̲ally cells
420⍝│ A tower's colors (top, left, right faces) by kind.
421FACES ← 3 3 r̲eshape "#d4a373" "#a47148" "#7f5539" "#adb5bd" "#6c757d" "#495057" "#bde0fe" "#7fb7e8" "#4a90c8"
422⍝│ A box standing on the board: its middle (x, y), half its width, its
423⍝│ height, and its corners turned by a (radians) about the middle; the
424⍝│ two faces toward the viewer and the top.
425ʰb̲ox ← { (x, y, w, z, a, kind) →
426 u ← (a + 0.25 × p̲i @) + 0.5 × (p̲i @) × 0.0 1.0 2.0 3.0
427 cx ← x + w × 1.414 × c̲os u
428 cy ← y + w × 1.414 × s̲in u
429 i ← g̲rade n̲eg cx + cy
430 near ← 3 t̲ake i
431 l ← 2 t̲ake near
432 r ← (f̲irst near) c̲at 3 s̲elect near
433 col ← '{ j → e̲nclose d̲isclose j s̲elect kind s̲elect FACES } e̲ach 1 2 3
434 zs ← 0.0 0.0 c̲at z c̲at z
435 left ← ʰp̲oly ((l s̲elect cx) c̲at r̲ev l s̲elect cx, (l s̲elect cy) c̲at r̲ev l s̲elect cy, zs, d̲isclose 2 s̲elect col)
436 right ← ʰp̲oly ((r s̲elect cx) c̲at r̲ev r s̲elect cx, (r s̲elect cy) c̲at r̲ev r s̲elect cy, zs, d̲isclose 3 s̲elect col)
437 top ← ʰp̲oly (cx, cy, 4 r̲eshape z, d̲isclose f̲irst col)
438 left c̲at right c̲at top
439}
440⍝│ A tower drawn: a box as tall as its level, with a pip a level on top.
441ʰd̲rawTower ← { (x, y, kind, level, a) →
442 z ← 14.0 + 10.0 × f̲loat level
443 pips ← ᵗj̲oin '{ i → e̲nclose @ f̲ormat< "<circle cx=\"{sv:w_hole (h:s_x (x, y)) + 6.0 * f_loat i - 2}\" cy=\"{sv:w_hole (h:s_y (x, y, z)) - 3.0}\" r=\"2.5\" fill=\"#ffffff\"/>" } e̲ach r̲ange level
444 (ʰb̲ox (x, y, 0.32, z, a, kind)) c̲at pips
445}
446⍝│ Every kind and level of tower drawn once, on tile (0, 0); the board
447⍝│ moves each to its tile (towers do not turn on the board).
448TOWERART ← '{ j → e̲nclose ʰd̲rawTower (0.0, 0.0, 1 + (j − 1) d̲iv 3, 1 + (j − 1) m̲od 3, 0.0) } e̲ach r̲ange 9
449ʰp̲laced ← { (x, y, j) → @ f̲ormat< "<g transform=\"translate({sv:w_hole (h:s_x (x, y)) - OX} {sv:w_hole (h:s_y (x, y, 0.0)) - OY})\">{d_isclose j s_elect TOWERART}</g>" }
450⍝│ Over a tower, what its upgrade costs: gold when the money is there,
451⍝│ gray when not, "top" at level 3 (j: its row in the towers' table).
452ʰu̲pLabel ← { (x, y, j, mo) →
453 top ← 0 = j m̲od 3
454 cost ← (1 + j m̲in 8) s̲elect COST
455 words ← ʰu̲pWords (top, cost)
456 fill ← d̲isclose (1 + (n̲ot top) ∧ cost ≤ mo) s̲elect "#adb5bd" "#ffd166"
457 z ← ʰl̲abelZ j
458 @ f̲ormat< "<text x=\"{sv:w_hole h:s_x (x, y)}\" y=\"{sv:w_hole (h:s_y (x, y, z)) - 8.0}\" font-size=\"13\" font-weight=\"bold\" text-anchor=\"middle\" fill=\"{fill}\" stroke=\"#1d1f2b\" stroke-width=\"3\" paint-order=\"stroke\">{words}</text>"
459}
460⍝│ How high over its tile a tower's label stands: over its picture, or
461⍝│ over its box (taller each level).
462ʰl̲abelZ ← { j → ART ? 0.6 × SPRITE◆ 30.0 + 10.0 × f̲loat 1 + (j − 1) m̲od 3 }
463ʰu̲pWords ← { (top, cost) → top ? "top"◆ @ f̲ormat< "up {cost}" }
464⍝│ A piece drawn from the art (td.toml art = "1"): its picture from
465⍝│ X_eTaL-extensions (a 3D model rendered in Blender), every piece at one
466⍝│ scale, standing on its tile.
467SPRITE ← 112.0
468ʰs̲prite ← { (x, y, name) → @ f̲ormat< "<image class=\"entity flat\" href=\"art/{name}.png\" x=\"{sv:w_hole (h:s_x (x, y)) - 0.5 * SPRITE}\" y=\"{sv:w_hole (h:s_y (x, y, 0.0)) - 0.85 * SPRITE}\" width=\"{sv:w_hole SPRITE}\" height=\"{sv:w_hole SPRITE}\"/>" }
469⍝│ A creep's hit points, as a bar over it.
470ʰh̲pBar ← { (x, y, kind, hp, z) →
471 frac ← 0.0 m̲ax 1.0 m̲in hp ÷ kind s̲elect HP
472 sy ← ʰs̲y (x, y, z)
473 @ f̲ormat< "<rect x=\"{sv:w_hole (h:s_x (x, y)) - 10.0}\" y=\"{sv:w_hole sy}\" width=\"20\" height=\"3\" fill=\"#3a0d0d\"/><rect x=\"{sv:w_hole (h:s_x (x, y)) - 10.0}\" y=\"{sv:w_hole sy}\" width=\"{sv:w_hole 20.0 * frac}\" height=\"3\" fill=\"#ff595e\"/>"
474}
475⍝│ A creep drawn: a shadow, a body by its kind, its hit points as a bar.
476CREEPCOLORS ← "#80ed99" "#c1440e" "#5c7aa6"
477ʰd̲rawCreep ← { (x, y, kind, hp) →
478 sx ← ˢᵛw̲hole ʰs̲x (x, y)
479 sy ← ʰs̲y (x, y, 0.0)
480 r ← (1 + kind) s̲elect 0.0 6.0 10.0 8.0
481 col ← d̲isclose kind s̲elect CREEPCOLORS
482 frac ← 0.0 m̲ax 1.0 m̲in hp ÷ kind s̲elect HP
483 @ f̲ormat< "<ellipse cx=\"{sx}\" cy=\"{sv:w_hole sy}\" rx=\"{sv:w_hole r}\" ry=\"{sv:w_hole 0.5 * r}\" fill=\"#000000\" opacity=\"0.3\"/><circle class=\"entity\" cx=\"{sx}\" cy=\"{sv:w_hole sy - r}\" r=\"{sv:w_hole r}\" fill=\"{col}\" stroke=\"#1d1f2b\" stroke-width=\"1.5\"/><rect x=\"{sv:w_hole (h:s_x (x, y)) - 10.0}\" y=\"{sv:w_hole sy - 6.0 + 2.0 * r}\" width=\"20\" height=\"3\" fill=\"#3a0d0d\"/><rect x=\"{sv:w_hole (h:s_x (x, y)) - 10.0}\" y=\"{sv:w_hole sy - 6.0 + 2.0 * r}\" width=\"{sv:w_hole 20.0 * frac}\" height=\"3\" fill=\"#ff595e\"/>"
484}
485⍝│ A shot drawn, in the air.
486ʰs̲hotAt ← { (x, y) → @ f̲ormat< "<circle cx=\"{sv:w_hole h:s_x (x, y)}\" cy=\"{sv:w_hole h:s_y (x, y, 22.0)}\" r=\"3\" fill=\"#fff3b0\" stroke=\"#000000\" stroke-width=\"0.5\"/>" }
487⍝│ Everything on the board, drawn far to near (by x + y): what each
488⍝│ entity is picks its drawing.
489ʰt̲hings ← { (W, mo) →
490 e ← w̲here ᵉᶜa̲live W
491 P ← e s̲elect ʰp̲os W
492 order ← g̲rade ('+ r̲/₂ P) + 0.01 × f̲loat 0 + e s̲elect ʰh̲asShot W
493 '{ i → e̲nclose ʰt̲hing (W, i s̲elect e, i s̲elect P, mo) } e̲ach order
494}
495⍝│ The board's things, unless the grimoire is open over them.
496ʰt̲hingsIf ← { (W, mo, md) → md = 1 ? 0 r̲eshape e̲nclose ""◆ ʰt̲hings (W, mo) }
497ʰt̲hing ← { (W, n, p, mo) →
498 x ← f̲irst p
499 y ← 2 s̲elect p
500 ART ∧ n s̲elect ʰh̲asTower W ? (ʰs̲prite (x, y, d̲isclose (W ʰr̲ow n) s̲elect PIECES)) c̲at ʰu̲pLabel (x, y, W ʰr̲ow n, mo)
501 ART ∧ n s̲elect ʰh̲asCreep W ? (ʰs̲prite (x, y, d̲isclose (9 + f̲loor n s̲elect ʰk̲ind W) s̲elect PIECES)) c̲at ʰh̲pBar (x, y, f̲loor n s̲elect ʰk̲ind W, n s̲elect ʰh̲p W, 44.0)
502 n s̲elect ʰh̲asTower W ? (ʰp̲laced (x, y, W ʰr̲ow n)) c̲at ʰu̲pLabel (x, y, W ʰr̲ow n, mo)
503 n s̲elect ʰh̲asCreep W ? ʰd̲rawCreep (x, y, f̲loor n s̲elect ʰk̲ind W, n s̲elect ʰh̲p W)
504 ʰs̲hotAt (x, y)
505}
506⍝│ A button: its rectangle, its words, lit when picked.
507ʰb̲utton ← { (r, words, lit) →
508 fill ← d̲isclose (1 + lit) s̲elect "#2b2d42" "#4361ee"
509 cls ← d̲isclose (1 + lit) s̲elect "button" "button you"
510 e̲nclose @ f̲ormat< "<g class=\"{cls}\"><rect x=\"{sv:w_hole f_irst r}\" y=\"{sv:w_hole 2 s_elect r}\" width=\"{sv:w_hole 3 s_elect r}\" height=\"{sv:w_hole 4 s_elect r}\" rx=\"8\" fill=\"{fill}\" stroke=\"#8d99ae\" stroke-width=\"2\"/><text x=\"{sv:w_hole (f_irst r) + 0.5 * 3 s_elect r}\" y=\"{sv:w_hole (2 s_elect r) + 33.0}\" font-size=\"18\" text-anchor=\"middle\" fill=\"#ffffff\">{words}</text></g>"
511}
512⍝│ The toolbar: the three towers (with what they cost), the next wave,
513⍝│ the speed, the grimoire; drawn once for each tower picked and speed.
514ʰb̲ar ← { j →
515 sel ← 1 + (j − 1) d̲iv 3
516 sp ← (1 + (j − 1) m̲od 3) s̲elect 1 2 4
517 names ← "Arrow" "Cannon" "Frost"
518 towers ← '{ k → ʰb̲utton (k s̲elect BAR, @ f̲ormat< "{d_isclose k s_elect names} {(1 + 3 * k - 1) s_elect COST}", k = sel) } e̲ach 1 2 3
519 ᵗj̲oin towers c̲at (ʰb̲utton (4 s̲elect BAR, "Next wave", 0 = 1)) c̲at (ʰb̲utton (5 s̲elect BAR, @ f̲ormat< "Speed {sp}x", sp > 1)) c̲at ʰb̲utton (6 s̲elect BAR, "Grimoire", 0 = 1)
520}
521BARS ← 'ʰb̲ar m̲ap r̲ange 9
522⍝│ Text cut into lines of about n characters, at spaces: each word's line
523⍝│ from a running sum of the words' lengths.
524ʰw̲rap ← { t n →
525 w ← (n̲ot t = f̲irst " ") p̲artition t
526 len ← 1 + 'ʰl̲en e̲ach w
527 line ← (('+ s̲\ len) − 1) d̲iv n
528 '{ i → e̲nclose ᵗj̲oin '{ x → e̲nclose (d̲isclose x) c̲at " " } e̲ach (line = i) r̲eplicate w } e̲ach u̲nique line
529}
530ʰl̲en ← { x → t̲ally d̲isclose x }
531⍝│ The grimoire's panel; with the art, a window in it where the piece
532⍝│ turns in the 3D view (behind the picture).
533ʰp̲anel ← { art →
534 art ? "<path d=\"M46 70 H834 Q850 70 850 86 V574 Q850 590 834 590 H46 Q30 590 30 574 V86 Q30 70 46 70 Z M70 130 V470 H410 V130 Z\" fill=\"#11121c\" fill-rule=\"evenodd\" opacity=\"0.96\" stroke=\"#8d99ae\" stroke-width=\"2\"/>"
535 "<rect x=\"30\" y=\"70\" width=\"820\" height=\"520\" rx=\"16\" fill=\"#11121c\" opacity=\"0.96\" stroke=\"#8d99ae\" stroke-width=\"2\"/>"
536}
537⍝│ The grimoire's page pg: the piece turning (the 3D art's turntable, or
538⍝│ the game's own drawing turned), its name and what it does.
539ʰp̲age ← { (pg, t) →
540 panel ← e̲nclose ʰp̲anel ART
541 tower ← pg ≤ 9
542 pic ← ʰs̲pin (pg, t)
543 words ← ʰa̲bout pg
544 lines ← '{ i → (430.0, 150.0 + 30.0 × f̲loat i − 1, 20.0) ʰw̲ords d̲isclose i s̲elect words } e̲ach r̲ange t̲ally words
545 buttons ← (ʰb̲utton (1 s̲elect BOOK, "Back", 0 = 1)) c̲at (ʰb̲utton (2 s̲elect BOOK, "Next", 0 = 1)) c̲at ʰb̲utton (3 s̲elect BOOK, "Close", 0 = 1)
546 hint ← (440.0, 500.0, 15.0) ʰw̲ords "Left, right: pages | g, Enter, x or a click outside: close"
547 panel c̲at pic c̲at (r̲avel lines) c̲at buttons c̲at hint
548}
549⍝│ The piece on page pg: its picture when the art is in use (it turns in
550⍝│ the 3D view), else the game's own drawing, turned with the time.
551ʰs̲pin ← { (pg, t) →
552 ART ? e̲nclose @ f̲ormat< "<rect class=\"flat\" x=\"70\" y=\"130\" width=\"340\" height=\"340\" fill=\"#11121c\"/><image class=\"entity flat\" href=\"art/{d_isclose pg s_elect PIECES}.png\" x=\"70\" y=\"130\" width=\"340\" height=\"340\"/>"
553 pg ≤ 9 ? e̲nclose "<g transform=\"translate(-816 -504) scale(3)\">" c̲at (ʰd̲rawTower (6.0, 6.0, 1 + (pg − 1) d̲iv 3, 1 + (pg − 1) m̲od 3, t)) c̲at "</g>"
554 e̲nclose "<g transform=\"translate(-992 -623) scale(3.5)\">" c̲at (ʰd̲rawCreep (5.6, 5.6, pg − 9, 1000.0)) c̲at "</g>"
555}
556⍝│ What page pg says: a tower's name, level, numbers, words and its next
557⍝│ upgrade; a creep's name, numbers and words.
558ʰa̲bout ← { pg →
559 pg > 9 ? ʰc̲reepAbout pg − 9
560 name ← d̲isclose pg s̲elect 1 s̲elect₂ TT
561 lvl ← 1 + (pg − 1) m̲od 3
562 next ← ʰn̲extUp pg
563 head ← (e̲nclose @ f̲ormat< "{name} (level {lvl})") c̲at e̲nclose @ f̲ormat< "Reach {pg s_elect RANGE} | damage {pg s_elect DAMAGE} | every {pg s_elect COOLDOWN} s"
564 more ← e̲nclose @ f̲ormat< "Splash {pg s_elect SPLASH} | slows {pg s_elect CHILL} s | costs {pg s_elect COST}"
565 head c̲at more c̲at (e̲nclose "") c̲at ((d̲isclose pg s̲elect 8 s̲elect₂ TT) ʰw̲rap 38) c̲at (e̲nclose "") c̲at e̲nclose next
566}
567ʰn̲extUp ← { pg →
568 3 = 1 + (pg − 1) m̲od 3 ? "The top level."
569 @ f̲ormat< "Click it on the board to upgrade: {(pg + 1) s_elect COST}."
570}
571ʰc̲reepAbout ← { k →
572 name ← d̲isclose k s̲elect 1 s̲elect₂ CT
573 head ← (e̲nclose name) c̲at e̲nclose @ f̲ormat< "Hit points {k s_elect HP} | speed {k s_elect SPEED} | armor {k s_elect ARMOR}"
574 more ← e̲nclose @ f̲ormat< "Worth {k s_elect BOUNTY} | costs {k s_elect LEAK} lives if it gets out"
575 head c̲at more c̲at (e̲nclose "") c̲at (d̲isclose k s̲elect 8 s̲elect₂ CT) ʰw̲rap 38
576}
577⍝│ Words at x, y in size z, light on the dark picture.
578ʰw̲ords ← { (x, y, z) t → e̲nclose @ f̲ormat< "<text x=\"{sv:w_hole x}\" y=\"{sv:w_hole y}\" font-size=\"{sv:w_hole z}\" fill=\"#e9ecef\">{t}</text>" }
579⍝│ What the top line says.
580ʰs̲ays ← { (mo, lv, wv, t, st) →
581 st = 1 ? @ f̲ormat< "Every wave beaten! Lives {lv} | Money {mo} | Time {f_loor t} s"
582 st = 2 ? @ f̲ormat< "The creeps got through. Wave {wv} | Time {f_loor t} s"
583 @ f̲ormat< "Money {mo} | Lives {lv} | Wave {wv} of {t_ally WAVES} | Time {f_loor t} s"
584}
585⍝ :: (Any c, Any d, Num e, Num f, Num g) => (Float, Int, a, b, c, d, Int, e, Int, Float, f, g, Char) -> Char
586⍝│ The picture, as SVG text: the board and everything on it drawn far to
587⍝│ near, the toolbar, the top line, and the grimoire over it all when
588⍝│ open.
589ˡd̲raw ← { (W, mo, lv, wv, q, tm, sel, md, pg, t, st, sp, ms) →
590 top ← (16.0, 40.0, 22.0) ʰw̲ords ʰs̲ays (mo, lv, wv, t, st)
591 said ← (16.0, 70.0, 18.0) ʰw̲ords ms
592 book ← ʰb̲ookIf (md, pg, t)
593 scene ← ʰs̲ceneIf (W, md, pg, t)
594 VIEW ˢᵛp̲icture (VIEW ˢᵛr̲ect "class=\"flat\" fill=\"#1d1f2b\"") c̲at (e̲nclose "<g class=\"flat\">" c̲at BOARD c̲at "</g>") c̲at scene c̲at (ʰt̲hingsIf (W, mo, md)) c̲at (((3 × sel − 1) + 1 2 4 i̲ndexOf sp) s̲elect BARS) c̲at top c̲at said c̲at book
595}
596ʰb̲ookIf ← { (md, pg, t) → md = 0 ? 0 r̲eshape e̲nclose ""◆ ʰp̲age (pg, t) }
597
598⍝━━ The scene, for a 3D view
599
600⍝│ With the art, the picture carries what a 3D view of it is to draw, as
601⍝│ JSON in its metadata: a camera that sees the board as this picture's
602⍝│ isometric map does (30 degrees above it, along its diagonal, as many
603⍝│ units of the picture to a tile), the tiles, every piece (its model,
604⍝│ where it stands, the way it faces, the clip it plays and how far into
605⍝│ it), the shots. A page that can draws that scene behind the picture
606⍝│ and hides what the picture marks "flat" (the board and the pieces'
607⍝│ pictures); one that cannot shows the picture as it is.
608SCALE ← TW × 2.0 ^ 0.5
609⍝│ Numbers as a JSON list.
610ʰj̲son ← { v → "[" c̲at (1 d̲rop ᵗj̲oin '{ x → e̲nclose "," c̲at f̲ormat x } e̲ach v) c̲at "]" }
611⍝│ Text as a JSON string (the names and colors here need no escapes).
612ʰq̲uote ← { x → "\"" c̲at x c̲at "\"" }
613⍝│ The board point at the middle of the picture: x and z.
614MID ← (0.5 × ((0.5 × 3 s̲elect VIEW) − OX) ÷ TW) + 0.5 × ((0.5 × 4 s̲elect VIEW) − OY) ÷ TH
615MIDZ ← (0.5 × ((0.5 × 4 s̲elect VIEW) − OY) ÷ TH) − 0.5 × ((0.5 × 3 s̲elect VIEW) − OX) ÷ TW
616⍝│ The camera: looking at the board point at the middle of the picture
617⍝│ (up above the ground), along the board's diagonal from 30 degrees up,
618⍝│ k picture units a tile.
619ʰc̲amera ← { (k, up) →
620 tx ← MID
621 tz ← MIDZ
622 "\"camera\":{\"target\":" c̲at (ʰj̲son tx c̲at up c̲at tz) c̲at ",\"dir\":" c̲at (ʰj̲son 0.6124 0.5 0.6124) c̲at ",\"scale\":" c̲at (f̲ormat k) c̲at "}"
623}
624⍝│ A piece of the scene: its model, place, heading, clip and time.
625ʰp̲iece ← { (m, x, z, hx, hz, clip, t) →
626 "{\"m\":" c̲at (ʰq̲uote m) c̲at ",\"x\":" c̲at (f̲ormat x) c̲at ",\"z\":" c̲at (f̲ormat z) c̲at ",\"dir\":" c̲at (ʰj̲son hx c̲at hz) c̲at ",\"clip\":" c̲at (ʰq̲uote clip) c̲at ",\"t\":" c̲at (f̲ormat t) c̲at "}"
627}
628⍝│ The towers: idle, or the fire clip just after a shot.
629ʰt̲owerPieces ← { (W, t) →
630 tw ← ʰt̲owers W
631 '{ i → e̲nclose ʰt̲owerPiece (W, i s̲elect tw, t) } e̲ach r̲ange t̲ally tw
632}
633ʰt̲owerPiece ← { (W, n, t) →
634 j ← W ʰr̲ow n
635 p ← n s̲elect ʰp̲os W
636 since ← (j s̲elect COOLDOWN) − n s̲elect ʰc̲ool W
637 since < 0.4 ? ʰp̲iece (d̲isclose j s̲elect PIECES, f̲irst p, 2 s̲elect p, 0.0, 1.0, "fire", since)
638 ʰp̲iece (d̲isclose j s̲elect PIECES, f̲irst p, 2 s̲elect p, 0.0, 1.0, "idle", t)
639}
640⍝│ The creeps: walking, each facing along the road where it is.
641ʰc̲reepPieces ← { (W, t) →
642 c ← ʰc̲reeps W
643 '{ i → e̲nclose ʰc̲reepPiece (W, i s̲elect c, t) } e̲ach r̲ange t̲ally c
644}
645ʰc̲reepPiece ← { (W, n, t) →
646 p ← n s̲elect ʰp̲os W
647 i ← 0 m̲ax (LONG − 1) m̲in f̲loor n s̲elect ʰp̲rog W
648 hx ← ((i + 2) s̲elect PX) − (i + 1) s̲elect PX
649 hz ← ((i + 2) s̲elect PY) − (i + 1) s̲elect PY
650 ʰp̲iece (d̲isclose (9 + f̲loor n s̲elect ʰk̲ind W) s̲elect PIECES, f̲irst p, 2 s̲elect p, hx, hz, "walk", t)
651}
652⍝│ The board's tiles: 1 road, 0 grass, row by row.
653ROADTEXT ← ᵗj̲oin '{ r → e̲nclose f̲ormat r } e̲ach ROAD
654⍝│ The scene of the board: its camera, tiles, pieces and shots.
655ʰb̲oardScene ← { (W, t) →
656 ps ← (ʰt̲owerPieces (W, t)) c̲at ʰc̲reepPieces (W, t)
657 S ← (ʰs̲hots W) s̲elect ʰp̲os W
658 shots ← 1 d̲rop ᵗj̲oin '{ i → e̲nclose "," c̲at ʰj̲son i s̲elect S } e̲ach r̲ange t̲ally S
659 "{\"view\":" c̲at (ʰj̲son 2 d̲rop VIEW) c̲at ",\"background\":\"#1d1f2b\",\"base\":\"art/\"," c̲at (ʰc̲amera (SCALE, 0.0)) c̲at ",\"tiles\":{\"cols\":" c̲at (f̲ormat C) c̲at ",\"road\":" c̲at (ʰq̲uote ROADTEXT) c̲at ",\"colors\":[\"#3a7d44\",\"#8d7b5e\"]},\"pieces\":[" c̲at (1 d̲rop ᵗj̲oin '{ x → e̲nclose "," c̲at d̲isclose x } e̲ach ps) c̲at "],\"shots\":[" c̲at shots c̲at "]}"
660}
661⍝│ The scene of the grimoire's page pg: its piece alone, turning, where
662⍝│ the panel's window is (200 picture units left of the middle: along
663⍝│ the picture's x, which is the board's x less its z).
664ʰb̲ookScene ← { (pg, t) →
665 k ← ʰz̲oom pg
666 e ← 200.0 ÷ k × 2.0 ^ 0.5
667 piece ← ʰp̲iece (d̲isclose pg s̲elect PIECES, MID − e, MIDZ + e, s̲in 0.8 × t, c̲os 0.8 × t, "idle", t)
668 "{\"view\":" c̲at (ʰj̲son 2 d̲rop VIEW) c̲at ",\"background\":\"#11121c\",\"base\":\"art/\"," c̲at (ʰc̲amera (k, ʰh̲eight pg)) c̲at ",\"pieces\":[" c̲at piece c̲at "],\"shots\":[]}"
669}
670⍝│ How near the grimoire's camera is (picture units a tile) and how
671⍝│ high it looks: towers are taller than creeps.
672ʰz̲oom ← { pg → pg ≤ 9 ? 170.0◆ 260.0 }
673ʰh̲eight ← { pg → pg ≤ 9 ? 0.75◆ 0.25 }
674⍝│ The scene as the picture's metadata, with the art; else nothing.
675ʰs̲ceneIf ← { (W, md, pg, t) →
676 n̲ot ART ? 0 r̲eshape e̲nclose ""
677 md = 1 ? e̲nclose "<metadata id=\"scene\">" c̲at (ʰb̲ookScene (pg, t)) c̲at "</metadata>"
678 e̲nclose "<metadata id=\"scene\">" c̲at (ʰb̲oardScene (W, t)) c̲at "</metadata>"
679}
ᵉᶜc̲omponents< expands to
ʰw̲orld ← { n → (n c̲at 30) 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 30 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 30 } ʰk̲ind ← { W → (6) s̲elect₂ W } ʰh̲asKind ← { W → 0 < 5 s̲elect₂ W } ʰs̲etKind ← { 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 (5 6) '= t̲able r̲ange 30 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̲ropKind ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 5 = r̲ange 30 } ʰl̲evel ← { W → (8) s̲elect₂ W } ʰh̲asLevel ← { W → 0 < 7 s̲elect₂ W } ʰs̲etLevel ← { 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 (7 8) '= t̲able r̲ange 30 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̲ropLevel ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 7 = r̲ange 30 } ʰp̲rog ← { W → (10) s̲elect₂ W } ʰh̲asProg ← { W → 0 < 9 s̲elect₂ W } ʰs̲etProg ← { 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 (9 10) '= t̲able r̲ange 30 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̲ropProg ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 9 = r̲ange 30 } ʰh̲p ← { W → (12) s̲elect₂ W } ʰh̲asHp ← { W → 0 < 11 s̲elect₂ W } ʰs̲etHp ← { 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 (11 12) '= t̲able r̲ange 30 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̲ropHp ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 11 = r̲ange 30 } ʰs̲low ← { W → (14) s̲elect₂ W } ʰh̲asSlow ← { W → 0 < 13 s̲elect₂ W } ʰs̲etSlow ← { 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 (13 14) '= t̲able r̲ange 30 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̲ropSlow ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 13 = r̲ange 30 } ʰc̲ool ← { W → (16) s̲elect₂ W } ʰh̲asCool ← { W → 0 < 15 s̲elect₂ W } ʰs̲etCool ← { 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 (15 16) '= t̲able r̲ange 30 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̲ropCool ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 15 = r̲ange 30 } ʰt̲arget ← { W → (18) s̲elect₂ W } ʰh̲asTarget ← { W → 0 < 17 s̲elect₂ W } ʰs̲etTarget ← { 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 (17 18) '= t̲able r̲ange 30 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̲ropTarget ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 17 = r̲ange 30 } ʰd̲mg ← { W → (20) s̲elect₂ W } ʰh̲asDmg ← { W → 0 < 19 s̲elect₂ W } ʰs̲etDmg ← { 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 (19 20) '= t̲able r̲ange 30 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̲ropDmg ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 19 = r̲ange 30 } ʰa̲rea ← { W → (22) s̲elect₂ W } ʰh̲asArea ← { W → 0 < 21 s̲elect₂ W } ʰs̲etArea ← { 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 (21 22) '= t̲able r̲ange 30 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̲ropArea ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 21 = r̲ange 30 } ʰc̲hill ← { W → (24) s̲elect₂ W } ʰh̲asChill ← { W → 0 < 23 s̲elect₂ W } ʰs̲etChill ← { 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 (23 24) '= t̲able r̲ange 30 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̲ropChill ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 23 = r̲ange 30 } ʰt̲ower ← { W → (26) s̲elect₂ W } ʰh̲asTower ← { W → 0 < 25 s̲elect₂ W } ʰs̲etTower ← { 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 (25 26) '= t̲able r̲ange 30 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̲ropTower ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 25 = r̲ange 30 } ʰc̲reep ← { W → (28) s̲elect₂ W } ʰh̲asCreep ← { W → 0 < 27 s̲elect₂ W } ʰs̲etCreep ← { 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 (27 28) '= t̲able r̲ange 30 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̲ropCreep ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 27 = r̲ange 30 } ʰs̲hot ← { W → (30) s̲elect₂ W } ʰh̲asShot ← { W → 0 < 29 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 (29 30) '= t̲able r̲ange 30 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 29 = r̲ange 30 }
f̲ormat< expands to
("That tower costs " c̲at (f̲ormat (cost)) c̲at "; the money is " c̲at (f̲ormat (mo)) c̲at ".")
f̲ormat< expands to
("Built: " c̲at (f̲ormat (d̲isclose (1 + 3 × sel − 1) s̲elect 1 s̲elect₂ TT)) c̲at " (" c̲at (f̲ormat (cost)) c̲at "). Click it to upgrade.")
f̲ormat< expands to
("The upgrade costs " c̲at (f̲ormat (cost)) c̲at "; the money is " c̲at (f̲ormat (mo)) c̲at ".")
f̲ormat< expands to
("Upgraded to " c̲at (f̲ormat (d̲isclose (1 + (W ʰr̲ow tw)) s̲elect 1 s̲elect₂ TT)) c̲at " (level " c̲at (f̲ormat (l + 1)) c̲at ", " c̲at (f̲ormat (cost)) c̲at ").")
f̲ormat< expands to
((f̲ormat (ˢᵛw̲hole i s̲elect sx)) c̲at "," c̲at (f̲ormat (ˢᵛw̲hole i s̲elect sy)) c̲at " ")
f̲ormat< expands to
"<polygon points=\"" c̲at (f̲ormat (pts)) c̲at "\" fill=\"" c̲at (f̲ormat (fill)) c̲at "\" stroke=\"#1d1f2b\" stroke-width=\"1\"/>"
f̲ormat< expands to
("<circle cx=\"" c̲at (f̲ormat (ˢᵛw̲hole (ʰs̲x (x, y)) + 6.0 × f̲loat i − 2)) c̲at "\" cy=\"" c̲at (f̲ormat (ˢᵛw̲hole (ʰs̲y (x, y, z)) − 3.0)) c̲at "\" r=\"2.5\" fill=\"#ffffff\"/>")
f̲ormat< expands to
"<g transform=\"translate(" c̲at (f̲ormat (ˢᵛw̲hole (ʰs̲x (x, y)) − OX)) c̲at " " c̲at (f̲ormat (ˢᵛw̲hole (ʰs̲y (x, y, 0.0)) − OY)) c̲at ")\">" c̲at (f̲ormat (d̲isclose j s̲elect TOWERART)) c̲at "</g>"
f̲ormat< expands to
"<text x=\"" c̲at (f̲ormat (ˢᵛw̲hole ʰs̲x (x, y))) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole (ʰs̲y (x, y, z)) − 8.0)) c̲at "\" font-size=\"13\" font-weight=\"bold\" text-anchor=\"middle\" fill=\"" c̲at (f̲ormat (fill)) c̲at "\" stroke=\"#1d1f2b\" stroke-width=\"3\" paint-order=\"stroke\">" c̲at (f̲ormat (words)) c̲at "</text>"
f̲ormat< expands to
"<image class=\"entity flat\" href=\"art/" c̲at (f̲ormat (name)) c̲at ".png\" x=\"" c̲at (f̲ormat (ˢᵛw̲hole (ʰs̲x (x, y)) − 0.5 × SPRITE)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole (ʰs̲y (x, y, 0.0)) − 0.85 × SPRITE)) c̲at "\" width=\"" c̲at (f̲ormat (ˢᵛw̲hole SPRITE)) c̲at "\" height=\"" c̲at (f̲ormat (ˢᵛw̲hole SPRITE)) c̲at "\"/>"
f̲ormat< expands to
"<rect x=\"" c̲at (f̲ormat (ˢᵛw̲hole (ʰs̲x (x, y)) − 10.0)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole sy)) c̲at "\" width=\"20\" height=\"3\" fill=\"#3a0d0d\"/><rect x=\"" c̲at (f̲ormat (ˢᵛw̲hole (ʰs̲x (x, y)) − 10.0)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole sy)) c̲at "\" width=\"" c̲at (f̲ormat (ˢᵛw̲hole 20.0 × frac)) c̲at "\" height=\"3\" fill=\"#ff595e\"/>"
f̲ormat< expands to
"<ellipse cx=\"" c̲at (f̲ormat (sx)) c̲at "\" cy=\"" c̲at (f̲ormat (ˢᵛw̲hole sy)) c̲at "\" rx=\"" c̲at (f̲ormat (ˢᵛw̲hole r)) c̲at "\" ry=\"" c̲at (f̲ormat (ˢᵛw̲hole 0.5 × r)) c̲at "\" fill=\"#000000\" opacity=\"0.3\"/><circle class=\"entity\" cx=\"" c̲at (f̲ormat (sx)) c̲at "\" cy=\"" c̲at (f̲ormat (ˢᵛw̲hole sy − r)) c̲at "\" r=\"" c̲at (f̲ormat (ˢᵛw̲hole r)) c̲at "\" fill=\"" c̲at (f̲ormat (col)) c̲at "\" stroke=\"#1d1f2b\" stroke-width=\"1.5\"/><rect x=\"" c̲at (f̲ormat (ˢᵛw̲hole (ʰs̲x (x, y)) − 10.0)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole sy − 6.0 + 2.0 × r)) c̲at "\" width=\"20\" height=\"3\" fill=\"#3a0d0d\"/><rect x=\"" c̲at (f̲ormat (ˢᵛw̲hole (ʰs̲x (x, y)) − 10.0)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole sy − 6.0 + 2.0 × r)) c̲at "\" width=\"" c̲at (f̲ormat (ˢᵛw̲hole 20.0 × frac)) c̲at "\" height=\"3\" fill=\"#ff595e\"/>"
f̲ormat< expands to
"<circle cx=\"" c̲at (f̲ormat (ˢᵛw̲hole ʰs̲x (x, y))) c̲at "\" cy=\"" c̲at (f̲ormat (ˢᵛw̲hole ʰs̲y (x, y, 22.0))) c̲at "\" r=\"3\" fill=\"#fff3b0\" stroke=\"#000000\" stroke-width=\"0.5\"/>"
f̲ormat< expands to
("<g class=\"" c̲at (f̲ormat (cls)) c̲at "\"><rect x=\"" c̲at (f̲ormat (ˢᵛw̲hole f̲irst r)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole 2 s̲elect r)) c̲at "\" width=\"" c̲at (f̲ormat (ˢᵛw̲hole 3 s̲elect r)) c̲at "\" height=\"" c̲at (f̲ormat (ˢᵛw̲hole 4 s̲elect r)) c̲at "\" rx=\"8\" fill=\"" c̲at (f̲ormat (fill)) c̲at "\" stroke=\"#8d99ae\" stroke-width=\"2\"/><text x=\"" c̲at (f̲ormat (ˢᵛw̲hole (f̲irst r) + 0.5 × 3 s̲elect r)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole (2 s̲elect r) + 33.0)) c̲at "\" font-size=\"18\" text-anchor=\"middle\" fill=\"#ffffff\">" c̲at (f̲ormat (words)) c̲at "</text></g>")
f̲ormat< expands to
((f̲ormat (d̲isclose k s̲elect names)) c̲at " " c̲at (f̲ormat ((1 + 3 × k − 1) s̲elect COST)))
f̲ormat< expands to
("<rect class=\"flat\" x=\"70\" y=\"130\" width=\"340\" height=\"340\" fill=\"#11121c\"/><image class=\"entity flat\" href=\"art/" c̲at (f̲ormat (d̲isclose pg s̲elect PIECES)) c̲at ".png\" x=\"70\" y=\"130\" width=\"340\" height=\"340\"/>")
f̲ormat< expands to
("Reach " c̲at (f̲ormat (pg s̲elect RANGE)) c̲at " | damage " c̲at (f̲ormat (pg s̲elect DAMAGE)) c̲at " | every " c̲at (f̲ormat (pg s̲elect COOLDOWN)) c̲at " s")
f̲ormat< expands to
("Splash " c̲at (f̲ormat (pg s̲elect SPLASH)) c̲at " | slows " c̲at (f̲ormat (pg s̲elect CHILL)) c̲at " s | costs " c̲at (f̲ormat (pg s̲elect COST)))
f̲ormat< expands to
"Click it on the board to upgrade: " c̲at (f̲ormat ((pg + 1) s̲elect COST)) c̲at "."
f̲ormat< expands to
("Hit points " c̲at (f̲ormat (k s̲elect HP)) c̲at " | speed " c̲at (f̲ormat (k s̲elect SPEED)) c̲at " | armor " c̲at (f̲ormat (k s̲elect ARMOR)))
f̲ormat< expands to
("Worth " c̲at (f̲ormat (k s̲elect BOUNTY)) c̲at " | costs " c̲at (f̲ormat (k s̲elect LEAK)) c̲at " lives if it gets out")
f̲ormat< expands to
("<text x=\"" c̲at (f̲ormat (ˢᵛw̲hole x)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole y)) c̲at "\" font-size=\"" c̲at (f̲ormat (ˢᵛw̲hole z)) c̲at "\" fill=\"#e9ecef\">" c̲at (f̲ormat (t)) c̲at "</text>")
f̲ormat< expands to
("Every wave beaten! Lives " c̲at (f̲ormat (lv)) c̲at " | Money " c̲at (f̲ormat (mo)) c̲at " | Time " c̲at (f̲ormat (f̲loor t)) c̲at " s")
f̲ormat< expands to
("The creeps got through. Wave " c̲at (f̲ormat (wv)) c̲at " | Time " c̲at (f̲ormat (f̲loor t)) c̲at " s")
f̲ormat< expands to
"Money " c̲at (f̲ormat (mo)) 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"