diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-25 07:53:05 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-25 07:53:05 +0100 |
commit | fe0e86d475b825d855e58662bef3bcedab5eab60 (patch) | |
tree | 3faeb53ac97e31d4942db1289eea2bc7750fcce3 /game/main.asm | |
parent | 3ed9e71f143000262dd1b57a8abac9c86af455ea (diff) | |
download | tr8vm-fe0e86d475b825d855e58662bef3bcedab5eab60.tar.gz tr8vm-fe0e86d475b825d855e58662bef3bcedab5eab60.zip |
Add score to the HUD
- add points to the score
- hiscore updates
Diffstat (limited to 'game/main.asm')
-rw-r--r-- | game/main.asm | 149 |
1 files changed, 140 insertions, 9 deletions
diff --git a/game/main.asm b/game/main.asm index 87e2f97..253c812 100644 --- a/game/main.asm +++ b/game/main.asm @@ -49,6 +49,46 @@ game_loop: bnz jmp game_loop + ; see if the hiscore needs updating + + ; 6 digits to compare + ld y, 6 + push y + + ld x, <score + ld a, >score + ld y, <hiscore + ld b, >hiscore +update_hiscore_loop: + cmpi + bc + jmp update_no_hiscore + bnz + jmp update_new_hiscore + + push y + ld y, [sp + 1] + dec y + ld [sp + 1], y + pop y + bno + jmp update_hiscore_loop + +update_new_hiscore: + ; new hiscore! + ld x, <score + ld a, >score + ld y, <hiscore + ld b, >hiscore + ldi + ldi + ldi + ldi + ldi + ldi + +update_no_hiscore: + pop y jmp menu ; @@ -70,15 +110,18 @@ init_game: ld [a : x], y ; clear score - ld x, <score - ld a, >score - ld y, 6 - ld b, 0 -init_score_loop: - ld [a : x], b - dec y - bnz - jmp init_score_loop + ld y, <score + ld b, >score + ; this is all zeroes that we use + ; to erase things on screen etc + ld x, 0 + ld a, 0xa0 + ldi + ldi + ldi + ldi + ldi + ldi halt @@ -87,7 +130,53 @@ init_score_loop: ret +; +; Update the HUD (score, lives, etc) +; update_hud: + ; erase + + ; settings mode + ld y, 128 + ld b, 0xb0 + port b, y + + ; setup + inc b + + ; addr: bg data + ld y, 0 + port b, y + ld y, 0xa0 + port b, y + + ; x + inc x + bo + inc a + ld y, 100 + port b, y + + ; y + inc x + bo + inc a + ld y, 4 + port b, y + + ; w + ld y, 25 + port b, y + ; h + ld y, 8 + port b, y + + ; blit + dec b + ; write, no transparent + ld y, 1 + port b, y + ; 6 digits ld x, 6 push x @@ -105,6 +194,48 @@ update_hud: ret ; +; Add points to the score +; +; in: y points (1 to 10) +add_score: + ; update score + ld x, <score + ld a, >score + add x, 5 + bo + inc a + + ld b, 6 +add_score_loop: + push b + + ld b, [a : x] + add b, y + ld [a : x], b + cmp b, 10 + bnc + jmp add_score_carry + + pop b + ret + +add_score_carry: + sub b, 10 + ld [a : x], b + + ld y, 1 + + dec x + bo + dec a + + pop b + dec b + bnz + jmp add_score_loop + ret + +; ; Helper to clear the screen ; clear_screen: |