programgames/raycaster/play.xtl

The raycaster: find the way out of the walls, seen from inside. Up (or w) steps ahead, down (or s) steps back, left and right turn, a and d step sideways; walk into the teal door to get out; r starts again. The clock runs while you look: on the page the game is in a dialog, and the clock's ticks (twenty a second) and your keys come to the program as events; at the command line, lines such as "tick 0.05" and "key UP" on standard input. Getting out ends the program (on the page, Play or any key then starts again). The rules are Rays.xtl's.

source · imports rc: games/raycaster/Rays.xtl

ᵘs̲how : Num a => (Float, Float, Float, Float, a) -> Char

function · line 13

Show the game, then wait for the next event.

ᵘs̲how ← { s →
  _ ← ⎕S̲HOW ʳᶜd̲raw s
  0 < ʳᶜs̲tatus s ? ᵘe̲nd s
  ᵘl̲oop s
}

ᵘl̲oop : Num a => (Float, Float, Float, Float, a) -> Char

function · line 19

The next event: a tick moves the game on and shows it; a key acts.

ᵘl̲oop ← { s →
  e ← ⎕E̲VENT @
  "end" m̲atch ⎕E̲KIND e ? "THE END"
  "tick" m̲atch ⎕E̲KIND e ? ᵘs̲how s ʳᶜt̲ick f̲irst ⎕E̲AT e
  n̲ot "key" m̲atch ⎕E̲KIND e ? ᵘl̲oop s
  name ← f̲ormat ⎕E̲KEY e
  "r" m̲atch name ? ᵘs̲how ʳᶜn̲ew 0
  ᵘl̲oop s ʳᶜk̲ey name
}

ᵘe̲nd : Num a => (Float, Float, Float, Float, a) -> Char

function · line 29

How it ended (the program ends with it).

ᵘe̲nd ← { s → @ f̲ormat< "You found the way out in {f_loor 4 s_elect rc:y_ou s} seconds!" }
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!"
Used in: ᵘs̲how