sourcegames/scroller/Jump.xtl

1⍝│ The side-scroller's rules, a library: scroller.xtl (scripted), 2⍝│ play.xtl (the game: keys and the clock) and the web page all use 3⍝│ these. Built on lib/Ecs: a world is a matrix, a row per entity, and 4⍝│ every rule is a system, one expression over every entity with the 5⍝│ components it needs. You, the walkers, the coins and the flag are 6⍝│ entities; gravity, movement and collision with the ground act on 7⍝│ every body at once, you and the walkers alike. A game's state is a 8⍝│ tuple: (the world, the coins picked up, the seconds played, how it 9⍝│ stands: 0 playing, 1 you reached the flag, 2 you were caught or fell). 10 11"ec:" u̲se< "Ecs" 12"sv:" u̲se< "Svg" 13"t:" u̲se< "Text" 14 15⍝━━ The data 16 17⍝│ The layout: where it is (x then y, in tiles, y down), how fast it 18⍝│ moves, whether gravity and the ground act on it, and what it is. 19"h" ᵉᶜc̲omponents< "pos:2 vel:2 body walker coin player goal"
ᵉᶜc̲omponents< expands to
ʰw̲orld ← { n → (n c̲at 17) r̲eshape 0.0 }
ʰp̲os ← { W → (3 4) s̲elect₂ W }
ʰh̲asPos ← { W → 0 < 2 s̲elect₂ W }
ʰs̲etPos ← { W (ids, v) →
  i ← r̲avel ids
  V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 2) r̲eshape v
  R ← f̲loat (r̲ange t̲ally W) '= t̲able i
  C ← f̲loat (2 3 4) '= t̲able r̲ange 17
  M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 3) r̲eshape 1.0) '+ '× i̲nner C
  (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C
}
ʰd̲ropPos ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 2 = r̲ange 17 }
ʰv̲el ← { W → (6 7) s̲elect₂ W }
ʰh̲asVel ← { W → 0 < 5 s̲elect₂ W }
ʰs̲etVel ← { W (ids, v) →
  i ← r̲avel ids
  V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 2) r̲eshape v
  R ← f̲loat (r̲ange t̲ally W) '= t̲able i
  C ← f̲loat (5 6 7) '= t̲able r̲ange 17
  M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 3) r̲eshape 1.0) '+ '× i̲nner C
  (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C
}
ʰd̲ropVel ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 5 = r̲ange 17 }
ʰb̲ody ← { W → (9) s̲elect₂ W }
ʰh̲asBody ← { W → 0 < 8 s̲elect₂ W }
ʰs̲etBody ← { W (ids, v) →
  i ← r̲avel ids
  V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v
  R ← f̲loat (r̲ange t̲ally W) '= t̲able i
  C ← f̲loat (8 9) '= t̲able r̲ange 17
  M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C
  (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C
}
ʰd̲ropBody ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 8 = r̲ange 17 }
ʰw̲alker ← { W → (11) s̲elect₂ W }
ʰh̲asWalker ← { W → 0 < 10 s̲elect₂ W }
ʰs̲etWalker ← { W (ids, v) →
  i ← r̲avel ids
  V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v
  R ← f̲loat (r̲ange t̲ally W) '= t̲able i
  C ← f̲loat (10 11) '= t̲able r̲ange 17
  M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C
  (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C
}
ʰd̲ropWalker ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 10 = r̲ange 17 }
ʰc̲oin ← { W → (13) s̲elect₂ W }
ʰh̲asCoin ← { W → 0 < 12 s̲elect₂ W }
ʰs̲etCoin ← { W (ids, v) →
  i ← r̲avel ids
  V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v
  R ← f̲loat (r̲ange t̲ally W) '= t̲able i
  C ← f̲loat (12 13) '= t̲able r̲ange 17
  M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C
  (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C
}
ʰd̲ropCoin ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 12 = r̲ange 17 }
ʰp̲layer ← { W → (15) s̲elect₂ W }
ʰh̲asPlayer ← { W → 0 < 14 s̲elect₂ W }
ʰs̲etPlayer ← { W (ids, v) →
  i ← r̲avel ids
  V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v
  R ← f̲loat (r̲ange t̲ally W) '= t̲able i
  C ← f̲loat (14 15) '= t̲able r̲ange 17
  M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C
  (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C
}
ʰd̲ropPlayer ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 14 = r̲ange 17 }
ʰg̲oal ← { W → (17) s̲elect₂ W }
ʰh̲asGoal ← { W → 0 < 16 s̲elect₂ W }
ʰs̲etGoal ← { W (ids, v) →
  i ← r̲avel ids
  V ← (((t̲ally i) c̲at 1) r̲eshape 1.0) c̲at₂ ((t̲ally i) c̲at 1) r̲eshape v
  R ← f̲loat (r̲ange t̲ally W) '= t̲able i
  C ← f̲loat (16 17) '= t̲able r̲ange 17
  M ← 0 < R '+ '× i̲nner (((t̲ally i) c̲at 2) r̲eshape 1.0) '+ '× i̲nner C
  (W × f̲loat n̲ot M) + R '+ '× i̲nner V '+ '× i̲nner C
}
ʰd̲ropGoal ← { W ids → W × f̲loat n̲ot ((r̲ange t̲ally W) m̲ember? r̲avel ids) '× t̲able 16 = r̲ange 17 }
20⍝│ The level: R rows of C tiles, row by row; which tiles are ground. 21rows ← "scroller.toml" ⎕L̲IST "level" 22cells ← ᵗj̲oin rows 23R ← t̲ally rows 24C ← (t̲ally cells) d̲iv R 25solid ← cells = f̲irst "#" 26⍝│ The physics: gravity, a jump's speed, running speed, a walker's 27⍝│ speed, the fastest fall, the speed kept each tick. 28phys ← 'ˢᵛn̲um e̲ach "scroller.toml" ⎕L̲IST "physics" 29GRAVITY ← f̲irst phys 30JUMP ← 2 s̲elect phys 31RUN ← 3 s̲elect phys 32WALK ← 4 s̲elect phys 33FALL ← 5 s̲elect phys 34KEEP ← 6 s̲elect phys 35⍝│ Every entity is a square this many tiles wide. 36SIZE ← 0.8 37 38⍝━━ A new game 39 40⍝│ n by 2 from two columns (x and y, or two speeds). 41ʰp̲air ← { (a, b) → o̲\ (2 c̲at t̲ally a) r̲eshape a c̲at b } 42⍝ :: (Any a, Num b, Num c) => a -> (Float, b, Float, c) 43⍝│ A new game: an entity for each character of the level that is one 44⍝│ (you, the coins, the walkers, the flag), standing on its tile; the 45⍝│ walkers set off to the left. Gravity and the ground act on you and the 46⍝│ walkers (body); the coins and the flag stay where they are. 47ˡn̲ew ← { z → 48 at ← w̲here cells m̲ember? "@owF" 49 ch ← at s̲elect cells 50 (spawned, ids) ← (ʰw̲orld 64) ᵉᶜs̲pawn t̲ally at 51 x ← 0.1 + f̲loat (at − 1) m̲od C 52 y ← (1.0 − SIZE) + f̲loat (at − 1) d̲iv C 53 me ← (ch = f̲irst "@") r̲eplicate ids 54 walk ← (ch = f̲irst "w") r̲eplicate ids 55 placed ← spawned ʰs̲etPos (ids, ʰp̲air (x, y)) 56 moving ← ((placed ʰs̲etVel (me, 0.0 0.0)) ʰs̲etVel (walk, (n̲eg WALK) c̲at 0.0)) ʰs̲etBody (me c̲at walk, 1.0) 57 cast ← (moving ʰs̲etPlayer (me, 1.0)) ʰs̲etWalker (walk, 1.0) 58 W ← (cast ʰs̲etCoin ((ch = f̲irst "o") r̲eplicate ids, 1.0)) ʰs̲etGoal ((ch = f̲irst "F") r̲eplicate ids, 1.0) 59 (W, 0, 0.0, 0) 60} 61 62⍝━━ The systems 63 64⍝│ Whether the tiles at rows r and columns c (whole numbers, any number 65⍝│ of them) are ground: past the left or right end is a wall, above the 66⍝│ top or below the bottom is open. 67ʰs̲olid ← { (r, c) → 68 side ← (c < 0) ∨ c ≥ C 69 in ← (n̲ot side) ∧ (r ≥ 0) ∧ r < R 70 k ← 1 + (C × 0 m̲ax r m̲in R − 1) + 0 m̲ax c m̲in C − 1 71 side ∨ in ∧ k s̲elect solid 72} 73⍝│ The bodies alive: you and the walkers. 74ʰb̲odies ← { W → w̲here (ᵉᶜa̲live W) ∧ ʰh̲asBody W } 75⍝│ Your entity. 76ʰm̲e ← { W → f̲irst w̲here (ᵉᶜa̲live W) ∧ ʰh̲asPlayer W } 77 78⍝│ Gravity: every body falls faster, up to the fastest fall. 79ʰg̲ravity ← { W dt → 80 b ← ʰb̲odies W 81 V ← b s̲elect ʰv̲el W 82 W ʰs̲etVel (b, ʰp̲air (1 s̲elect₂ V, FALL m̲in (2 s̲elect₂ V) + GRAVITY × dt)) 83} 84⍝│ Your speed, kept a little less each tick once you let go. 85ʰs̲low ← { W → me ← ʰm̲e W◆ W ʰs̲etVel (me, (KEEP × 1 s̲elect me s̲elect ʰv̲el W) c̲at 2 s̲elect me s̲elect ʰv̲el W) } 86⍝│ Across: every body moves by its speed, stopped at the ground in its 87⍝│ way (its edge put against the tile); a walker stopped turns back. 88ʰa̲cross ← { W dt → 89 b ← ʰb̲odies W 90 P ← b s̲elect ʰp̲os W 91 V ← b s̲elect ʰv̲el W 92 y ← 2 s̲elect₂ P 93 vx ← 1 s̲elect₂ V 94 ahead ← vx > 0.0 95 tx ← (1 s̲elect₂ P) + vx × dt 96 c ← f̲loor tx + SIZE × f̲loat ahead 97 hit ← (vx ≠ 0.0) ∧ (ʰs̲olid (f̲loor y + 0.01, c)) ∨ ʰs̲olid (f̲loor y + SIZE − 0.01, c) 98 h ← f̲loat hit 99 snap ← (f̲loat c) + (f̲loat n̲ot ahead) − SIZE × f̲loat ahead 100 nx ← (tx × 1.0 − h) + snap × h 101 nvx ← vx × 1.0 − h × 1.0 + f̲loat b s̲elect ʰh̲asWalker W 102 (W ʰs̲etPos (b, ʰp̲air (nx, y))) ʰs̲etVel (b, ʰp̲air (nvx, 2 s̲elect₂ V)) 103} 104⍝│ Down (or up): every body moves by its speed, landing on the ground 105⍝│ below it or stopped by the ground above, its speed then 0. 106ʰd̲own ← { W dt → 107 b ← ʰb̲odies W 108 P ← b s̲elect ʰp̲os W 109 V ← b s̲elect ʰv̲el W 110 x ← 1 s̲elect₂ P 111 vy ← 2 s̲elect₂ V 112 down ← vy > 0.0 113 ty ← (2 s̲elect₂ P) + vy × dt 114 r ← f̲loor ty + SIZE × f̲loat down 115 hit ← (vy ≠ 0.0) ∧ (ʰs̲olid (r, f̲loor x + 0.01)) ∨ ʰs̲olid (r, f̲loor x + SIZE − 0.01) 116 h ← f̲loat hit 117 snap ← (f̲loat r) + (f̲loat n̲ot down) − SIZE × f̲loat down 118 ny ← (ty × 1.0 − h) + snap × h 119 (W ʰs̲etPos (b, ʰp̲air (x, ny))) ʰs̲etVel (b, ʰp̲air (1 s̲elect₂ V, vy × 1.0 − h)) 120} 121⍝│ Which entities of ids touch you (at p, one row of x and y). 122ʰt̲ouching ← { W (ids, p) → (r̲avel ᵉᶜn̲ear (ids s̲elect ʰp̲os W, 1 2 r̲eshape p, SIZE)) r̲eplicate ids } 123⍝│ Whether any of m holds. 124ʰa̲ny ← { m → 0 < '+ r̲/ 0 c̲at 0 + m } 125⍝│ How it stands: caught or fallen 2, at the flag 1, else 0. 126ʰo̲utcome ← { (caught, won) → caught ? 2◆ won ? 1◆ 0 } 127⍝│ What touches you: coins are picked up; a walker you land on is beaten 128⍝│ (and you bounce), one that meets you otherwise catches you; the flag 129⍝│ wins. A walker that falls out of the level goes; so do you, caught. 130ʰt̲ouch ← { W g → 131 me ← ʰm̲e W 132 p ← me s̲elect ʰp̲os W 133 got ← W ʰt̲ouching (w̲here (ᵉᶜa̲live W) ∧ ʰh̲asCoin W, p) 134 picked ← W ᵉᶜd̲espawn got 135 met ← picked ʰt̲ouching (w̲here (ᵉᶜa̲live picked) ∧ ʰh̲asWalker picked, p) 136 vy ← 2 s̲elect me s̲elect ʰv̲el picked 137 beat ← (vy > 0.0) ∧ (0.3 + 2 s̲elect p) < 2 s̲elect₂ met s̲elect ʰp̲os picked 138 b ← f̲loat ʰa̲ny beat 139 bounced ← picked ʰs̲etVel (me, (1 s̲elect me s̲elect ʰv̲el picked) c̲at (vy × 1.0 − b) − 0.6 × JUMP × b) 140 fought ← bounced ᵉᶜd̲espawn beat r̲eplicate met 141 gone ← w̲here (ᵉᶜa̲live fought) ∧ (ʰh̲asWalker fought) ∧ (2 s̲elect₂ ʰp̲os fought) > f̲loat R + 1 142 left ← fought ᵉᶜd̲espawn gone 143 caught ← (ʰa̲ny n̲ot beat) ∨ (2 s̲elect p) > f̲loat R 144 won ← 0 < t̲ally left ʰt̲ouching (w̲here (ᵉᶜa̲live left) ∧ ʰh̲asGoal left, p) 145 (left, g + t̲ally got, ʰo̲utcome (caught, won)) 146} 147⍝ :: Num a => (Float, Int, Float, a) -> Float -> (Float, Int, Float, a) 148⍝│ A tick of the clock, dt seconds: gravity, then every body across and 149⍝│ down, then what touches you; each a system over every entity at once. 150⍝│ A game over stays as it is. 151ˡt̲ick ← { (W, g, t, st) dt → 152 st > 0 ? (W, g, t, st) 153 moved ← ((ʰs̲low W ʰg̲ravity dt) ʰa̲cross dt) ʰd̲own dt 154 (left, coins, stands) ← moved ʰt̲ouch g 155 (left, coins, t + dt, stands) 156} 157 158⍝━━ Your keys 159 160⍝│ Whether you stand on the ground (it is just below your feet). 161ʰs̲tanding? ← { W me → 162 p ← me s̲elect ʰp̲os W 163 r ← f̲loor (2 s̲elect p) + SIZE + 0.05 164 '∨ r̲/ (ʰs̲olid (r, f̲loor (f̲irst p) + 0.01)) c̲at ʰs̲olid (r, f̲loor (f̲irst p) + SIZE − 0.01) 165} 166⍝ :: (Any a, Any b, Num c) => (Float, a, b, c) -> Char -> (Float, a, b, c) 167⍝│ A key: left or right (or a and d) runs that way, up (or w) jumps when 168⍝│ you stand on the ground; other keys do nothing. 169ˡk̲ey ← { s name → 170 (W, g, t, st) ← s 171 me ← ʰm̲e W 172 V ← me s̲elect ʰv̲el W 173 k ← ("LEFT" "RIGHT" "a" "d" "UP" "w") i̲ndexOf e̲nclose name 174 (k > 6) ∨ st > 0 ? s 175 (k > 4) ∧ n̲ot W ʰs̲tanding? me ? s 176 k > 4 ? (W ʰs̲etVel (me, (f̲irst V) c̲at n̲eg JUMP), g, t, st) 177 (W ʰs̲etVel (me, (RUN × f̲loat (2 × (k − 1) m̲od 2) − 1) c̲at 2 s̲elect V), g, t, st) 178} 179 180⍝━━ What it shows 181 182⍝ :: (Any a, Any b, Any c, Any d) => (a, b, c, d) -> d 183⍝│ 0 playing, 1 you reached the flag, 2 you were caught or fell. 184ˡs̲tatus ← { (W, g, t, st) → st } 185⍝ :: (Num a, Any b, Any c, Any d, Num e, Truthy e) => (a, b, c, d) -> e 186⍝│ How many of each are alive: you, walkers, coins, flags; and how many 187⍝│ of them gravity and the ground act on (bodies). 188ˡc̲ounts ← { (W, g, t, st) → 189 n ← 5 c̲at t̲ally W 190 M ← n r̲eshape 0 + (ʰh̲asPlayer W) c̲at (ʰh̲asWalker W) c̲at (ʰh̲asCoin W) c̲at (ʰh̲asGoal W) c̲at ʰh̲asBody W 191 '+ r̲/₂ M × n r̲eshape 0 + ᵉᶜa̲live W 192} 193⍝ :: (Num a, Any b, Any c, Any d) => (a, b, c, d) -> a 194⍝│ Where every body is (you and the walkers): a row each, x then y. 195ˡb̲odies ← { (W, g, t, st) → (ʰb̲odies W) s̲elect ʰp̲os W } 196⍝ :: (Num a, Any b) => (Float, a, Float, b) -> Float 197⍝│ Where you are (x then y, in tiles), the coins and the seconds. 198ˡy̲ou ← { (W, g, t, st) → ((ʰm̲e W) s̲elect ʰp̲os W) c̲at (f̲loat g) c̲at t } 199⍝│ A tile of ground, drawn: grass on top where open sky is above it. 200ʰt̲ile ← { k → 201 top ← (k > C) ∧ (1 m̲ax k − C) s̲elect n̲ot solid 202 fill ← d̲isclose (1 + top ∨ k ≤ C) s̲elect "#8d5a34" "#4caf50" 203 e̲nclose @ f̲ormat< "<rect x=\"{50 * (k - 1) m_od C}\" y=\"{60 + 50 * (k - 1) d_iv C}\" width=\"50\" height=\"50\" fill=\"{fill}\" stroke=\"#5b3a1e\" stroke-width=\"2\"/>"
f̲ormat< expands to
("<rect x=\"" c̲at (f̲ormat (50 × (k − 1) m̲od C)) c̲at "\" y=\"" c̲at (f̲ormat (60 + 50 × (k − 1) d̲iv C)) c̲at "\" width=\"50\" height=\"50\" fill=\"" c̲at (f̲ormat (fill)) c̲at "\" stroke=\"#5b3a1e\" stroke-width=\"2\"/>")
204} 205⍝│ The whole level drawn once; each picture slides it under the view. 206level ← ᵗj̲oin 'ʰt̲ile e̲ach w̲here solid 207⍝│ An entity, drawn at x, y (tiles) by what it is: 1 you, 2 a walker, 3 a 208⍝│ coin, 4 the flag. 209ʰs̲prite ← { (x, y, k) → 210 X ← 50.0 × x 211 Y ← 60.0 + 50.0 × y 212 k = 1 ? @ f̲ormat< "<rect class=\"entity you\" x=\"{sv:w_hole X}\" y=\"{sv:w_hole Y}\" width=\"40\" height=\"40\" rx=\"8\" fill=\"#e63946\" stroke=\"#1d1d1f\" stroke-width=\"3\"/><rect x=\"{sv:w_hole X + 24}\" y=\"{sv:w_hole Y + 10}\" width=\"8\" height=\"10\" fill=\"#ffffff\"/>"
f̲ormat< expands to
("<rect class=\"entity you\" x=\"" c̲at (f̲ormat (ˢᵛw̲hole X)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole Y)) c̲at "\" width=\"40\" height=\"40\" rx=\"8\" fill=\"#e63946\" stroke=\"#1d1d1f\" stroke-width=\"3\"/><rect x=\"" c̲at (f̲ormat (ˢᵛw̲hole X + 24)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole Y + 10)) c̲at "\" width=\"8\" height=\"10\" fill=\"#ffffff\"/>")
213 k = 2 ? @ f̲ormat< "<rect class=\"entity\" x=\"{sv:w_hole X}\" y=\"{sv:w_hole Y + 8}\" width=\"40\" height=\"32\" rx=\"14\" fill=\"#6d4c41\" stroke=\"#1d1d1f\" stroke-width=\"3\"/>"
f̲ormat< expands to
("<rect class=\"entity\" x=\"" c̲at (f̲ormat (ˢᵛw̲hole X)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole Y + 8)) c̲at "\" width=\"40\" height=\"32\" rx=\"14\" fill=\"#6d4c41\" stroke=\"#1d1d1f\" stroke-width=\"3\"/>")
214 k = 3 ? @ f̲ormat< "<circle class=\"entity\" cx=\"{sv:w_hole X + 20}\" cy=\"{sv:w_hole Y + 20}\" r=\"12\" fill=\"#ffd166\" stroke=\"#b8860b\" stroke-width=\"3\"/>"
f̲ormat< expands to
("<circle class=\"entity\" cx=\"" c̲at (f̲ormat (ˢᵛw̲hole X + 20)) c̲at "\" cy=\"" c̲at (f̲ormat (ˢᵛw̲hole Y + 20)) c̲at "\" r=\"12\" fill=\"#ffd166\" stroke=\"#b8860b\" stroke-width=\"3\"/>")
215 @ f̲ormat< "<rect x=\"{sv:w_hole X + 18}\" y=\"{sv:w_hole Y - 110}\" width=\"5\" height=\"150\" fill=\"#333333\"/><polygon class=\"entity\" points=\"{sv:w_hole X + 23},{sv:w_hole Y - 110} {sv:w_hole X + 63},{sv:w_hole Y - 92} {sv:w_hole X + 23},{sv:w_hole Y - 74}\" fill=\"#2a9d8f\"/>"
f̲ormat< expands to
"<rect x=\"" c̲at (f̲ormat (ˢᵛw̲hole X + 18)) c̲at "\" y=\"" c̲at (f̲ormat (ˢᵛw̲hole Y − 110)) c̲at "\" width=\"5\" height=\"150\" fill=\"#333333\"/><polygon class=\"entity\" points=\"" c̲at (f̲ormat (ˢᵛw̲hole X + 23)) c̲at "," c̲at (f̲ormat (ˢᵛw̲hole Y − 110)) c̲at " " c̲at (f̲ormat (ˢᵛw̲hole X + 63)) c̲at "," c̲at (f̲ormat (ˢᵛw̲hole Y − 92)) c̲at " " c̲at (f̲ormat (ˢᵛw̲hole X + 23)) c̲at "," c̲at (f̲ormat (ˢᵛw̲hole Y − 74)) c̲at "\" fill=\"#2a9d8f\"/>"
216} 217⍝│ What the top line says. 218ʰs̲ays ← { (g, t, st) → 219 st = 1 ? @ f̲ormat< "You reached the flag! | Coins {g} | Time {f_loor t} s"
f̲ormat< expands to
("You reached the flag! | Coins " c̲at (f̲ormat (g)) c̲at " | Time " c̲at (f̲ormat (f̲loor t)) c̲at " s")
220 st = 2 ? @ f̲ormat< "Caught! | Coins {g} | Time {f_loor t} s"
f̲ormat< expands to
("Caught! | Coins " c̲at (f̲ormat (g)) c̲at " | Time " c̲at (f̲ormat (f̲loor t)) c̲at " s")
221 @ f̲ormat< "Coins {g} | Time {f_loor t} s | Arrows: run and jump"
f̲ormat< expands to
"Coins " c̲at (f̲ormat (g)) c̲at " | Time " c̲at (f̲ormat (f̲loor t)) c̲at " s | Arrows: run and jump"
222} 223⍝ :: (Num b, Num c) => (Float, a, b, c) -> Char 224⍝│ The picture, as SVG text: the sky, then the level and every entity 225⍝│ alive slid so that you stay in view (16 tiles wide, the rest cut 226⍝│ off), then the top line. 227ˡd̲raw ← { (W, g, t, st) → 228 v ← 0.0 0.0 800.0 c̲at 60.0 + 50.0 × f̲loat R 229 me ← ʰm̲e W 230 cx ← 0.0 m̲ax (f̲loat C − 16) m̲in (f̲irst me s̲elect ʰp̲os W) − 7.0 231 live ← w̲here ᵉᶜa̲live W 232 P ← live s̲elect ʰp̲os W 233 k ← (0 + live s̲elect ʰh̲asPlayer W) + (2 × 0 + live s̲elect ʰh̲asWalker W) + (3 × 0 + live s̲elect ʰh̲asCoin W) + 4 × 0 + live s̲elect ʰh̲asGoal W 234 order ← g̲rade k = 1 235 ents ← '{ i → e̲nclose ʰs̲prite (i s̲elect 1 s̲elect₂ P, i s̲elect 2 s̲elect₂ P, i s̲elect k) } e̲ach order 236 slide ← e̲nclose @ f̲ormat< "<g transform=\"translate({sv:w_hole n_eg 50.0 * cx} 0)\">"
f̲ormat< expands to
("<g transform=\"translate(" c̲at (f̲ormat (ˢᵛw̲hole n̲eg 50.0 × cx)) c̲at " 0)\">")
237 top ← (20.0, 42.0, 30.0) ˢᵛw̲ords ʰs̲ays (g, t, st) 238 clip ← e̲nclose @ f̲ormat< "<clipPath id=\"view\"><rect width=\"800\" height=\"{sv:w_hole 4 s_elect v}\"/></clipPath><g clip-path=\"url(#view)\">"
f̲ormat< expands to
("<clipPath id=\"view\"><rect width=\"800\" height=\"" c̲at (f̲ormat (ˢᵛw̲hole 4 s̲elect v)) c̲at "\"/></clipPath><g clip-path=\"url(#view)\">")
239 v ˢᵛp̲icture (v ˢᵛr̲ect "fill=\"#8ecae6\"") c̲at clip c̲at slide c̲at (e̲nclose level) c̲at ents c̲at (e̲nclose "</g></g>") c̲at top 240}