programgames/asteroids/asteroids.xtl

Asteroids, scripted (seed 1), with the rules of Rocks.xtl on lib/Ecs: entities spawned and despawned every few ticks (shots fired and spent, rocks broken in two), the free slots found by a mask.

source · imports ro: games/asteroids/Rocks.xtl; ec: lib/Ecs.xtl lib/Ecs.xtlm

start : (Float, Int, Int, Int, Float, Int, Float)

value · line 11
start ← ʳᵒn̲ew 0

W : Float

value · line 12
(W, _, _, _, _, _, _) ← start

ᵘf̲ire : (Num a, Num b, Num c) => (Float, Int, a, Int, Float, b, Float) -> c -> (Float, Int, a, Int, Float, b, Float)

function · line 20
ᵘf̲ire ← { s n → n = 0 ? s◆ ((s ʳᵒk̲ey " ") ʳᵒt̲ick 0.05) ᵘf̲ire n − 1 }
Used in: ᵘf̲ire, fired, later

fired : (Float, Int, Int, Int, Float, Int, Float)

value · line 21
fired ← start ᵘf̲ire 20

later : (Float, Int, Int, Int, Float, Int, Float)

value · line 27
later ← fired ᵘf̲ire 80

_ : Char

function · line 30
_ ← ⎕S̲HOW ʳᵒd̲raw later

_ : Unit

function · line 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]"◆ @ } @)

_ : Unit

function · line 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]"◆ @ } @)

_ : Unit

function · line 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]"◆ @ } @)