sourcegames/scroller/scroller.xtl
1⍝!/usr/bin/env xetal
2⍝│ The side-scroller, scripted (seed 1), with the rules of Jump.xtl on
3⍝│ lib/Ecs: the world as a matrix, and gravity, movement and collision as
4⍝│ systems over every body at once.
5"j:" u̲se< "Jump"
6"ec:" u̲se< "Ecs"
7
8⍝ A new game: an entity for every character of the level in
9⍝ scroller.toml that is one. The world: a row per entity slot (64) and a
10⍝ column per field (alive, then for each component whether the entity
11⍝ has it, then its fields).
12start ← ʲn̲ew 0
13(W, g, t, st) ← start
14s̲hape W
15ᵉᶜc̲ount W
16
17⍝ What is alive: you, the walkers, the coins, the flag; and the bodies
18⍝ (you and the walkers), on which gravity and the ground act.
19ʲc̲ounts start
20
21⍝ Where you are (x and y in tiles, y down), the coins and the seconds.
22ʲy̲ou start
23
24⍝ Run right for ten ticks of the clock (a second is twenty): the right
25⍝ key sets your speed, and each tick moves every body by its own.
26ᵘr̲un ← { s n → n = 0 ? s◆ ((s ʲk̲ey "RIGHT") ʲt̲ick 0.05) ᵘr̲un n − 1 }
27ran ← start ᵘr̲un 10
28ʲy̲ou ran
29
30⍝ Jump: up sets your speed upward; gravity slows you, turns you and
31⍝ brings you down to the ground. Your height (y) tick by tick:
32ᵘh̲eight ← { s → 2 s̲elect ʲy̲ou s }
33ᵘa̲ir ← { s n → n = 0 ? 0 r̲eshape 0.0◆ (ᵘh̲eight s) c̲at (s ʲt̲ick 0.05) ᵘa̲ir n − 1 }
34up ← ran ʲk̲ey "UP"
35y ← up ᵘa̲ir 16
36f̲loor 0.5 + 100 × y
37_ ← ⎕S̲HOW ʲd̲raw up
38
39⍝ What the game guarantees, checked by a_ssert< (silent when it holds).
40_ ← "1 = f_irst j:c_ounts j:n_ew 0" a̲ssert< "one of you in a new game"
41_ ← "(f_irst y) = 'm_ax r_/ y" a̲ssert< "a jump goes up and comes back down to where it started"
42_ ← "0 = j:s_tatus up" a̲ssert< "still playing"
a̲ssert< expands to
({ @ → (1 = f̲irst ʲc̲ounts ʲn̲ew 0) ? @◆ ⎕E̲RR "assertion failed: 1 = f_irst j:c_ounts j:n_ew 0 (one of you in a new game) [games/scroller/scroller.xtl:40]"◆ @ } @)
a̲ssert< expands to
({ @ → ((f̲irst y) = 'm̲ax r̲/ y) ? @◆ ⎕E̲RR "assertion failed: (f_irst y) = 'm_ax r_/ y (a jump goes up and comes back down to where it started) [games/scroller/scroller.xtl:41]"◆ @ } @)