Keeping Score: Easy Peasy
This tutorial is for everybody who wants to throw some sort of score in their game, but doesn't have the time to tailor something special. They just need a score, somehow someway, and something generic will work. By doing exactly what is described in this tutorial, you can get a 4-digit score from 0000 to 9999 printed and updated at the beginning of the bottom line of the screen. It's easy. It's peasy. It's got your name all over it. Let's get started:
Assumptions
For this easy generic score stuff, we assume:
- your background tiles are at _SCRN0 ($9800)
- you aren't already using a window
- you have loaded in the ASCII tile set
Example Code
see hello-score.asm
Implementation
Initialization
add
INCLUDE "easyScore.asm"
to your main code after a SECTION heading. A good place is right before or right after memory.asm
look for the line in the initialization area of your code that looks something like:
ld a, LCDCF_ON|LCDCF_BG8000|LCDCF_BG9800|LCDCF_BGON|LCDCF_OBJ16|LCDCF_OBJOFF
and append
|LCDCF_WIN9C00|LCDCF_WINON
to it.somewhere after the above line and before your main loop, add a call to the score initilization routine:
call easyScoreInit
Usage
whenever you want to raise the score, load a with the amount you wish to raise the score by and call easyScoreRaise. For example, to raise the score by 1:
ld a,1 ; raise score by this amount call easyScoreRaise
whenever you want to lower the score, load a with the amount you wish to lower the score by and call easyScoreDrop. For example, to lower the score by 1:
ld a,1 ; lower score by this amount call easyScoreDrop
to reset the score to 0, call easyScoreReset:
call z,easyScoreReset
to set the score to any BCD number, load hl with the BCD number and call easyScoreSet:
ld hl,$4000 ; choose any BCD number between 0 and $9999 call easyScoreSet