sourcegames/racer/play.xtl

1⍝!/usr/bin/env xetal 2⍝│ The racer: three laps against three rivals. Up (or w) speeds you up, 3⍝│ down (or s) slows you, left and right (or a and d) steer; keep off the 4⍝│ grass, which slows you; r starts again. The race moves with the 5⍝│ clock: on the page it is in a dialog, and the clock's ticks (twenty a 6⍝│ second) and your keys come to the program as events; at the command 7⍝│ line, lines such as "tick 0.05" and "key UP" on standard input. When 8⍝│ you finish the program ends with your place (on the page, Play or any 9⍝│ key then starts a new race). The rules are Race.xtl's, built on 10⍝│ lib/Ecs. 11"rc:" u̲se< "Race" 12 13⍝│ Show the game, then wait for the next event. 14ᵘs̲how ← { s → 15 _ ← ⎕S̲HOW ʳᶜd̲raw s 16 0 < ʳᶜs̲tatus s ? ᵘe̲nd s 17 ᵘl̲oop s 18} 19⍝│ The next event: a tick moves the game on and shows it; a key acts. 20ᵘl̲oop ← { s → 21 e ← ⎕E̲VENT @ 22 "end" m̲atch ⎕E̲KIND e ? "THE END" 23 "tick" m̲atch ⎕E̲KIND e ? ᵘs̲how s ʳᶜt̲ick f̲irst ⎕E̲AT e 24 n̲ot "key" m̲atch ⎕E̲KIND e ? ᵘl̲oop s 25 name ← f̲ormat ⎕E̲KEY e 26 "r" m̲atch name ? ᵘs̲how ʳᶜn̲ew 0 27 ᵘl̲oop s ʳᶜk̲ey name 28} 29⍝│ How the race ended (the program ends with it). 30ᵘe̲nd ← { s → 31 p ← ʳᶜp̲lace s 32 1 = p ? "You won the race!" 33 @ f̲ormat< "You finished in place {p}."
f̲ormat< expands to
"You finished in place " c̲at (f̲ormat (p)) c̲at "."
34} 35ᵘs̲how ʳᶜn̲ew 0