Prev: 29118 Up: Map Next: 29385
29268: 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 29268 LD A,(26276) Jump to Handler_DisplayMothershipBonus if *Flag_Collision is not 2 ("explosion complete").
29271 CP 2
29273 JP NZ,Handler_DisplayMothershipBonus
29276 LD A,(26353) Jump to LevelReset_ClearGameState if *Phase is not phase 4.
29279 CP 4
29281 JR NZ,LevelReset_ClearGameState
This is phase 4 - the mothership phase.
29283 LD HL,26077 Point HL to Table_CurrentAlienPhaseData.
29286 LD B,8 Set a counter in B for 8 aliens.
LevelReset_ClearMothership_Loop 29288 PUSH BC Stash the alien counter on the stack.
29289 LD E,(HL) Load the alien position into DE.
29290 INC HL
29291 LD D,(HL)
29292 INC HL Move the alien data pointer to the next alien.
29293 PUSH HL Stash the alien data pointer on the stack.
29294 BIT 6,D Call ClearSpriteArea if bit 6 of D is active.
29296 CALL NZ,ClearSpriteArea
29299 POP HL Restore the alien data pointer and alien counter from the stack.
29300 POP BC
29301 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 29303 LD HL,26240 Clear 0108 bytes from 26240 onwards.
29306 LD DE,26241
29309 LD BC,108
29312 LD (HL),B
29313 LDIR
29315 LD HL,26077 Point HL to Table_CurrentAlienPhaseData.
29318 LD DE,26078 DE=26078.
29321 PUSH HL Stash HL on the stack.
29322 LD C,29 C=29.
29324 LD (HL),B Write B to *HL.
29325 LDIR LDIR.
Reset the alien positions back to defaults.
Start by setting a phase default (data for phases 2 and 3).
29327 LD HL,26167 HL=Table_AlienPhaseData_02_03.
29330 LD A,(26353) Jump to LevelReset_CheckPhase_01 if *Phase is not phase 0.
29333 OR A
29334 JR NZ,LevelReset_CheckPhase_01
This is phase 0 so set accordingly.
29336 LD HL,26107 HL=Table_AlienPhaseData_00.
29339 JR LevelReset_CopyWaveData Jump to LevelReset_CopyWaveData.
Is this phase 1?
LevelReset_CheckPhase_01 29341 CP 1 Jump to LevelReset_CheckPhase_04 if *Phase is not phase 1.
29343 JR NZ,LevelReset_CheckPhase_04
This is phase 1 so set accordingly.
29345 LD HL,26137 HL=Table_AlienPhaseData_01.
29348 JR LevelReset_CopyWaveData Jump to LevelReset_CopyWaveData.
Is this phase 4?
LevelReset_CheckPhase_04 29350 CP 4 Jump to LevelReset_CopyWaveData if *Phase is not phase 4.
29352 JR NZ,LevelReset_CopyWaveData
This is phase 4 so set accordingly.
29354 LD HL,26183 HL=Table_AlienPhaseData_04.
Copy the phase default data to the active table.
LevelReset_CopyWaveData 29357 POP DE Restore DE from the stack.
29358 LD A,(26239) A=*AlienCount.
29361 ADD A,A Multiply A by 2.
29362 JR Z,LevelReset_ResetPlayerPosition Jump to LevelReset_ResetPlayerPosition if A is zero.
29364 LD C,A C=A.
29365 LDIR LDIR.
Reset player position.
LevelReset_ResetPlayerPosition 29367 LD HL,26349 Write 206 to *PlayerAttributeBufferPosition.
29370 LD (HL),206
Handle "spending a life".
29372 LD HL,26352 HL=Player_Lives.
29375 DEC (HL) Decrease Player_Lives by one.
29376 LD A,(HL) Jump to Handler_LevelComplete if *Player_Lives indicates the player still has lives left.
29377 OR A
29378 JR NZ,Handler_LevelComplete
Player has lost all their lives, set the *Flag_GameOver flag.
29380 INC A Write 1 to *Flag_GameOver.
29381 LD (26357),A
29384 RET Return.
Prev: 29118 Up: Map Next: 29385