Long version:
sync on : set display mode 64,48,16
type xy
x as integer
y as integer
endtype
global dim snake(2) as xy
global dim mouse(10) as xy
global xd as integer
global yd as integer
global ox as integer
global oy as integer
global dotx as integer
global doty as integer
global time as word
global dv as word
global score as dword
global spawn as byte
time = 5000
dv = 49
xd = 1
ink rgb(50,50,50),0
set text font "Arial"
set text size 45
load sound "Bleep.wav",1
load sound "Munch.wav",2
do
dots()
ox = xd
oy = yd
while timer() < start+(time/dv)
control()
endwhile
start = timer()
move()
spawn()
render()
sync
cls 0
center text screen width()/2,2,str$(score)
loop
function render()
for d = 0 to array count(snake(0))
dot snake(d).x,snake(d).y,rgb(255,255,0)
next d
endfunction
function move()
for d = array count(snake(0)) to 1 step -1
snake(d) = snake(d-1)
next d
snake(0).x = snake(0).x+xd
snake(0).y = snake(0).y+yd
for d = 1 to array count(snake(0))
if snake(0).x = snake(d).x and snake(0).y = snake(d).y
exit prompt "You scored "+str$(score)+" points!","You lose"
end
endif
next d
if snake(0).x < 0 then snake(0).x = screen width()-1
if snake(0).y < 0 then snake(0).y = screen height()-1
if snake(0).x >= screen width() then snake(0).x = 0
if snake(0).y >= screen height() then snake(0).y = 0
endfunction
function control()
xd = rightkey()-leftkey()
yd = downkey()-upkey()
if xd <> 0 and yd <> 0 then yd = 0
if xd = 0 and yd = 0 then xd = ox : yd = oy
if xd = 0-ox then xd = ox
if yd = 0-oy then yd = oy
endfunction
function dots()
dot dotx,doty,rgb(0,255,255)
if snake(0).x = dotx and snake(0).y = doty
array insert at bottom snake(0)
dotx = rnd(screen width()-1)
doty = rnd(screen height()-1)
inc dv
inc score,1
play sound 2
endif
endfunction
function spawn()
if spawn > 0
dec spawn
for d = 0 to array count(mouse(0))
if snake(0).x = mouse(d).x and snake(0).y = mouse(d).y
inc score,spawn
spawn = 0
play sound 1
else
dot mouse(d).x,mouse(d).y,rgb((spawn*4)+15,0,(spawn*4)+15)
endif
next d
else
if rnd(200) = 1
spawn = 60
mouse(0).x = rnd(screen width()-1)
mouse(0).y = rnd(screen height()-1)
for d = 1 to array count(mouse(0))
get_free_space(d)
next d
endif
endif
endfunction
function get_free_space(d)
f = 1
while f = 1
f = 0
p = rnd(d-1)
x = rnd(2)-1
y = rnd(2)-1
nx = mouse(p).x+x
ny = mouse(p).y+y
for a = 0 to d-1
if nx = mouse(a).x and ny = mouse(a).y
f = 1
endif
if nx >= screen width() or nx < 0 or ny >= screen height() or ny < 0
f = 1
endif
next a
endwhile
mouse(d).x = nx
mouse(d).y = ny
endfunction
15 lines:
sync on : set display mode 64,48,16
type xy x as integer, y as integer endtype
global dim snake(2) as xy : global dim mouse(10) as xy : global xd as integer : global yd as integer : global ox as integer : global oy as integer : global dotx as integer : global doty as integer : global time as word : global dv as word : global score as dword : global spawn as byte
time = 5000 : dv = 49 : xd = 1 : ink rgb(50,50,50),0 : set text font "Arial" : set text size 45 : load sound "Bleep.wav",1 : load sound "Munch.wav",2
do : dots() : ox = xd : oy = yd : while timer() < start+(time/dv) : control() : endwhile : start = timer() : move() : spawn() : render() : sync : cls 0 : center text screen width()/2,2,str$(score) : loop
function render() : for d = 0 to array count(snake(0)) : dot snake(d).x,snake(d).y,rgb(255,255,0) : next d
endfunction : function move() : for d = array count(snake(0)) to 1 step -1 : snake(d) = snake(d-1) : next d : snake(0).x = snake(0).x+xd : snake(0).y = snake(0).y+yd : for d = 1 to array count(snake(0)) : if snake(0).x = snake(d).x and snake(0).y = snake(d).y : exit prompt "You scored "+str$(score)+" points!","You lose" : end : endif : next d : if snake(0).x < 0 : snake(0).x = screen width()-1 : endif : if snake(0).y < 0 : snake(0).y = screen height()-1 : endif : if snake(0).x >= screen width() : snake(0).x = 0 : endif : if snake(0).y >= screen height() : snake(0).y = 0 : endif
endfunction : function control() : xd = rightkey()-leftkey() : yd = downkey()-upkey() : if xd <> 0 and yd <> 0 : yd = 0 : endif : if xd = 0 and yd = 0 : xd = ox : yd = oy : endif : if xd = 0-ox : xd = ox : endif : if yd = 0-oy : yd = oy : endif
endfunction : function dots() : dot dotx,doty,rgb(0,255,255) : if snake(0).x = dotx and snake(0).y = doty : array insert at bottom snake(0) : dotx = rnd(screen width()-1) : doty = rnd(screen height()-1) : inc dv : inc score,1 : play sound 2 : endif
endfunction : function spawn() : if spawn > 0 : dec spawn : for d = 0 to array count(mouse(0)) : if snake(0).x = mouse(d).x and snake(0).y = mouse(d).y : inc score,spawn : spawn = 0 : play sound 1 : else : dot mouse(d).x,mouse(d).y,rgb((spawn*4)+15,0,(spawn*4)+15) : endif : next d : else : if rnd(200) = 1 : spawn = 60 : mouse(0).x = rnd(screen width()-1) : mouse(0).y = rnd(screen height()-1) : for d = 1 to array count(mouse(0)) : get_free_space(d) : next d : endif : endif
endfunction : function get_free_space(d) : f = 1 : while f = 1 : f = 0 : p = rnd(d-1) : x = rnd(2)-1 : y = rnd(2)-1 : nx = mouse(p).x+x : ny = mouse(p).y+y : for a = 0 to d-1 : if nx = mouse(a).x and ny = mouse(a).y : f = 1 : endif : if nx >= screen width() or nx < 0 or ny >= screen height() or ny < 0 : f = 1 : endif : next a : endwhile : mouse(d).x = nx : mouse(d).y = ny
endfunction
Uses two sound files, but they are not essential to play.
They are attached