From b0ffef5124c88d52d81cbd2f8c96c019ce84ad47 Mon Sep 17 00:00:00 2001 From: nic-gaffney Date: Tue, 18 Apr 2023 09:08:49 -0500 Subject: Need to write tests for it, but hopefully function docs work now --- examples/snake.sloth | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/snake.sloth (limited to 'examples') 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("*"); +} -- cgit v1.2.3