Jump to content

Snake: Difference between revisions

1,737 bytes added ,  11 months ago
m (→‎{{header|Rust}}: cosmetic)
Line 2,286:
OnCreate = FormCreate
end
</syntaxhighlight>
 
=={{header|EasyLang}}==
[https://easylang.dev/apps/_snake.html Run it]
{{Trans|Craft Basic}}
<syntaxhighlight lang="easylang">
subr fruit
rx = (random 20 - 1) * 5 + 2.5
ry = (random 20 - 1) * 5 + 2.5
.
subr start
call fruit
game = 1
sx[] = [ 52.5 0 0 0 0 ]
sy[] = [ 52.5 0 0 0 0 ]
dir = random 4
timer 0
.
call start
background 242
textsize 5
#
on key
if keybkey = "ArrowUp" and dir <> 3
dir = 1
elif keybkey = "ArrowRight" and dir <> 4
dir = 2
elif keybkey = "ArrowDown" and dir <> 1
dir = 3
elif keybkey = "ArrowLeft" and dir <> 2
dir = 4
elif keybkey = " " and game = 0
call start
.
.
on timer
clear
color 997
move 2 96
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
call fruit
.
sx[1] = sx ; sy[1] = sy
if game = 1
timer 0.15
else
color 997
move 10 10
text "Press space for new game"
.
.
</syntaxhighlight>
 
2,063

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.