Rem Project: snake2
Rem Created: 08/01/2006 12:41:28
INPUT "Please enter your name";new_name$
GOSUB read_high_score
RANDOMIZE TIMER()
load sound "beep.wav",1
load sound "boink.wav",2
snakelength=1
DIM snakebody_across(35)
DIM snakebody_down(35)
score=0
image=3
hide mouse
across= 210
down= 210
set current bitmap 0
rem load BITMAP "Background.bmp",0
Load BITMAP "Snake head.bmp",1
GET IMAGE 1,3,3,30,30
load BITMAP "snake head down.bmp",2
GET IMAGE 2,3,3,29,30
load BITMAP "snake head right.bmp",3
GET IMAGE 3,3,3,30,30
load BITMAP "snake head left.bmp",4
GET IMAGE 4,3,3,30,30
load BITMAP "snake body.bmp",5
GET IMAGE 5,1,1,30,28
load BITMAP "food.bmp",40
GET IMAGE 40,1,1,30,28
set current bitmap 0
gosub foodsub
Xchange=0
change=0
game_over=0
repeat
spritenum=1
sprite 1,across,down,image
sprite 2,across,down,image
sprite 3,across,down,image
sprite 4,across,down,image
rem reads keyboard for direction
rem left head
IF INKEY$()=CHR$(122) AND image<>3
Xchange=-30
Change=0
image =4
spritenum=4
ENDIF
rem up head
IF INKEY$()=CHR$(39) AND image<>2
change=-30
Xchange=0
image=1
spritenum=1
ENDIF
rem right head
IF INKEY$()=CHR$(120) AND image<>4
Xchange=+30
change=0
image=3
spritenum=3
ENDIF
rem down head
IF INKEY$()=CHR$(47) AND image <>1
change=+30
Xchange=0
image=2
spritenum=2
ENDIF
if across<0 then across =0
if down <0 then down = 0
if across > 600 then across=600
if down >450 then down = 450
sprite spritenum,across,down,image
snakebody_across(1)=across
snakebody_down(1)=down
GOSUB hit
FOR LOOP=2 to snakelength step+1
sprite loop+3,snakebody_across(loop),snakebody_down(loop),5
NEXT LOOP
FOR loop=snakelength to 2 step-1
snakebody_across(loop)=snakebody_across(loop-1)
snakebody_down(loop)=snakebody_down(loop-1)
NEXT LOOP
remstart
IF across>10 AND across <570
ENDIF
IF down>60 AND down <400
ENDIF
remend
across=across+xchange
down=down+change
wait 100
until game_over=1
rem END
hit:
FOR LOOP2 = 5 to 35
IF SPRITE HIT(SPRITENUM,loop2) >0
play sound 1
GOSUB deaded
ENDIF
NEXT LOOP2
IF SPRITE HIT(SPRITENUM,40) >0
Gosub foodsub
score=score+100
snakelength=snakelength+1
snakebody_across(snakelength)=900
snakebody_down(snakelength)=900
ENDIF
RETURN
foodsub:
repeat
flag=1
foodx=RND(20)*30
foody=RND(15)*30
gosub flagcheck
until flag = 1
SPRITE 40,foodx,foody,40
play sound 1
RETURN
deaded:
Create bitmap 1,640,480
set cursor 0,0
PRINT "You have snuffed it"
PRINT "score is "; score
copy bitmap 1,0
PRINT "MOOSE"
wait key
GOSUB Compare_score
copy bitmap 1,0
wait key
Game_over=1
RETURN
flagcheck:
FOR loop3= 1 to snakelength
IF foodx=snakebody_across(loop3) or foody=snakebody_down(loop3)
flag=0
ENDIF
NEXT loop3
RETURN
read_high_score:
DIM name$(10)
DIM score$(10)
IF FILE EXIST ("HighScore")=0
PRINT "High Score table not found, press any key for one to be created"
WAIT KEY
GOSUB create
ENDIF
OPEN TO READ 1,"HighScore"
FOR Loop2 = 1 to 10
READ STRING 1,name$
READ STRING 1,score$
name$(loop2)=name$
score$(loop2)=score$
NEXT loop2
CLOSE FILE 1
FOR Loop3 = 1 to 10
PRINT name$(loop3)," ";score$(loop3)
NEXT Loop3
WAIT KEY
RETURN
CREATE:
FOR LOOP= 1 to 10
READ name$,score$
NAME$(loop)=name$
SCORE$(loop)=score$
NEXT loop
DATA "BOB","4000","Steve","3500","David","5","Tam","200","Joe","2"
DATA "Jill","3000","Ben","2000","Mike","5500","Christy","5000","Kev","5000"
GOSUB sort
OPEN TO WRITE 1,"HighScore"
FOR loop1 = 1 to 10
name$=name$(loop1)
score$=score$(loop1)
WRITE STRING 1,name$
WRITE STRING 1,score$
next loop1
CLOSE FILE 1
RETURN
Sort:
FOR counter1 = 1 to 10
FOR counter2 = 1 to 10-counter1
IF VAL (score$(counter2))<VAL (score$(counter2+1))
temp$=score$(counter2)
score$(counter2)=score$(counter2+1)
score$(counter2+1)=temp$
temp$=name$(counter2)
name$(counter2)=name$(counter2+1)
name$(counter2+1)=temp$
ENDIF
NEXT counter2
NEXT counter1
RETURN
compare_score:
new_score$=str$(score)
IF VAL (new_score$)> VAL (score$(10))
play sound 2
PRINT "well done - new high score"
PRINT "Writing new high score..."
copy bitmap 1,0
score$(10)=new_score$
name$(10)= new_name$
GOSUB sort
GOSUB update_high_score
ENDIF
RETURN
update_high_score:
IF FILE EXIST("HighScore")=1
DELETE FILE "HighScore"
ENDIF
OPEN TO WRITE 1,"HighScore"
FOR loop1 = 1 to 10
name$=name$(loop1)
score$=score$(loop1)
WRITE STRING 1,name$
WRITE STRING 1,score$
next loop1
CLOSE FILE 1
RETURN
ok, hope that works, should be code. I havent got a sync in anywhere at the moment, when i had one it seems to solve the problem of it not loading my background, but also causes the programme to just stop when it hits the sync on command... :S
The meaning of life. Sometimes its a chicken. Sometimes its a chair. Sometimes its a peice of cheese, suspended in the air.