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\food.png",5
Load Image "background\background.png",6
`variables
score = 0
snakex = 400
snakey = 300
lives = 3
sprite 2,rnd(700),rnd(600),5
Do
paste image 6,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:
`move left
if leftkey()=1
snakex = snakex - 1
sprite 1,snakex,snakey,1
endif
`move right
if rightkey()=1
snakex = snakex + 1
sprite 1,snakex,snakey,3
endif
`move down
if downkey()=1
snakey = snakey + 1
sprite 1,snakex,snakey,4
endif
`move up
if upkey()=1
snakey = snakey - 1
sprite 1,snakex,snakey,2
endif
return
`edgescreen
edgescreen:
if snakex>800 then snakex = 400 : sprite 1,snakex,snakey,1 : lives = lives - 1
if snakex<0 then snakex = 400 : sprite 1,snakex,snakey,1 : lives = lives - 1
if snakey>600 then snakey = 300 : sprite 1,snakex,snakey,1 : lives = lives - 1
if snakey<0 then snakey = 300 : sprite 1,snakex,snakey,1 : lives = lives - 1
return
`food
food:
if sprite exist(2)=0 then sprite 2,rnd(600),rnd(550),5
return
`collision
collision:
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 : center text 400,300,"YOU HAVE WON!"
return
`lose
lose:
if lives=<0 then goto loses
return
`loses
loses:
cls
center text 400,300,"YOU HAVE LOST!"
wait key
This code works but when i eat the food 6 time it does not reapear any help? please this is really annoying and the code has been updated for a few changes. please help.
just code