First, the explanation of your issue.
myLives is a variable that can have any integer value. But, because you displays it as 2 digits on your HUD, NESmaker split it into 2 memory addresses:
"myLives+1" for the tenths digit
"myLives" for the units digit
Each of them should have a value between "0" and "9" to be able to display "00" - "99" in your hud (2 different tiles are drawn).
Your current code is only based on "myLives"... increasing it. Then, when the units digit (myLives) is "9" and you do a +1... it becomes "10", it means the next value after "9", also mean the next "tile" after "9" in your tileset... which is the "A" tile.
So you have to use specific macro to increase and decrease a variable that is displayed as a number on the HUD (more than 2 digits), if you take a look at how myScore code is made, you can guess...
Here is a modified version of your code using the AddValue and SubtractValue macros instead of ADC/INC/SBC/DEC opcodes...
The "1UP" Power up script:
Code:
TXA
STA tempx
AddValue #$02, myLives, #$01, #$00 ;; Adding +1 to a 2 digits HUD variable
;; update the count in hud:
UpdateHud HUD_myLives
;; play 1UP sound
PlaySound #SND_GET
LDX tempx
The "crayon" script:
Code:
;;blank
CPX player1_object
BEQ isPlayerForCollectable
JMP ++
isPlayerForCollectable:
LDA tileCollisionFlag
BEQ +
JMP ++
+
LDA #$01
STA tileCollisionFlag
ChangeTileAtCollision #$00, #$60
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TXA
STA tempx
AddValue #$08, myMoney, #$01, #$00
;;; we also need to set up the routine to update the HUD
;; for this to work right, health must be a "blank-then-draw" type element.
;STA hudElementTilesToLoad
; LDA #$00
; STA hudElementTilesMax
; LDA DrawHudBytes
; ora #HUD_myMoney
; STA DrawHudBytes
UpdateHud HUD_myMoney
PlaySound #SND_CART
LDA #$00
STA value
STA value+1
STA value+2
STA value+3
STA value+4
STA value+5
STA value+6
STA value+7
;; extra life stuff:
LDA myMoney+2
BNE updateLives ;count equal to 100
JMP +
updateLives:
AddValue #$02, myLives, #$01, #$00 ;; Adding +1 to a 2 digits HUD variable
;; update the count in hud:
UpdateHud HUD_myLives
;; play 1UP sound
PlaySound #SND_GET
;;reset myMoney count
LDA #$00
STA myMoney
STA myMoney+1
STA myMoney+2
+:
LDX tempx
The lose life script:
Code:
;;; do loss of life stuff here
SubtractValue #$02, myLives, #$01, #$00 ;; Decreasing -1 a 2 digits HUD variable
LDA myLives+1 ;; checking if the tenth digit is different than 0
BNE gameNotOver
LDA myLives ;; then, checking if the unit digit is different than 0
BNE gameNotOver
;;do gameover stuff here. Warp to screen? Show animation? Just restart?
;JMP RESET
JMP gameOver
gameNotOver:
;;;;;
;;; do warp to continue screen stuff here.
LDA #$00
STA newGameState
LDA continueMap
CLC
ADC #$01
STA temp
GoToScreen continueScreen, temp, #$04
LDA #$00
STA playerToSpawn
;LDX player1_object
;DeactivateCurrentObject
LDA #$01
STA loadObjectFlag
JSR DeactivateAllObjects
LDA continuePositionX
STA newX
LDA continuePositionY
STA newY
;; player1 reset health:
LDA #$03 ;; <--- HERE reset with your Health value
STA myHealth
RTS
gameOver:
;; warp to Game over:
LDA #GAME_OVER_SCREEN
STA warpToScreen
LDA #$00
STA newGameState
LDA continueMap
CLC
ADC #$01
STA temp
GoToScreen warpToScreen, temp, #$02
LDA #$00
STA playerToSpawn
;LDX player1_object
;DeactivateCurrentObject
LDA #$01
STA loadObjectFlag
JSR DeactivateAllObjects
RTS
Also, make sure your SubtractValue.asm macro is the 4.1.1 updated one! (Joe fixed it for the 4.1.1... but forgot to put it in the 4.1.5 version).
If you open it (the script should be in your "Basic\Macros" folder), it should be that one:
Code:
MACRO SubtractValue arg0, arg1, arg2, arg3
TXA
PHA
;arg0 = how many places this value has.
;arg1 = home variable
;arg2 = amount to subtract ... places?
;arg3 = to what place
LDX arg0
--:
LDA arg1,x ;; the variable that you want to push
STA value,x
dex
BPL --
LDX arg3 ; sets the place to push.
LDA arg2
STA temp
JSR valueSubLoop ;; will add what is in accumulator.
;;; now value nees to be unpacked back into the variable.
LDX arg0
-:
LDA value,x ;; the variable that you want to push
STA arg1,x
dex
BPL -
PLA
TAX
ENDM
(in that updated version... the "arg3" variable is used "LDX arg3 ; sets the place to push."... in the incorrect version that line was not in the script)
If it doesn't work as intended, tell me, I could fix the issue... when I am at home (I am at my office, right now).
See ya