sourcegames/scroller/play.xtl
1⍝!/usr/bin/env xetal
2⍝│ The side-scroller: run right to the flag. Left and right (or a and d)
3⍝│ run, up (or w) jumps; land on a walker to beat it, touch one otherwise
4⍝│ and you are caught; mind the pits; pick up the coins; r starts again.
5⍝│ The game moves with the clock: on the page it is in a dialog, and the
6⍝│ clock's ticks (twenty a second) and your keys come to the program as
7⍝│ events; at the command line, lines such as "tick 0.05" and "key UP"
8⍝│ on standard input. A game won or lost ends the program (on the page,
9⍝│ Play or any key then starts a new one). The rules are Jump.xtl's,
10⍝│ built on lib/Ecs.
11"j:" u̲se< "Jump"
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 game ended (the program ends with it).
30ᵘe̲nd ← { s →
31 y ← ʲy̲ou s
32 1 = ʲs̲tatus s ? @ f̲ormat< "You reached the flag with {f_loor 3 s_elect y} coins in {f_loor 4 s_elect y} seconds!"
33 @ f̲ormat< "Caught! {f_loor 3 s_elect y} coins in {f_loor 4 s_elect y} seconds."
34}
35ᵘs̲how ʲn̲ew 0
f̲ormat< expands to
("You reached the flag with " c̲at (f̲ormat (f̲loor 3 s̲elect y)) c̲at " coins in " c̲at (f̲ormat (f̲loor 4 s̲elect y)) c̲at " seconds!")
f̲ormat< expands to
"Caught! " c̲at (f̲ormat (f̲loor 3 s̲elect y)) c̲at " coins in " c̲at (f̲ormat (f̲loor 4 s̲elect y)) c̲at " seconds."