Extra Life from collectable

dale_coop

Moderator
Staff member
Nice, but you might have an issue, if you don't reset the score.. because that score check if your score is more than (or equalto) 10 to give you an extra life... it means when you will have more than 10, if you don't reset... the comparison will always be true, your score will always be more than 10, so you will always get a new life...
That is a problem.

Let me check tonight, I will try to give you a better script corresponding to what you want.
 

red moon

Member
Dale, that makes sense...
I appreciate you taking the time to give it some thought to come up with a better solution. I am really just wanting to give the player a reason to collect treasures and offering an extra life for "X" number collected seemed like a fairly straightforward way.
 

dale_coop

Moderator
Staff member
I understand well this. It's important to give the player motivations ;) ah ah
I'll have a new CollectForScore script for you, today...
 

dale_coop

Moderator
Staff member
Make a new script (for example "Collectable_JustForScore_GivingExtraLife10.asm") in your "Basic\ModuleScripts\TileScripts\ScrollingPlatformer" folder, with that:

Code:
;;blank
	CPX player1_object
	BEQ isPlayerForCollectableScore
	JMP ++
isPlayerForCollectableScore:
	LDA tileCollisionFlag
	BEQ +
	JMP ++
+
	LDA #$01
	STA tileCollisionFlag
	ChangeTileAtCollision #$00, #$00
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	TXA
	STA tempx	

	AddValue #$02, myScore, #$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_myScore
		; STA DrawHudBytes
	UpdateHud HUD_myScore
	PlaySound #SND_GET
	
	
	;; extra life stuff:
    LDA myScore	;; checking the current unit digit of the score is "0" (it means 10, 20, ... 90)?
    BNE +		;; if not "0" we skip
    LDA myLives
    ADC #$01 ;add 1 to lives
    STA myLives    
    ;; update the count in hud
    STA hudElementTilesToLoad
    UpdateHud HUD_myLives

    ;; play 1UP sound:
    ; PlaySound #SND_1UP	(add a new "SND_1UP" sfx)
	+


    LDX tempx
	++


Then, assigned that script to the "Tile Collision 03" element in your "Project Settings > Script Settings".

2019-10-28-11-06-56-Project-Settings.png



Now, it should give you +1 life every 10 score collected.
 

red moon

Member
Awesome, thanks so much Dale!

I will add this as soon as I'm home, I will look closely at what you created too, to expand my understanding of your script.
 

TolerantX

Active member
I tried to write a script that updated the SCORE and the MONEY/COINS that give an extra life at 100 and reset after reaching that number. the tile pick up should add to score as well... The current error is when I do this all it does is add a point to the SCORE and nothing to the myMoney MONEY variable in the HUD.

;;; Increase Score
;;; works with variable myScore
;;; works with HUD variable HUD_myScore.

CPX player1_object
BEQ isPlayerForCollectable
JMP ++
isPlayerForCollectable:
LDA tileCollisionFlag
BEQ +
JMP ++
+
LDA #$01
STA tileCollisionFlag
ChangeTileAtCollision #$00, #$00

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TXA
STA tempx
AddValue #$08, myScore, #$05, #$01
;;; 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_myScore
; STA DrawHudBytes
UpdateHud HUD_myScore

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

LDX tempx

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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_GET

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:
LDA myLives
ADC #$01 ;add 1 to lives
STA myLives

;; update the count in hud
STA hudElementTilesToLoad
UpdateHud HUD_myLives

;; play 1UP sound
PlaySound #SND_GET

;;reset myMoney count
LDA #$00
STA myMoney
STA myMoney+1
STA myMoney+2

+:
LDX tempx
 

dale_coop

Moderator
Staff member
First important question. How is your hud? We need to know how you display those variables on your HUD.... how many digits have your hud variables myMoney, myScore and myLives if you display them
Could share screenshots ?
 

Yan

Member
What about a collectable tile that acts as a checkpoint but also gives extra lives (5 for example) ignoring the score? How could I make something like that?
 

dale_coop

Moderator
Staff member
Yan said:
What about a collectable tile that acts as a checkpoint but also gives extra lives (5 for example) ignoring the score? How could I make something like that?

Maybe something like that:
Code:
	;; INCREASE LIVES
	LDA myLives
	ADC #$05 		;; add 5 to lives
	STA myLives    
	;; update the hud
	STA hudElementTilesToLoad
	UpdateHud HUD_myLives
	
	;; CHECKPOINT :
	LDA Object_x_hi,x
	STA continuePositionX
	LDA Object_y_hi,x
	STA continuePositionY
	LDA currentMap
	STA continueMap
	LDA Object_scroll,x
	STA continueScreen
	PlaySound #SND_VICTORY
	
	TriggerScreen screenType
 

vanderblade

Active member
I'm using the Collectable_JustForScore_GivingExtraLife10.asm and have an issue where whenever the lives cross an integer of 10, the symbol in the ones spot (farthest right digit) draws a symbol from the bmg sheet instead of a number. I don't have this issue with the level display or the score.

I'm using Var1 for myLives and using Numbers. It's the same as what I'm doing for my score in the HUD. What might be causing this?

Code:
;;blank
	CPX player1_object
	BEQ isPlayerForCollectableScore
	CPX player2_object
	BEQ isPlayerForCollectableScore
	JMP ++
isPlayerForCollectableScore:
	LDA tileCollisionFlag
	BEQ +
	JMP ++
+
	LDA #$01
	STA tileCollisionFlag
	ChangeTileAtCollision #$00, #$00
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	TXA
	STA tempx	

	AddValue #$02, myScore, #$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_myScore
		; STA DrawHudBytes
	UpdateHud HUD_myScore
	PlaySound #SND_GET
	
	
	;; extra life stuff:
    LDA myScore	;; checking the current unit digit of the score is "0" (it means 10, 20, ... 90)?
    BNE +		;; if not "0" we skip
    LDA myLives
    ADC #$01 ;add 1 to lives
    STA myLives    
    ;; update the count in hud
    STA hudElementTilesToLoad
    UpdateHud HUD_myLives

    ;; play 1UP sound:
    PlaySound #SND_GET	; (add a new "SND_1UP" sfx)
	+


    LDX tempx
	++

Screenshot (96).png
Screenshot (95).png
Screenshot (94).png
 

vanderblade

Active member
Related to this glitch -- or perhaps because of it -- the game randomly sometimes thinks I'm out of lives and goes back to the Start screen. I haven't figured out what variables result in this, but it's happened at least three times. I have plenty of lives, but then I die and the game thinks I'm out of lives. Hm.
 

dale_coop

Moderator
Staff member
It's because default scripts don't support more than 9 lives (hud element as number 1).
If you want a 2 digit number lives, you'll have to change your Collectable_JustForScore_GivingExtraLife10 to support that. Also have to modify the Handle Lose Lives to support it, too (because it checks only the 1 digit variable).
 

dale_coop

Moderator
Staff member
Here's for your Collectable_JustForScore_GivingExtraLife10.asm :

Code:
;;blank
	CPX player1_object
	BEQ isPlayerForCollectableScore
	CPX player2_object
	BEQ isPlayerForCollectableScore
	JMP ++
isPlayerForCollectableScore:
	LDA tileCollisionFlag
	BEQ +
	JMP ++
+
	LDA #$01
	STA tileCollisionFlag
	ChangeTileAtCollision #$00, #$00
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	TXA
	STA tempx	

	AddValue #$03, myScore, #$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_myScore
		; STA DrawHudBytes
	UpdateHud HUD_myScore
	PlaySound #SND_GET
	
	
	;; extra life stuff:
    LDA myScore	;; checking the current unit digit of the score is "0" (it means 10, 20, ... 90)?
    BNE +		;; if not "0" we skip
    AddValue #$02, myLives, #$01, #$00 
    ;; update the count in hud
    UpdateHud HUD_myLives

    ;; play 1UP sound:
    PlaySound #SND_GET	; (add a new "SND_1UP" sfx)
	+


    LDX tempx
	++


And for your Handle Lose Lives script, at the beginning, replace those lines:
Code:
playerLoseLife:
;;; do loss of life stuff here
	DEC myLives
	LDA myLives
	BNE gameNotOver
	;;do gameover stuff here.  Warp to screen?  Show animation?  Just restart?
	JMP RESET

By those lines:
Code:
playerLoseLife:
;;; do loss of life stuff here
	SubtractValue #$02, myLives, #$01, #$00 
	LDA myLives+1
	BNE gameNotOver
	LDA myLives
	BNE gameNotOver
	;;do gameover stuff here.  Warp to screen?  Show animation?  Just restart?
	JMP RESET

I think it should work
 

dale_coop

Moderator
Staff member
Not everything, but some lines, maybe....
Important question, what module are you using?
What do you want to do? Could you share your current powerup/IncreaseMoney.asm script?
 
Top Bottom