2 Player Vs Score/Death Script Help?

crazygrouptrio

Active member
Okay so, I'm horrible at script. But I have this player death script almost working and just need some advice for its execution. Basically when a player dies the other player gets a point and they warp to the next screen(warping is handled in the player action) with full health. Right now it at least seems to work fine for player 1, but player 2's score never goes up so I'm obviously missing a line of code to count for that player (but it doesn't count to player 1 so I must be close?) The HUD stuff is set correctly as well.
Here's my playerdeath script as it is (it's probably a mess)
Code:
    TXA
    STA tempx
    TYA 
    STA tempy

    ;;;;;;;;;;;;;;;;;;;
    ;LDX player1_object ;;dale_coop player object is already in x ?
    LDA player2Mode
    BEQ +
    CPX player2_object
    BNE +
    ;; is player 2

    LDA #$FF
    STA player2_object
    LDA #$00
    STA myHealth2

    ;; Update HUD:
    STA hudElementTilesToLoad
    AddValue #$03, P1Score, #$01, #$00
    UpdateHud HUD_P1Score
    UpdateHud HUD_myHealth2
    LDA #$01
    STA temp3
    +
        LDA Object_x_hi,x
    STA temp
    LDA Object_y_hi,x
    STA temp1
        DeactivateCurrentObject
        CreateObject temp, temp1, #OBJ_PLAYER_DEATH, temp3, currentNametable
    JMP ++
    

    +
    
    ;; is player 1
    LDA #$FF
    STA player1_object
    LDA #$00    
    STA myHealth1
    ;; Update HUD:
    STA hudElementTilesToLoad
    AddValue #$05, P2Score, #$01, #$00
    UpdateHud HUD_P2Score
    UpdateHud HUD_myHealth1
    LDA #$00
    STA temp3
    +
    LDA Object_x_hi,x
    STA temp
    LDA Object_y_hi,x
    STA temp1
        DeactivateCurrentObject
        CreateObject temp, temp1, #OBJ_PLAYER_DEATH, temp3, currentNametable
    ++
    

    ;;;;;;;;;;;;;;;;;;;
    ;StopSound
    ;PlaySound #$00, #$00
    
    LDA #$05
    STA myHealth1
    +
    LDA #$05
    STA myHealth2
    +

    
    LDX tempx
    LDY tempy
    
    PlaySound #SND_DEATH_PLAYER
    
    ;; if ALL dead, it's finished
    ;; player 2 dead?
    ; LDA player2_object
    ; CLC
    ; CMP #$FF
    ; BNE +
    ; player 1 dead?
    ; LDA player1_object
    ; CLC
    ; CMP #$FF
    ; BNE +
    ; JSR LoseLife
    ; +
    
    RTS
Dale's original code has both players sharing the deactivateobject/createobject line, but in my game it would produce a second sprite of the still living player when the other died so I split it, which fixed it, but probably created my current problem?
Also player 1's health meter never goes down to 0. They still die correctly, but the HUD shows they have 1 life left each time. Not sure why that is either...
Any help would be appreciated!

EDIT: After some experimenting I've gotten some differing results:
1. Player 1 kills player 2, works fine.
2. Player 2 kills player 1, no score is added.
3. Monsters killing the player usually work as above, but on 1 occasion it scored player 2 correctly? (and yes I want the monster killing the player to count towards the living player)
May be more going on here than this one script... I can upload a video of whats happening if any of this is confusing. Again, any insight is appreciated! :?
 

dale_coop

Moderator
Staff member
Hey crazygrouptrio,
sorry, I was very busy this weekend, couldn't check all those interesting topics :p

About yourr CreatePlayerDeathObject script, here a fixed version (when a player dies, it adds 1 point to the other player):
Code:
	TXA
	STA tempx
	TYA 
	STA tempy

	;;;;;;;;;;;;;;;;;;;
	;LDX player1_object	;;dale_coop player object is already in x ?
	LDA player2Mode
	BEQ +
	CPX player2_object
	BNE +
	;; is player 2
	LDA #$FF
	STA player2_object
	LDA #$00
	STA myHealth2
	;; Update HUD:
	STA hudElementTilesToLoad
	UpdateHud HUD_myHealth2
    AddValue #$03, P1Score, #$01, #$00
    UpdateHud HUD_P1Score
	
	LDA #$01
	STA temp3
	JMP ++
	+
	;; is player 1
	LDA #$FF
	STA player1_object
	LDA #$00	
	STA myHealth1
	;; Update HUD:
	STA hudElementTilesToLoad
	UpdateHud HUD_myHealth1
    AddValue #$03, P2Score, #$01, #$00
    UpdateHud HUD_P2Score	
	LDA #$00
	STA temp3
	++
	
	LDA Object_x_hi,x
	STA temp
	LDA Object_y_hi,x
	STA temp1

	DeactivateCurrentObject
	
	CreateObject temp, temp1, #OBJ_PLAYER_DEATH, temp3, currentNametable
	;;;;;;;;;;;;;;;;;;;
	;StopSound
	;PlaySound #$00, #$00

	
	LDX tempx
	LDY tempy
	
	PlaySound #SND_DEATH_PLAYER
	
	;; if ALL dead, it's finished
	;; player 2 dead?
	; LDA player2_object
	; CLC
	; CMP #$FF
	; BNE +
	; player 1 dead?
	; LDA player1_object
	; CLC
	; CMP #$FF
	; BNE +
	; JSR LoseLife
	; +
	
	RTS

You don't need to split in 2 different death objects... because currenlty, my module use 2 different action steps for the death players. But it's create individually. When the player 1 dies, it creates the action step 0 animation death. When the player 2 dies, it creates the action step 1 animation death.
In the Death Animation Object, the Action Step 0 is for the player 1 and the Action Step 1 for the player 2. So you can assign 2 differents animations, it means 2 different graphics (2 different color palettes)! The only limitation is they both needs to have the same size.
I hope you understand my not-so-clear explanation.


About the re-initilization of yoru players lives... those lines: (note: I removed them)
Code:
    LDA #$05
    STA myHealth1
    LDA #$05
    STA myHealth2
Yes, you could add those in the createPlayerDeathObject script... but I think it would be better to put them in the script that does the WARP (when loose/win) or in the Handle Screen Loads (when a new screen is loaded).

;)
 

crazygrouptrio

Active member
Like I said I divided the createdeathobject line just because it was making copies of the players when one would die, I thought maybe it was caused by the health reset being part of the same script, but apparently not as it is still happening with your script implemented. :? It looks like when the 2nd player dies a second time it kills the 1st player as well and creates another player sprite in the process. This screenshot is taken on the 3rd screen, which means only 2 deaths could have occurred but Player 1 seems to have also died since Player 2 got a point somehow :lol:
iMIKuhJ.png
 

dale_coop

Moderator
Staff member
I understand what you said, I just think you don't need to split... the death animation object can be used for both player's deaths. Here, it's not the cause of your issue.
Player 1 dies --> creates the death animation object, action step 0 (animation representing the player 1 dead)
Player 2 dies --> creates the death animation object, action step 1 (animation representing the player 2 dead)
How is set your "end of animation" for both action step 0 and action 1? (or end of timer... depends of which one you used) I think the real problem is here.

You have your duplication as soon as a player dies...? or when they both warped to a new screen?
Could you share a video of the issue?
 

crazygrouptrio

Active member
[media]https://youtu.be/-2v27JywL5w[/media]
FPUbZ8s.png


It looks like when Player 2 dies a second time, Player 1 loses all of his health and dies as well. That's my current death object actions.
 

dale_coop

Moderator
Staff member
Try this CreatePlayerDeathObject script:
Code:
	TXA
	STA tempx
	TYA 
	STA tempy

	;;;;;;;;;;;;;;;;;;;
	;LDX player1_object	;;dale_coop player object is already in x ?
	LDA player2Mode
	BEQ +
	CPX player2_object
	BNE +
	;; is player 2
	LDA #$FF
	STA player2_object
	LDA #$00
	STA myHealth2
	;; Update HUD:
	STA hudElementTilesToLoad
	UpdateHud HUD_myHealth2
    AddValue #$03, P1Score, #$01, #$00
    UpdateHud HUD_P1Score
	
	LDA #$01
	STA temp3
	JMP ++
	+
	;; is player 1
	LDA #$FF
	STA player1_object
	LDA #$00	
	STA myHealth1
	;; Update HUD:
	STA hudElementTilesToLoad
	UpdateHud HUD_myHealth1
    AddValue #$03, P2Score, #$01, #$00
    UpdateHud HUD_P2Score	
	LDA #$00
	STA temp3
	++
	
	LDA Object_x_hi,x
	STA temp
	LDA Object_y_hi,x
	STA temp1

	DeactivateCurrentObject
	
	CreateObject temp, temp1, #OBJ_PLAYER_DEATH, temp3, currentNametable
	;;;;;;;;;;;;;;;;;;;
	;StopSound
	;PlaySound #$00, #$00

	
	LDX tempx
	LDY tempy
	
	PlaySound #SND_DEATH_PLAYER
	
	
	;; player 1 init health:
	LDA #$05
	STA myHealth1
	
	;; if player 2 is set:
	LDA player2Mode
	BEQ +
	;; player 2 init health:
	LDA #$05
	STA myHealth2
	+	
	
	;; if ALL dead, it's finished
	;; player 2 dead?
	; LDA player2_object
	; CLC
	; CMP #$FF
	; BNE +
	; player 1 dead?
	; LDA player1_object
	; CLC
	; CMP #$FF
	; BNE +
	; JSR LoseLife
	; +
	
	RTS

The difference with my previous script is I just added the reinit of my life at the end.
Make sure to set both (same settings) Action Step 0 and Action Step 1 to "Warp to Screen" on "end of animation" (and nothing else... dont mix restart game and warp to screen!).
Tested on my demo project, it should work...
(And about that positioning of your players on screen load, you could set the "PLAYER_2_OFFSET_TRANSITIONS" and "PLAYER_2_OFFSET_STARTING" to the same value... it's the distance between the players when a new screen loads).
 

crazygrouptrio

Active member
Hmm. It's still happening exactly the same... :?
And I already had the Offsets at the same value just in case. It was just the duplicate on that last screen that spawned where the player "died".
I forgot to mention this happens with each screen onward as well. It produces a new player object every time.
 

dale_coop

Moderator
Staff member
I don't have this with my demo...
You didn't made other modifications in scripts (timer warp script or handle screen loads script) ?

If you want, I could check your project, I could tell exactly what's goining on... (would need the project .MST file and the GameEngineData and GraphicAssets folders), if you don't mind sharing it?
 

crazygrouptrio

Active member
I checked those scripts and copied them over with the original files just in case (I am bad about messing with stuff) and the problem remains. But it has something to do with monsters. I removed my test monster from the first screen and sure enough the glitch doesn't happen on any later screens. But I don't know what would cause that? I'll message the files over to you in a second.
 

dale_coop

Moderator
Staff member
Thanks for sharing your project... I check and it might be related to the monster, yep (or the death game object itself)... that on warp, the object might be not deactivated.

So I have a small fix for you:
Modify the Timer_WarpToNewScript_DC.asm (you can find it in the "Project Settings > Scripts Settings" assigned to the "Action Anim End 9" element.
And before the "RTS" line, add :
Code:
	JSR DeactivateAllObjects
	
	RTS


NOTE: I 'd suggest to duplicate the original Timer_WarpToNewScript_DC.asm to maybe "Timer_WarpToNewScript_brawler.asm" and modify & assign that one to the element.
(always keep original scripts when you can... and make custom ones when you need modification)
 

crazygrouptrio

Active member
Yes I've learned to always keep backups :lol: and thank you for your help! That has been driving me nuts for days. I wish I realized it was the monster sooner...
Now I can start the fun part of designing the levels :D thanks again!
 
Top Bottom