RosettaCodeData/Task/Snake/EasyLang/snake.easy

124 lines
1.9 KiB
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
subr fruit
2024-03-06 22:25:12 -08:00
rx = (randint 20 - 1) * 5 + 2.5
ry = (randint 20 - 1) * 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 ]
2024-03-06 22:25:12 -08:00
dir = randint 4
2023-07-01 11:58:00 -04:00
timer 0
.
background 242
move 30 70
clear
color 997
text "SNAKE"
textsize 5
2023-10-02 18:11:16 -07:00
move 6 40
text "Keys or mouse for controlling"
move 6 30
text "Space or click to to start"
2023-07-01 11:58:00 -04:00
#
on key
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
.
.
on timer
clear
color 997
2023-10-02 18:11:16 -07:00
move 2 95
2023-07-01 11:58:00 -04:00
text "Score: " & 10 * len sx[] - 50
color 966
move rx ry
circle 1.5
#
sx = sx[1] ; sy = sy[1]
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
game = 0
.
color 494
for i = len sx[] downto 2
if sx = sx[i] and sy = sy[i]
game = 0
.
sx[i] = sx[i - 1]
sy[i] = sy[i - 1]
if sx[i] > 0
move sx[i] sy[i]
circle 2.5
.
.
move sx sy
circle 2.5
color 000
if dir = 2 or dir = 4
move sx sy + 1
circle 0.5
move sx sy - 1
circle 0.5
else
move sx + 1 sy
circle 0.5
move sx - 1 sy
circle 0.5
.
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
.
sx[1] = sx ; sy[1] = sy
if game = 1
timer 0.15
else
color 997
move 10 10
2023-10-02 18:11:16 -07:00
text "Space or click new game"
2023-07-01 11:58:00 -04:00
.
.