sourcegames/asteroids/asteroids.xtl

1⍝!/usr/bin/env xetal 2⍝│ Asteroids, scripted (seed 1), with the rules of Rocks.xtl on lib/Ecs: 3⍝│ entities spawned and despawned every few ticks (shots fired and spent, 4⍝│ rocks broken in two), the free slots found by a mask. 5"ro:" u̲se< "Rocks" 6"ec:" u̲se< "Ecs" 7 8⍝ A new game: the ship in the middle and the first wave, three big rocks 9⍝ on a ring around it, flying off at random. The world has 64 slots; 10⍝ alive: the ship, rocks, shots, and the slots in use. 11start ← ʳᵒn̲ew 0 12(W, _, _, _, _, _, _) ← start 13s̲hape W 14ʳᵒc̲ounts start 15f̲loor 0.5 + 100 × ʳᵒr̲ocks start 16 17⍝ Fire every tick for a second, heading up: at most six shots fly at 18⍝ once (a shot is spawned in the first free slot, and spent after a 19⍝ second of flight). 20ᵘf̲ire ← { s n → n = 0 ? s◆ ((s ʳᵒk̲ey " ") ʳᵒt̲ick 0.05) ᵘf̲ire n − 1 } 21fired ← start ᵘf̲ire 20 22ʳᵒc̲ounts fired 23 24⍝ Four more seconds of fire: shots that reach a rock break it, and its 25⍝ two halves are spawned in the slots that freed. The score, lives and 26⍝ wave; what is alive. 27later ← fired ᵘf̲ire 80 28ʳᵒs̲core later 29ʳᵒc̲ounts later 30_ ← ⎕S̲HOW ʳᵒd̲raw later 31 32⍝ What the game guarantees, checked by a_ssert< (silent when it holds). 33_ ← "4 = 4 s_elect ro:c_ounts ro:n_ew 0" a̲ssert< "a new game fills four slots"
a̲ssert< expands to
({ @ → (4 = 4 s̲elect ʳᵒc̲ounts ʳᵒn̲ew 0) ? @◆ ⎕E̲RR "assertion failed: 4 = 4 s_elect ro:c_ounts ro:n_ew 0 (a new game fills four slots) [games/asteroids/asteroids.xtl:33]"◆ @ } @)
34_ ← "6 >= 3 s_elect ro:c_ounts later" a̲ssert< "no more than six shots in flight"
a̲ssert< expands to
({ @ → (6 ≥ 3 s̲elect ʳᵒc̲ounts later) ? @◆ ⎕E̲RR "assertion failed: 6 >= 3 s_elect ro:c_ounts later (no more than six shots in flight) [games/asteroids/asteroids.xtl:34]"◆ @ } @)
35_ ← "(4 s_elect ro:c_ounts later) = '+ r_/ 3 t_ake ro:c_ounts later" a̲ssert< "every slot in use holds the ship, a rock or a shot"
a̲ssert< expands to
({ @ → ((4 s̲elect ʳᵒc̲ounts later) = '+ r̲/ 3 t̲ake ʳᵒc̲ounts later) ? @◆ ⎕E̲RR "assertion failed: (4 s_elect ro:c_ounts later) = '+ r_/ 3 t_ake ro:c_ounts later (every slot in use holds the ship, a rock or a shot) [games/asteroids/asteroids.xtl:35]"◆ @ } @)