sourcegames/raycaster/raycaster.xtl
1⍝!/usr/bin/env xetal
2⍝│ The raycaster, scripted (seed 1), with the rules of Rays.xtl: one ray
3⍝│ per column of the picture, every ray stepped through the grid at once
4⍝│ until all of them have hit a wall.
5"rc:" u̲se< "Rays"
6
7⍝ A new game: you in the middle of the start tile, facing east (x, y in
8⍝ tiles, y down; the way you face in radians; the seconds).
9s ← ʳᶜn̲ew 0
10ʳᶜy̲ou s
11
12⍝ What the rays see, one row each (120 of them, left to right): the
13⍝ wall's kind (1 to 4 its color, 5 the door), the side it was struck on
14⍝ (0 across, 1 down) and how far it is. The leftmost five, then the
15⍝ middle one: the blue wall (kind 2) five and a half tiles ahead.
16r ← ʳᶜs̲ees s
175 t̲ake r
1860 s̲elect r
19
20⍝ Three steps ahead and a quarter turn right (twelve turns of 7.5
21⍝ degrees): the middle ray now looks south, down the corridor.
22ᵘp̲ress ← { s k → s ʳᶜk̲ey k }
23ᵘk̲eys ← { s ks → 0 = t̲ally ks ? s◆ (s ᵘp̲ress d̲isclose f̲irst ks) ᵘk̲eys 1 d̲rop ks }
24turned ← (s ᵘk̲eys "UP" "UP" "UP") ᵘk̲eys 12 r̲eshape e̲nclose "RIGHT"
25ʳᶜy̲ou turned
2660 s̲elect ʳᶜs̲ees turned
27_ ← ⎕S̲HOW ʳᶜd̲raw turned
28
29⍝ What the game guarantees, checked by a_ssert< (silent when it holds).
30_ ← "2 = f_loor f_irst 60 s_elect rc:s_ees rc:n_ew 0" a̲ssert< "straight ahead at the start is the blue wall"
31_ ← "120 = t_ally rc:s_ees turned" a̲ssert< "a ray for every column"
32_ ← "0 = rc:s_tatus turned" a̲ssert< "still inside"
a̲ssert< expands to
({ @ → (2 = f̲loor f̲irst 60 s̲elect ʳᶜs̲ees ʳᶜn̲ew 0) ? @◆ ⎕E̲RR "assertion failed: 2 = f_loor f_irst 60 s_elect rc:s_ees rc:n_ew 0 (straight ahead at the start is the blue wall) [games/raycaster/raycaster.xtl:30]"◆ @ } @)
a̲ssert< expands to
({ @ → (120 = t̲ally ʳᶜs̲ees turned) ? @◆ ⎕E̲RR "assertion failed: 120 = t_ally rc:s_ees turned (a ray for every column) [games/raycaster/raycaster.xtl:31]"◆ @ } @)