File tree Expand file tree Collapse file tree 5 files changed +406
-1
lines changed
e2e/play/test.js-snapshots Expand file tree Collapse file tree 5 files changed +406
-1
lines changed Original file line number Diff line number Diff line change 1+ // globals
2+ level := 0
3+
4+ // position of 👾
5+ x := 50
6+ y := 0
7+
8+ // x-position of arrows
9+ gold := 0
10+ orange := 50
11+ red := 0
12+
13+ on animate
14+ updateLevel
15+ updatePositions
16+ draw
17+ checkCollision
18+ end
19+
20+ // updateLevel increments level global and prints it
21+ // every time we start at the bottom (again).
22+ func updateLevel
23+ if y < 0.1
24+ level = level + 1
25+ print "Level" level
26+ end
27+ end
28+
29+ // updatePositions updates 👾 and arrow position globals
30+ func updatePositions
31+ y = (y + 0.1) % 100
32+ gold = (gold + 0.3) % 110
33+ orange = 100 - (100 - orange + 0.5) % 120
34+ red = (red + 0.7) % 130
35+ end
36+
37+ func draw
38+ clear
39+ drawText "👾" x y ""
40+ drawText "▶▶" gold 30 "gold"
41+ drawText "◀◀" orange 50 "orange"
42+ drawText "▶▶" red 70 "orangered"
43+ end
44+
45+ func drawText s:string x:num y:num hue:string
46+ color hue
47+ move x y
48+ text s
49+ end
50+
51+ // checkCollision ends game with "Game over" message if
52+ // 👾 collides with arrows.
53+ func checkCollision
54+ if (abs x-gold) < 6 and (abs y-30) < 4.5
55+ print "🟡 Game over."
56+ exit 0
57+ else if (abs x-orange) < 6 and (abs y-50) < 4.5
58+ print "🟠 Game over."
59+ exit 0
60+ else if (abs x-red) < 6 and (abs y-70) < 4.5
61+ print "🔴 Game over."
62+ exit 0
63+ end
64+ end
65+
66+ // on key moves 👾 left/right for arrow keys and h/l
67+ on key k:string
68+ if k == "ArrowLeft" or k == "h"
69+ x = (x + 99) % 100
70+ else if k == "ArrowRight" or k == "l"
71+ x = (x + 1) % 100
72+ end
73+ end
74+
75+ // on down moves 👾 left/right for mouse/touch events
76+ // near left and right edge.
77+ on down xd:num _:num
78+ if xd < 20
79+ x = (x + 99) % 100
80+ else if xd > 80
81+ x = (x + 1) % 100
82+ end
83+ end
You can’t perform that action at this time.
0 commit comments