Rem Project: Snake
Rem Created: 01/02/2004 16:14:28
Rem ***** Main Source File *****
Set Display Mode 800,600,32
hide mouse
`load image
Load Image "snake\headleft.png",1
Load Image "snake\headup.png",2
Load Image "snake\headright.png",3
Load Image "snake\headdown.png",4
Load Image "snake\segment.png",5
Load Image "snake\food.png",6
Load Image "background\background.png",7
`variables
direction as string : `direction snake is traveling in, L,R,U,D
direction = "L"
score = 0
snakex = 400
snakey = 300
lives = 3
seg_num as integer
last_move as integer : `timer value of last snake move
last_move = timer()
speed as integer : `delay between moves
speed = 300 : `move every half second
sprite 2,rnd(700),rnd(550),6
Do
paste image 7,0,0
gosub lives
gosub score
gosub snake
gosub move
gosub edgescreen
gosub food
gosub collision
gosub won
gosub lose
loop
`lives
lives:
text 600,10,"Lives left: " + str$(lives)
return
`score
score:
set text size 16
text 10,10,"Score: " + str$(score)
return
`snake
snake:
sprite 1,snakex,snakey,1
return
`move
move:
if upkey()=1 then direction = "U"
if downkey()=1 then direction = "D"
if leftkey()=1 then direction = "L"
if rightkey()=1 then direction = "R"
if direction = "R" then snakex=snakex+1 : sprite 1,snakex,snakey,3
if direction = "L" then snakex=snakex-1 : sprite 1,snakex,snakey,1
if direction = "U" then snakey=snakey-1 : sprite 1,snakex,snakey,2
if direction = "D" then snakey=snakey+1 : sprite 1,snakex,snakey,4
if seg_num > 1
for i = seg_num to 2 step -1
sprite i,sprite x(i-1),sprite y(i-1),5
next i
endif
if spacekey() and seg_wait = 0 then inc seg_wait
return
`edgescreen
edgescreen:
if snakex>800 then snakex = 400 : sprite 1,snakex,snakey,1 : lives = lives - 1 : direction = "L"
if snakex<0 then snakex = 400 : sprite 1,snakex,snakey,1 : lives = lives - 1 : direction = "L"
if snakey>600 then snakey = 300 : sprite 1,snakex,snakey,1 : lives = lives - 1 : direction = "L"
if snakey<0 then snakey = 300 : sprite 1,snakex,snakey,1 : lives = lives - 1 : direction = "L"
return
`food
food:
if sprite exist(2)=0 then sprite 2,rnd(600),rnd(550),6
return
`collision
collision:
if sprite visible(1)=1 and sprite exist(2)=1 and sprite collision(1,2)=1 and seg_wait = 0 then inc seg_wait
if sprite visible(1)=1 and sprite exist(2)=1 and sprite collision(1,2)=1
delete sprite 2
score = score + 10
endif
return
`won
won:
if score = 1000 then cls : goto wons
return
`lose
lose:
if lives=<0 then goto loses
return
`loses
loses:
cls
center text 400,300,"YOU HAVE LOST!"
wait mouse
`wons
wons:
cls
center text 400,300,"YOU HAVE WON!"
wait mouse
This is my code i've added the bit that make the snake grow when it eats food but nothing happens. any help?