Track & display high score.

This commit is contained in:
Colin McMillen 2015-06-07 15:14:41 -04:00
parent d12dcd32fb
commit 485da7fcc6
3 changed files with 45 additions and 1 deletions

View File

@ -5,6 +5,7 @@
; 0014-0016: 24-bit counter of vblanks. ; 0014-0016: 24-bit counter of vblanks.
; 0017-0019: RGB color values to use for background color, from [0-31]. ; 0017-0019: RGB color values to use for background color, from [0-31].
; 001A-001B: 16-bit pointer to next random byte. ; 001A-001B: 16-bit pointer to next random byte.
; 001C-001D: 16-bit high-score.
; [gap] ; [gap]
; 0020-0021: (x, y) coordinates of player. ; 0020-0021: (x, y) coordinates of player.
; 0022: player health. ; 0022: player health.
@ -31,6 +32,7 @@
.define backgroundGreen $18 .define backgroundGreen $18
.define backgroundBlue $19 .define backgroundBlue $19
.define randomBytePtr $1A .define randomBytePtr $1A
.define highScore $1C
.define playerX $20 .define playerX $20
.define playerY $21 .define playerY $21
.define playerHealth $22 .define playerHealth $22

View File

@ -504,6 +504,7 @@ UpdateWorld:
jsr CheckCollisionsWithEnemies jsr CheckCollisionsWithEnemies
jsr UpdateBackgroundScroll jsr UpdateBackgroundScroll
jsr UpdateHighScore
rts rts
@ -959,6 +960,18 @@ UpdateBackgroundScroll:
UpdateHighScore:
SetA16Bit
lda playerScore
cmp highScore
bcc +
sta highScore
+
SetA8Bit
rts
UpdateSprites: ; TODO: refactor into smaller pieces. UpdateSprites: ; TODO: refactor into smaller pieces.
; This page is a good reference on SNES sprite formats: ; This page is a good reference on SNES sprite formats:
; http://wiki.superfamicom.org/snes/show/SNES+Sprites ; http://wiki.superfamicom.org/snes/show/SNES+Sprites
@ -1094,7 +1107,7 @@ UpdateSprites: ; TODO: refactor into smaller pieces.
+ +
; Sprites to show player score. ; Sprites to show player score.
lda #(252 - 7 * 6) lda #76
sta $00 ; x-position sta $00 ; x-position
lda #212 lda #212
sta $01 ; y-position sta $01 ; y-position
@ -1108,6 +1121,35 @@ UpdateSprites: ; TODO: refactor into smaller pieces.
lda #0 lda #0
jsr RenderTwoDigits jsr RenderTwoDigits
; Sprites to show high score.
lda #(252 - 7 * 6)
sta $00
lda #212
sta $01
stz $02
stz $03
lda highScore + 1
jsr RenderTwoDigits
lda highScore
jsr RenderTwoDigits
inc $03 ; Render rightmost zero always.
lda #0
jsr RenderTwoDigits
; The little "HI" sprite next to high-score.
lda #(252 - 7 * 7 - 2)
sta spriteTableStart, X
lda #212
sta spriteTableStart + 1, X
lda #74
sta spriteTableStart + 2, X
; Set priority bits so that the sprite is drawn in front.
lda #%00110000
sta spriteTableStart + 3, X
lda #%01000000 ; Enable small sprite.
sta spriteTableScratchStart, Y
AdvanceSpritePointers
; Now clear out the unused entries in the sprite table. ; Now clear out the unused entries in the sprite table.
- -
cpx #spriteTable1Size cpx #spriteTable1Size

Binary file not shown.