Now we have a real two player coop mode. It's not both players playing by themselves, but true teamwork. Sam needs to capture, and only then Dean can shoot enemies.
To makes things easier we add a new flag to check if two player mode is active (TWO_PLAYER_MODE_ACTIVE):
;set two player mode active flag
lda #0
sta TWO_PLAYER_MODE_ACTIVE
lda GAME_MODE
cmp #GT_COOP
bne +
inc TWO_PLAYER_MODE_ACTIVE
+
Remove the flag if one of the player dies on his last life:
.OtherPlayerStillAlive
;remove 2 player active flag
lda #0
sta TWO_PLAYER_MODE_ACTIVE
jsr RemoveObject
rts
If Sam is firing away and the enemy would be hurt, we bail out if our flag is set. The flag set means having a value of 0. So beq actually checks if it is not set:
;Sam needs to keep pressed
jsr RedrawForceBeam
ldy SPRITE_HELD
dey
ldx SPRITE_ACTIVE,y
lda IS_TYPE_ENEMY,x
cmp #1
bne .NormalHurtByForce
;in 2p mode?
lda TWO_PLAYER_MODE_ACTIVE
beq .NormalHurtByForce
;no further action
jmp .NoEnemyHeld
.NormalHurtByForce
In Deans shot routine we check if the enemy is held, if not bail out:
.EnemyHit
;enemy hit! ;is two player enemy?
ldy SPRITE_ACTIVE,x
lda IS_TYPE_ENEMY,y
cmp #1
bne .HitEnemy
;in 2p mode?
lda TWO_PLAYER_MODE_ACTIVE
beq .HitEnemy
;is the player held?
ldy SPRITE_HELD
dey
sty PARAM1
cpx PARAM1
beq .HitEnemy
;enemy would be hit, but is not held
jmp .ShotDone
.HitEnemy
Simple addon, but bound to get complicated :)