-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add two more samples, one for graphing mathematical functions one for a frogger style game as described in https://lab.evy.dev#game Keep them in a single commit to avoid updating snapshots twice.
- Loading branch information
1 parent
85b0419
commit ee33603
Showing
5 changed files
with
409 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// globals | ||
level := 0 | ||
|
||
// position of 👾 | ||
x := 50 | ||
y := 0 | ||
|
||
// x-position of arrows | ||
gold := 0 | ||
orange := 50 | ||
red := 0 | ||
|
||
on animate | ||
updateLevel | ||
updatePositions | ||
draw | ||
checkCollision | ||
end | ||
|
||
// updateLevel increments level global and prints it | ||
// every time we start at the bottom (again). | ||
func updateLevel | ||
if y < 0.1 | ||
level = level + 1 | ||
print "Level" level | ||
end | ||
end | ||
|
||
// updatePositions updates 👾 and arrow position globals | ||
func updatePositions | ||
y = (y + 0.1) % 100 | ||
gold = (gold + 0.3) % 110 | ||
orange = 100 - (100 - orange + 0.5) % 120 | ||
red = (red + 0.7) % 130 | ||
end | ||
|
||
func draw | ||
clear | ||
drawText "👾" x y "" | ||
drawText "▶▶" gold 30 "gold" | ||
drawText "◀◀" orange 50 "orange" | ||
drawText "▶▶" red 70 "orangered" | ||
end | ||
|
||
func drawText s:string x:num y:num hue:string | ||
color hue | ||
move x y | ||
text s | ||
end | ||
|
||
// checkCollision ends game with "Game over" message if | ||
// 👾 collides with arrows. | ||
func checkCollision | ||
if (abs x-gold) < 6 and (abs y-30) < 4.5 | ||
print "🟡 Game over." | ||
exit 0 | ||
else if (abs x-orange) < 6 and (abs y-50) < 4.5 | ||
print "🟠 Game over." | ||
exit 0 | ||
else if (abs x-red) < 6 and (abs y-70) < 4.5 | ||
print "🔴 Game over." | ||
exit 0 | ||
end | ||
end | ||
|
||
// on key moves 👾 left/right for arrow keys and h/l | ||
on key k:string | ||
// introduce next gen to vi keys | ||
if k == "ArrowLeft" or k == "h" | ||
x = (x + 99) % 100 | ||
else if k == "ArrowRight" or k == "l" | ||
x = (x + 1) % 100 | ||
end | ||
end | ||
|
||
// on down moves 👾 left/right for mouse/touch events | ||
// near left and right edge. | ||
on down xd:num _:num | ||
if xd < 20 | ||
x = (x + 99) % 100 | ||
else if xd > 80 | ||
x = (x + 1) % 100 | ||
end | ||
end |
Oops, something went wrong.