sourcegames/tower-defense/tower-defense.xtl
1⍝!/usr/bin/env xetal
2⍝│ Tower defense, scripted (seed 1), with the rules of Defense.xtl on
3⍝│ lib/Ecs: every tower against every creep in one table, shots against
4⍝│ creeps in another, the road found by a flood, the board in 2.5D.
5"td:" u̲se< "Defense"
6
7⍝ The road, in order from S to E (row, column): every road tile's
8⍝ distance to E by a flood, then sorted, farthest first.
9start ← ᵗᵈn̲ew 0
103 t̲ake ᵗᵈr̲oad start
11t̲ally ᵗᵈr̲oad start
12
13⍝ Clicks build towers: a click is turned back into a tile by the inverse
14⍝ of the board's map. Two arrow towers beside the road, then a cannon
15⍝ (picked with the key 2) that the money does not stretch to.
16arrows ← (start ᵗᵈc̲lick 416.0 208.0) ᵗᵈc̲lick 480.0 240.0
17built ← (arrows ᵗᵈk̲ey "2") ᵗᵈc̲lick 352.0 240.0
18ᵗᵈt̲owers built
19ᵗᵈs̲core built
20
21⍝ The first wave (six runners) and twenty seconds of the clock: the
22⍝ towers shoot the creep in reach that has come farthest; beaten creeps
23⍝ pay. Towers, creeps, shots alive; money, lives, waves begun.
24wave ← built ᵗᵈk̲ey " "
25ᵘg̲o ← { s n → (n = 0) ∨ 0 < ᵗᵈs̲tatus s ? s◆ (s ᵗᵈt̲ick 0.1) ᵘg̲o n − 1 }
26later ← wave ᵘg̲o 200
27ᵗᵈc̲ounts later
28ᵗᵈs̲core later
29_ ← ⎕S̲HOW ᵗᵈd̲raw later
30
31⍝ What the game guarantees, checked by a_ssert< (silent when it holds).
32_ ← "52 = t_ally td:r_oad td:n_ew 0" a̲ssert< "the road is 52 tiles from S to E"
33_ ← "20 = 2 s_elect td:s_core later" a̲ssert< "no creep of the first wave got out"
a̲ssert< expands to
({ @ → (52 = t̲ally ᵗᵈr̲oad ᵗᵈn̲ew 0) ? @◆ ⎕E̲RR "assertion failed: 52 = t_ally td:r_oad td:n_ew 0 (the road is 52 tiles from S to E) [games/tower-defense/tower-defense.xtl:32]"◆ @ } @)