A life is the remaining chance to continue after the player ship is hit. The game stores it in a one-byte `lives` counter, starts a new game with five lives, and uses `player_dead` separately to prevent repeated collision handling during the death sequence. section 11.1
When an enemy overlaps the ship, the game decreases `lives`, marks the lives display for updating, sets `player_dead`, and removes the enemy. This separates the immediate collision result from the later animation and restart work. section 11.1
After a life is lost, the game follows a short recovery path:
- Advance through four explosion shapes over timed stages while the player is dead. section 11.2
- If lives remain, reset the current level, redraw the player ship, and clear the dead flag. section 11.2
- If no lives remain, show a Game Over message, wait, clear sprites, and return to the title screen. section 11.3
Listing 11.1 Adding a memory variable for player’s death sequence (Megablast.s)
.segment "ZEROPAGE" time: .res 2 lasttime: .res 1 level: .res 1 animate: .res 1 enemydata: .res 10 enemycooldown: .res 1 temp: .res 10 score: .res 3 update: .res 1 highscore: .res 3 lives: .res 1 #1 player_dead: .res 1 #2 #1 Keeps track of how many lives the player has #2 Is the player dead? If so, how far through the death animation sequence are we?
The two variables divide responsibilities: `lives` counts remaining attempts, while `player_dead` records whether—and how far—the death sequence has progressed. section 11.1
Lives are displayed as small ship images in two tile rows at the bottom of the screen. The display draws one ship per remaining life, clears tiles left by a previous larger count, and limits the visible display to eight ships so it stays within the available screen space. section 11.4
Awarding an extra life
Extra lives can reward score progress. Keep a `next_extra_life` threshold, compare it with the score’s thousand digit, then advance the threshold, increment `lives`, and flag the display for refresh when the threshold is passed. section 16.1.2
This makes the counter more than a display value: it controls collision recovery, death animation, level restart, game over, and score-based rewards. Each change also requests a screen update so the visible ships match the stored count. section 11.1 section 16.1.2
