RosettaCodeData/Task/Snake/EasyLang/snake.easy

123 lines
1.9 KiB
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
subr fruit
2026-04-30 12:34:36 -04:00
rx = (random 0 19) * 5 + 2.5
ry = (random 0 19) * 5 + 2.5
2023-07-01 11:58:00 -04:00
.
subr start
2023-09-16 17:28:03 -07:00
fruit
2023-07-01 11:58:00 -04:00
game = 1
sx[] = [ 52.5 0 0 0 0 ]
sy[] = [ 52.5 0 0 0 0 ]
2026-04-30 12:34:36 -04:00
dir = random 1 4
2023-07-01 11:58:00 -04:00
timer 0
.
2025-06-11 20:16:52 -04:00
gbackground 242
gclear
gcolor 997
gtext 30 70 "SNAKE"
gtextsize 5
gtext 6 40 "Keys or mouse for controlling"
gtext 6 30 "Space or click to start"
2023-07-01 11:58:00 -04:00
#
2025-06-11 20:16:52 -04:00
on key_down
2023-10-02 18:11:16 -07:00
if game = 0 and keybkey = " "
2023-09-16 17:28:03 -07:00
start
2023-10-02 18:11:16 -07:00
return
.
if dir mod 2 = 1
if keybkey = "ArrowRight"
dir = 2
elif keybkey = "ArrowLeft"
dir = 4
.
else
if keybkey = "ArrowUp"
dir = 1
elif keybkey = "ArrowDown"
dir = 3
.
.
.
on mouse_down
if game = 0
start
return
.
if dir mod 2 = 1
if mouse_x < sx
dir = 4
else
dir = 2
.
else
if mouse_y < sy
dir = 3
else
dir = 1
.
2023-07-01 11:58:00 -04:00
.
.
2025-06-11 20:16:52 -04:00
proc over .
gcolor 997
gtext 10 10 "Space or click for new game"
game = 2
timer 1
.
2023-07-01 11:58:00 -04:00
on timer
2025-06-11 20:16:52 -04:00
if game = 2
game = 0
return
.
sx = sx[1]
sy = sy[1]
2023-07-01 11:58:00 -04:00
if dir = 1
sy += 5
elif dir = 2
sx += 5
elif dir = 3
sy -= 5
elif dir = 4
sx -= 5
.
if sx < 0 or sx > 100 or sy < 0 or sy > 100
2025-06-11 20:16:52 -04:00
over
return
2023-07-01 11:58:00 -04:00
.
for i = len sx[] downto 2
if sx = sx[i] and sy = sy[i]
2025-06-11 20:16:52 -04:00
over
return
2023-07-01 11:58:00 -04:00
.
2025-06-11 20:16:52 -04:00
.
gclear
gcolor 997
gtext 2 95 "Score: " & 10 * len sx[] - 50
gcolor 966
gcircle rx ry 1.5
#
gcolor 494
for i = len sx[] downto 2
2023-07-01 11:58:00 -04:00
sx[i] = sx[i - 1]
sy[i] = sy[i - 1]
if sx[i] > 0
2025-06-11 20:16:52 -04:00
gcircle sx[i] sy[i] 2.5
2023-07-01 11:58:00 -04:00
.
.
2025-06-11 20:16:52 -04:00
gcircle sx sy 2.5
gcolor 000
2023-07-01 11:58:00 -04:00
if dir = 2 or dir = 4
2025-06-11 20:16:52 -04:00
gcircle sx sy + 1 0.5
gcircle sx sy - 1 0.5
2023-07-01 11:58:00 -04:00
else
2025-06-11 20:16:52 -04:00
gcircle sx + 1 sy 0.5
gcircle sx - 1 sy 0.5
2023-07-01 11:58:00 -04:00
.
if sx = rx and sy = ry
len sx[] len sx[] + 3
len sy[] len sy[] + 3
2023-09-16 17:28:03 -07:00
fruit
2023-07-01 11:58:00 -04:00
.
2025-06-11 20:16:52 -04:00
sx[1] = sx
sy[1] = sy
timer 0.15
2023-07-01 11:58:00 -04:00
.