Prev: 71BE Up: Map Next: 72C9
7254: Handler: Level Reset
Used by the routines at TitleScreen and StartGame.
Reset the level after the player death, clearing aliens and restoring states.
Handler_LevelReset 7254 LD A,($66A4) Jump to Handler_DisplayMothershipBonus if *Flag_Collision is not 02 ("explosion complete").
7257 CP $02
7259 JP NZ,Handler_DisplayMothershipBonus
725C LD A,($66F1) Jump to LevelReset_ClearGameState if *Phase is not phase 04.
725F CP $04
7261 JR NZ,LevelReset_ClearGameState
This is phase 04 - the mothership phase.
7263 LD HL,$65DD Point HL to Table_CurrentAlienPhaseData.
7266 LD B,$08 Set a counter in B for 08 aliens.
LevelReset_ClearMothership_Loop 7268 PUSH BC Stash the alien counter on the stack.
7269 LD E,(HL) Load the alien position into DE.
726A INC HL
726B LD D,(HL)
726C INC HL Move the alien data pointer to the next alien.
726D PUSH HL Stash the alien data pointer on the stack.
726E BIT 6,D Call ClearSpriteArea if bit 6 of D is active.
7270 CALL NZ,ClearSpriteArea
7273 POP HL Restore the alien data pointer and alien counter from the stack.
7274 POP BC
7275 DJNZ LevelReset_ClearMothership_Loop Decrease the alien counter by one and loop back to LevelReset_ClearMothership_Loop until all of the aliens have been reset.
Clear game state data.
LevelReset_ClearGameState 7277 LD HL,$6680 Clear 006C bytes from 6680 onwards.
727A LD DE,$6681
727D LD BC,$006C
7280 LD (HL),B
7281 LDIR
7283 LD HL,$65DD Point HL to Table_CurrentAlienPhaseData.
7286 LD DE,$65DE DE=65DE.
7289 PUSH HL Stash HL on the stack.
728A LD C,$1D C=1D.
728C LD (HL),B Write B to *HL.
728D LDIR LDIR.
Reset the alien positions back to defaults.
Start by setting a phase default (data for phases 02 and 03).
728F LD HL,$6637 HL=Table_AlienPhaseData_02_03.
7292 LD A,($66F1) Jump to LevelReset_CheckPhase_01 if *Phase is not phase 00.
7295 OR A
7296 JR NZ,LevelReset_CheckPhase_01
This is phase 00 so set accordingly.
7298 LD HL,$65FB HL=Table_AlienPhaseData_00.
729B JR LevelReset_CopyWaveData Jump to LevelReset_CopyWaveData.
Is this phase 01?
LevelReset_CheckPhase_01 729D CP $01 Jump to LevelReset_CheckPhase_04 if *Phase is not phase 01.
729F JR NZ,LevelReset_CheckPhase_04
This is phase 01 so set accordingly.
72A1 LD HL,$6619 HL=Table_AlienPhaseData_01.
72A4 JR LevelReset_CopyWaveData Jump to LevelReset_CopyWaveData.
Is this phase 04?
LevelReset_CheckPhase_04 72A6 CP $04 Jump to LevelReset_CopyWaveData if *Phase is not phase 04.
72A8 JR NZ,LevelReset_CopyWaveData
This is phase 04 so set accordingly.
72AA LD HL,$6647 HL=Table_AlienPhaseData_04.
Copy the phase default data to the active table.
LevelReset_CopyWaveData 72AD POP DE Restore DE from the stack.
72AE LD A,($667F) A=*AlienCount.
72B1 ADD A,A Multiply A by 02.
72B2 JR Z,LevelReset_ResetPlayerPosition Jump to LevelReset_ResetPlayerPosition if A is zero.
72B4 LD C,A C=A.
72B5 LDIR LDIR.
Reset player position.
LevelReset_ResetPlayerPosition 72B7 LD HL,$66ED Write CE to *PlayerAttributeBufferPosition.
72BA LD (HL),$CE
Handle "spending a life".
72BC LD HL,$66F0 HL=Player_Lives.
72BF DEC (HL) Decrease Player_Lives by one.
72C0 LD A,(HL) Jump to Handler_LevelComplete if *Player_Lives indicates the player still has lives left.
72C1 OR A
72C2 JR NZ,Handler_LevelComplete
Player has lost all their lives, set the *Flag_GameOver flag.
72C4 INC A Write 01 to *Flag_GameOver.
72C5 LD ($66F5),A
72C8 RET Return.
Prev: 71BE Up: Map Next: 72C9