Adding A Score
Click here to load the completed tutorial directly into the editor
SWARM-25.DBA. If you want to step through and make the modifications, click here to load SWARM-24.DBA.
We have added the elements that provide the playability, but now we need to implement lastability. To this end, we shall add a score and hiscore to our mini-epic shooter.
Replace the line REM * HERE D * to read:
rem Add to score
inc score,100
Replace the line REM * HERE C * to read:
rem Display score and hiscore
center text 80,2,str$(score)
center text 560,2,str$(hiscore)
Inside the _control_aliens subroutine, we score 100 points whenever our bullet destroys an alien. The second addition makes sure we see our score and hiscore on the screen.
Replace the line REM * HERE A * to read:
rem If new hiscore
if score>hiscore
hiscore=score : s$="NEW HISCORE!"
endif
Replace the line REM * HERE B * to read:
rem Reset score
score=0
At the end of the game, we check whether the score value is greater than the current hiscore value. If this is the case we can assign a new hiscore value and change the message stored in S$ to "NEW HISCORE!". In order to reset the game fully, we then set the score value back to zero for the new game.
Click Here For The Next Tutorial
Adding Sound and Music.