Extra Life from collectable

n8bit

Member
I am trying to add to the collectable script so that when you collect 100 items you get an extra life and the count resets.

When I tested with a low number like 3 (#$03) the script worked great, but when I changed it to 100 (#$64) it does not work at all.

here is my 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
    CMP #$64 ;compare count (must be 100)
    BEQ 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
Your myMoney is displayed as a number (3 digits) on the HUD?
So to check 100, you just need to check the hundreds digit:
Code:
    ;; extra life stuff:
    LDA myMoney+2
    BNE updateLives ;count equal to 100
    JMP +
 

n8bit

Member
dale_coop said:
Your myMoney is displayed as a number (3 digits) on the HUD?
So to check 100, you just need to check the hundreds digit:
Code:
    ;; extra life stuff:
    LDA myMoney+2
    BNE updateLives ;count equal to 100
    JMP +

That worked! I kinda thought I was making it more difficult than it needed to be.

Thanks Dale!
 

mongolianmisfit

New member
Is this a one off script, or did you end up including it in an existing one? Out of context, I'm just wondering where something like this would end up existing.
 

dale_coop

Moderator
Staff member
n8bit 's script (+ my small modification)... is a full tile script. You can directly use it as it... assign it to a unused "Collision Tile 0?" in the "Project Settings > Script Settings".
 

red moon

Member
Hey guys, this script would fit well with what I am trying to do with limiting the number of treasure elements that can be found. I understand that assigning this to an empty tile type allows it to count differently toward the total?
So, after adding this "Extralife.asm" script to my scrollingplatform folder , I would need to switch my treasures to use this new tile type?
Thanks!
 

Attachments

  • extra1.jpg
    extra1.jpg
    770.6 KB · Views: 2,017
  • extra2.jpg
    extra2.jpg
    242.3 KB · Views: 2,017

dale_coop

Moderator
Staff member
That script is "just" a modification to the Collectable for Score script... adding that when you got 100 (money), you got increase (+1) yours lives.
 

red moon

Member
Ahh, that makes more sense. My understanding was a bit off. Thanks for clearing it up!
Although, I will be setting my value really low since its tied to treasures and they may be 10 in total in my test level.
 

dale_coop

Moderator
Staff member
But you could do the same for your key script...
What are you using currently? the Get Key tile? or the Key pickup object?

If I remember well, the pickup/power key script, already has a limitation... of "9" keys:
Code:
	CMP #$0A
($0A in hex is 09 in decimal)
 

red moon

Member
Dale, I current have the chest tiles and other treasures set to collect score, so they function with the hud code. I would like to add keys later on, when killing bosses but that's weeks or months away!
i will open up the collection score script and take a look at adding these lines at the end...
 

red moon

Member
Dale,
I adjusted the powerup collectible script to look like this..
I am getting some odd results. If I jump into them when punching I instantly kill them and gain 10 treasures? I dont think that issue is related to this though....

Code:
;;; Increase Score
;;; works with variable myScore
;;; works with HUD variable HUD_myScore.
	TXA
	STA tempx
	
	AddValue #$08, 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_CART
	LDX tempx
	
	;;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
    CMP #$64 ;compare count (must be 100)
    BEQ 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
	
	    ;; extra life stuff:
    LDA myMoney+2
    BNE updateLives ;count equal to 10
    JMP +
 

dale_coop

Moderator
Staff member
I think it is related to your modification, yes. Your script is incorrect...

That script is assigned to your...? Currency Pickup? Health pickup? I mean, in the "Project Settings > Script Settings" to which "PowerUp ??" element that script is it assigned?

And most importantly, what do you want to do exactly?
 

red moon

Member
That makes sense, I will search the script settings to find where this and remove the additional code I added to the power-up then. I have these set to collect score so I will see where that exists "Project Settings > Script Settings" and what script its referencing. These are tiles, so it may locating the collect score tile script.
Thanks again!
 

red moon

Member
Hey guys, I adjusted my tile collectible for score script like this. My additions did not give me an extra life per 10 collectibles, it resulted in infinite lives.

Code:
;;blank
	CPX player1_object
	BEQ isPlayerForCollectableScore
	JMP ++
isPlayerForCollectableScore:
	LDA tileCollisionFlag
	BEQ +
	JMP ++
+
	LDA #$01
	STA tileCollisionFlag
	ChangeTileAtCollision #$00, #$00
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	TXA
	STA tempx	
	AddValue #$08, 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+2
    BNE updateLives ;count equal to 10
    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 myScore count
    LDA #$00
    STA myScore
    STA myScore+1
    STA myScore+2
	
	+:
    LDX tempx
 

dale_coop

Moderator
Staff member
red moon said:
Hey guys, I adjusted my tile collectible for score script like this. My additions did not give me an extra life per 10 collectibles, it resulted in infinite lives.


Just like that, reading your script... I see one error.
A missing
Code:
++
line at the complete end of the script.
Don't know if it will fix your issue... (can't test it right now, I am at my office)
 

dale_coop

Moderator
Staff member
Also, if you want an extra life every 10... you should check
Code:
LDA myScore+1
not LDA myScore+2

Then the real question here is do you display the myScore hud variable on your HUD ? (this script would work only if you display it as a number, of 3 digits).
But another question wouls be why you'd need to dipslay 3 digits if it reset to 0 every 10.... Right?
Because you'd just need a 1 digit number. And in that case, the script is not working (LDA myScore+1 would not work... and will return the value of another variable/memory address)


So... we should just start from the begining:

1) you want to add an extra life each time you collect 10?
2) your score variable?
3) Do you display this variable on the HUD?
We'll help you to get a working script.
 

red moon

Member
Thanks Dale,
I'm at work now and cant grab screenshots until I am home tonight. I will post a few showing the HUD setup and tiles setup then.

1) you want to add an extra life each time you collect 10?
2) your score variable?
3) Do you display this variable on the HUD?
We'll help you to get a working script.

And to answer these with some bit of context.
1)I am placing treasure tiles in the screens themselves for pickup. I wish the player to gain a life each time 10 treasures are collected.
2) my score variable is a 2 digit number 00-99
3) I am a tile graphic from the HUD sheet (a chest in this case) and a two digit number that is set to score.

For the lives gaining 1 for each 10 found.
I have my lives currently set to 3. Would the base script need to change to account for the extra lives gained from these pickups? A starting min (3) and a max (5/6 at most since I have limited display room in the HUD)
Thanks again, I will post screens in a couple hours!
 

red moon

Member
I am home and finally able to get these up.
One thing, I don't need to reset once an extra life is gained...I am fine with the counter continuing to 99.
Thanks Dale!
 

Attachments

  • Cscore1.jpg
    Cscore1.jpg
    518.7 KB · Views: 1,614
  • Cscore2.jpg
    Cscore2.jpg
    494.7 KB · Views: 1,614

red moon

Member
Dale,
I went ahead and fixed the bottom of the script, removed the reset to 0 and changed the LDA myscore + 2 to + 1.

Code:
;;blank
	CPX player1_object
	BEQ isPlayerForCollectableScore
	JMP ++
isPlayerForCollectableScore:
	LDA tileCollisionFlag
	BEQ +
	JMP ++
+
	LDA #$01
	STA tileCollisionFlag
	ChangeTileAtCollision #$00, #$00
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	TXA
	STA tempx	
	AddValue #$08, 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+1
    BNE updateLives ;count equal to 10
    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
    
    
	
	+:
    LDX tempx
	++
 
Top Bottom