aboutsummaryrefslogtreecommitdiff
path: root/examples/snake.sloth
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-04-27 18:42:28 -0500
committerGitHub <noreply@github.com>2023-04-27 18:42:28 -0500
commit86eab2dc7dc2f88e0f56d09ae3b5f36cf8d9706e (patch)
treed312fd5c0981df90aef29a4131703ae89f328268 /examples/snake.sloth
parent448babe8090c2bcf177c23efd2257a926a1d07f7 (diff)
parentd6b12291db70ea19d37d84226161f964400ae0b2 (diff)
downloadsloth-86eab2dc7dc2f88e0f56d09ae3b5f36cf8d9706e.tar.gz
Merge pull request #5 from slothlang/standard-library
Standard Library
Diffstat (limited to 'examples/snake.sloth')
-rw-r--r--examples/snake.sloth40
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/snake.sloth b/examples/snake.sloth
new file mode 100644
index 0000000..c60819d
--- /dev/null
+++ b/examples/snake.sloth
@@ -0,0 +1,40 @@
+var xPos = 0;
+var yPos = 0;
+# 0=right 1=down 2=left 3=up
+var direction = 0;
+
+while true {
+ if direction == 0{
+ var x = xPos + 1;
+ xPos = x;
+ }
+ if direction == 1 {
+ var y = yPos + 1;
+ yPos = y;
+ }
+ if direction == 2{
+ var x = xPos - 1;
+ xPos = x;
+ }
+ if direction == 3 {
+ var y = yPos - 1;
+ yPos = y;
+ }
+
+ var input = readln();
+ if input == "w" && direction != 1 {
+ direction = 3;
+ }
+ if input == "a" && direction != 0 {
+ direction = 2;
+ }
+ if input == "s" && direction != 3 {
+ direction = 1;
+ }
+ if input == "d" && direction != 2 {
+ direction = 0;
+ }
+
+ term_setpos(x, y);
+ print("*");
+}