sourcegames/raycaster/play.xtl
1⍝!/usr/bin/env xetal
2⍝│ The raycaster: find the way out of the walls, seen from inside. Up (or
3⍝│ w) steps ahead, down (or s) steps back, left and right turn, a and d
4⍝│ step sideways; walk into the teal door to get out; r starts again. The
5⍝│ clock runs while you look: on the page the game is in a dialog, and
6⍝│ the clock's ticks (twenty a second) and your keys come to the program
7⍝│ as events; at the command line, lines such as "tick 0.05" and
8⍝│ "key UP" on standard input. Getting out ends the program (on the page,
9⍝│ Play or any key then starts again). The rules are Rays.xtl's.
10"rc:" u̲se< "Rays"
11
12⍝│ Show the game, then wait for the next event.
13ᵘs̲how ← { s →
14 _ ← ⎕S̲HOW ʳᶜd̲raw s
15 0 < ʳᶜs̲tatus s ? ᵘe̲nd s
16 ᵘl̲oop s
17}
18⍝│ The next event: a tick moves the game on and shows it; a key acts.
19ᵘl̲oop ← { s →
20 e ← ⎕E̲VENT @
21 "end" m̲atch ⎕E̲KIND e ? "THE END"
22 "tick" m̲atch ⎕E̲KIND e ? ᵘs̲how s ʳᶜt̲ick f̲irst ⎕E̲AT e
23 n̲ot "key" m̲atch ⎕E̲KIND e ? ᵘl̲oop s
24 name ← f̲ormat ⎕E̲KEY e
25 "r" m̲atch name ? ᵘs̲how ʳᶜn̲ew 0
26 ᵘl̲oop s ʳᶜk̲ey name
27}
28⍝│ How it ended (the program ends with it).
29ᵘe̲nd ← { s → @ f̲ormat< "You found the way out in {f_loor 4 s_elect rc:y_ou s} seconds!" }
30ᵘs̲how ʳᶜn̲ew 0
f̲ormat< expands to
"You found the way out in " c̲at (f̲ormat (f̲loor 4 s̲elect ʳᶜy̲ou s)) c̲at " seconds!"