Hi cannot seem to get my high score table working, saving to an external file doesnt see to be workign. Please help
high score table
function high_scores(username$,userscore)
show mouse
name$(11) = username$
score(11) = userscore
ink rgb(0,0,0),0
set dir "h:\Computing\Adv Higher\Project"
open to read 1,"High Scores.txt"
for reading = 1 to 10
read string 1, name$(reading)
read string 1, str$(score(reading))
next reading
delete file "High Scores.txt"
innerloop = 2
For Outer = 1 To 11
For Inner = innerloop To 11
If score(Outer) < score(Inner)
Temp = score(Outer)
temp$ = name$(outer)
score(Outer) = score(Inner)
name$(outer) = name$(inner)
score(Inner) = Temp
name$(inner) = temp$
EndIf
Next Inner
Next Outer
y1=200
paste image 25,1,1
for printing = 1 to 10
text 130,y1,name$(printing)
text 700,y1,str$(score(printing))
y1 = y1 + 75
next printing
sync
delete file "High Scores.txt"
close file 1
open to write 2,"High Scores.txt"
for write = 1 to 10
write string 2,name$(write)
write string 2,str$(score(write))
next write
close file 2
wait key
if end_counter = 1 then end
menu()
endfunction
full game
set display mode 1000,1000,16
backdrop on
sync on : sync rate 60
load image "h:\My Pictures\highscoretable.png",25
load image "h:\My Pictures\spikes.png",31
load image "h:\My Pictures\High_scores.png",23
load image "h:\My Pictures\High_scores1.png",24
load image "h:\My Pictures\Exit Game1.png",14
load image "h:\My Pictures\Instructions1.png",13
load image "h:\My Pictures\New Game1.png",12
load image "h:\My Pictures\instructions screen.png",11
load image "h:\My Pictures\New Game.png",4
load image "h:\My Pictures\Instructions.png",5
load image "h:\My Pictures\front screen.png",10
load image "h:\My Pictures\Exit Game.png",6
load image "h:\My Pictures\green_monster.png",9
load image "h:\My Pictures\coin.png",20
load image "h:\My Pictures\block6.png",30
load image "h:\My Pictures\land here.png",32
load music "h:\Computing\Adv Higher\Project\Finding Movement.mp3",1
load sound "h:\Computing\Adv Higher\Project\happy alley.wav",2
dim name$(11)
dim score(11)
set text size 50
SET TEXT FONT "balloonist SF"
ink rgb (0,255,0),0
menu()
New_game:
input "Enter your name: ",username$
hide mouse
stop sound 2
coinflag = 1
coin2flag = 1
coin3flag = 1
coin4flag = 1
coin5flag = 1
coin6flag = 1
set text size 30
color backdrop rgb (255,255,255)
play music 1
load image "h:\My Pictures\block 5.png",26
load image "h:\My Pictures\block4.png",22
load image "h:\My Pictures\block 3.png",21
load image "h:\My Pictures\block 1.png",7
load image "h:\My Pictures\block 2.png",8
load image "h:\My Pictures\ball.png",1
lives = 3
block1x=0
block1y=388
block2x=700
block2y=633
block3x=1700
block3y=500
block4x= 2500
block4y=800
block5x= 3000
block5y=700
block6x=3100
block6y=600
block7x=3200
block7y=500
block8x=3200
block8y=400
block9x=3300
block9y=600
block10x=3600
block10y=950
block11x=4200
block11y=950
ballx =20
bally=100
monster1x=900
monster1y=525
monster2x=2000
monster2y=385
coin1x= 500
coin2x= 1000
coin3x= 1030
coin4x= 2550
coin5x=2575
coin6x=2600
time = 3000
airflag = 1
do
do
paste image 31,block10x,750
paste image 31,block11x,750
paste image 32,(block10x+300),550
airflag = 1
if coin6flag = 1
sprite 12,coin6x,670,20
endif
if coin5flag = 1
sprite 11,coin5x,645,20
endif
if coin4flag = 1
sprite 10,coin4x,620,20
endif
sprite 9,block4x,block4y,22
if coin3flag = 1
sprite 8,coin3x,608,20
endif
sprite 7,block3x,block3y,21
if coinflag = 1
sprite 5,coin1x,200,20
endif
if coin2flag = 1
sprite 6,coin2x,608,20
endif
sprite 13,monster2x,monster2y,9
sprite 22,block11x,block11y,30
sprite 21,block10x,block10y,30
sprite 18,block9x,block9y,26
sprite 17,block8x,block8y,26
sprite 16,block7x,block7y,26
sprite 14,block5x,block5y,26
sprite 15,block6x,block6y,26
sprite 4,monster1x,monster1y,9
sprite 3,block2x,block2y,8
sprite 2,block1x,block1y,7
sprite 1,ballx,bally,1
if rightkey()= 1
coin1x = coin1x - 4
coin2x = coin2x - 4
coin3x = coin3x - 4
coin4x = coin4x - 4
coin5x = coin5x - 4
coin6x = coin6x - 4
block1x = block1x-4
block2x = block2x-4
block3x = block3x-4
block4x = block4x-4
block5x = block5x-4
block6x = block6x-4
block7x = block7x - 4
block8x = block8x - 4
block9x = block9x - 4
block10x = block10x - 4
block11x = block11x - 4
monster1x = monster1x-4
monster2x = monster2x - 4
endif
if sprite collision (1,20) = 1
lives = lives - 1
goto new_start
endif
if sprite collision (1,13) = 1
lives = lives - 1
goto new_start
endif
if sprite collision (1,12) =1
delete sprite 12
coins = coins + 1
coin6flag = 0
endif
if sprite collision (1,11) =1
delete sprite 11
coins = coins + 1
coin5flag = 0
endif
if sprite collision (1,10) =1
delete sprite 10
coins = coins + 1
coin4flag = 0
endif
if sprite collision (1,8) =1
delete sprite 8
coins = coins + 1
coin3flag = 0
endif
if sprite collision (1,6) = 1
delete sprite 6
coins = coins + 1
coin2flag = 0
endif
if sprite collision (1,5) = 1
delete sprite 5
coins = coins + 1
coinflag = 0
endif
if sprite collision (1,4) = 1
lives = lives - 1
goto new_start
endif
if sprite collision(1,2) = 1 and bally < block1y
if (bally+4) > (block1y-19) then bally = block1y-19
airflag = 0
endif
if sprite collision(1,14) = 1 and bally < block5y
if (bally+4) > (block5y-19) then bally = block5y-19
airflag = 0
endif
if sprite collision(1,15) = 1 and bally < block6y
if (bally+4) > (block6y-19) then bally = block6y-19
airflag = 0
endif
if sprite collision(1,21) = 1 and bally < block10y
if (bally+4) > (block10y-19) then bally = block10y-19
lives = lives - 1
goto new_start
airflag = 0
endif
if sprite collision(1,22) = 1 and bally < block11y
if (bally+4) > (block11y-19) then bally = block11y-19
lives = lives - 1
goto new_start
airflag = 0
endif
if sprite collision(1,16) = 1 and bally < block7y
if (bally+4) > (block7y-19) then bally = block7y-19
airflag = 0
endif
if sprite collision(1,17) = 1 and bally < block8y
if (bally+4) > (block8y-19) then bally = block8y-19
airflag = 0
endif
if sprite collision(1,18) = 1 and bally < block9y
if (bally+4) > (block9y-19) then bally = block9y-19
airflag = 0
endif
if sprite collision (1,3) = 1 and block2x = 100
ballx = block2x
airflag = 0
endif
if ballx => block2x and bally => block2y and ballx <= block2x
ballx = block2x - 19
airflag = 1
endif
if ballx => block3x and bally => block3y and ballx <= block3x
ballx = block3x - 19
airflag = 1
endif
if sprite collision(1,3) = 1 and bally < block2y
if (bally+4) > (block2y-19)
bally = block2y-19
endif
airflag = 0
endif
if sprite collision(1,7) = 1 and bally < block3y
if (bally+4) > (block3y-19) then bally = block3y-19
airflag = 0
endif
if sprite collision(1,9) = 1 and bally < block4y
if (bally+4) > (block4y-19) then bally = block4y-19
airflag = 0
endif
bally = bally + 4
`jumping
if upkey()= 1 and jumpflag = 0 and airflag = 0
jumpflag = 1
jumptimer = 70
endif
if jumpflag = 1
airflag = 1
if jumptimer > 25
bally = bally - 10
endif
endif
jumptimer = jumptimer - .1
if jumptimer = 0 then jumpflag = 0
`end jumping
if bally > 1000
if ballx < block11x and ballx > (block10x + 500)
ink rgb(0,0,0),0
text 250,500,"CONGRATULATIONS, YOU HAVE PASSED THE FIRST TEST . . . "
sync
wait key
end_counter = 1
high_scores(username$,userscore)
endif
lives = lives - 1
goto new_start
endif
text 800,0,"Coins:"
text 870,0,"$"+str$(coins)
text 0,0,"Lives:"
text 70,0,str$(lives)
text 450,0,"Time:"
text 520,0,str$(time)
score = (lives * 1000) + (coins * 100)
userscore = score + time
text 250,0,"Score: "
text 330,0,str$(score)
monster1x = monster1x - 1
if monster1x < (block2x - 135)
monster1y = monster1y + 4
endif
time = time - 1
if time = 0
delete sprite 1
delete sprite 2
delete sprite 3
delete sprite 4
delete sprite 5
delete sprite 6
delete sprite 7
delete sprite 8
delete sprite 9
delete sprite 10
delete sprite 11
delete sprite 12
delete sprite 13
delete sprite 14
delete sprite 15
delete sprite 16
delete sprite 17
delete sprite 18
delete sprite 21
delete sprite 22
end_counter = 1
high_scores(username$,userscore)
endif
sync
loop
new_start:
if flag = 1
sprite 5,coinx,200,20
endif
if lives = 0
delete sprite 1
delete sprite 2
delete sprite 3
delete sprite 4
delete sprite 5
delete sprite 6
delete sprite 7
delete sprite 8
delete sprite 9
delete sprite 10
delete sprite 11
delete sprite 12
delete sprite 13
delete sprite 14
delete sprite 15
delete sprite 16
delete sprite 17
delete sprite 18
delete sprite 21
delete sprite 22
end_counter = 1
high_scores(username$,userscore)
endif
` Resetting all the variables.
coin1x = 500
coin2x= 1000
coin3x= 1030
coin4x= 2550
coin5x=2575
coin6x=2600
block1x=0
block1y=388
block2x=700
block2y=633
block3x=1700
block3y=500
block4x= 2500
block4y=800
block5x= 3000
block5y=700
block6x=3100
block6y=600
block7x=3200
block7y=500
block8x=3200
block8y=400
block9x=3300
block9y=500
block10x=3600
block10y=950
block11x=4200
block11y=950
ballx=100
bally=100
monster1x=800
monster1y=525
monster2x=2000
monster2y=385
` End resetting all the variables.
loop
function high_scores(username$,userscore)
show mouse
name$(11) = username$
score(11) = userscore
ink rgb(0,0,0),0
set dir "h:\Computing\Adv Higher\Project"
open to read 1,"High Scores.txt"
for reading = 1 to 10
read string 1, name$(reading)
read string 1, str$(score(reading))
next reading
delete file "High Scores.txt"
innerloop = 2
For Outer = 1 To 11
For Inner = innerloop To 11
If score(Outer) < score(Inner)
Temp = score(Outer)
temp$ = name$(outer)
score(Outer) = score(Inner)
name$(outer) = name$(inner)
score(Inner) = Temp
name$(inner) = temp$
EndIf
Next Inner
Next Outer
y1=200
paste image 25,1,1
for printing = 1 to 10
text 130,y1,name$(printing)
text 700,y1,str$(score(printing))
y1 = y1 + 75
next printing
sync
delete file "High Scores.txt"
close file 1
open to write 2,"High Scores.txt"
for write = 1 to 10
write string 2,name$(write)
write string 2,str$(score(write))
next write
close file 2
wait key
if end_counter = 1 then end
menu()
endfunction
function Menu()
play sound 2
do
paste image 10,1,1
paste image 4,339,200
paste image 5,339,400
paste image 6,339,600
paste image 23,339,800
if mousex() > 339 and mousex() < 661
if mousey() > 200 and mousey() < 307
paste image 12,339,200
if mouseclick() = 1
goto new_game
stop music 2
endif
endif
endif
if mousex() > 339 and mousex() < 661
if mousey() > 400 and mousey() < 507
paste image 13,339,400
if mouseclick() = 1
Instructions()
endif
endif
endif
if mousex() > 339 and mousex() < 661
if mousey() > 600 and mousey() < 707
paste image 14,339,600
if mouseclick() = 1 then end
endif
endif
if mousex() > 339 and mousex() < 661
if mousey() > 800 and mousey() < 907
paste image 24,339,800
if mouseclick() = 1
high_scores(username$,userscore)
endif
endif
endif
sync
loop
endfunction
function Instructions()
color backdrop rgb(255,0,0)
do
text 250, 50, "Instructions"
text 150, 150, "Press the right arrow key to move right."
text 150, 250, "Press the up arrow key to jump."
text 150,350, "Avoid all enemies."
text 150,450, "Collect as many coins as you can."
text 150,550, "Don't fall off the screen."
text 150,800, "Click to return to the menu."
if mouseclick() = 1 then Menu()
sync
loop
endfunction
Thanks, and goodnight.