liveBook · Manning

Score

As explained in Classic Game Programming on the NES: Make your own retro video game

A numerical measure of a player's progress or performance in a game.

A player score records progress in the shoot-em-up by awarding points for destroyed enemies and supporting score changes during play. section 1.1 section 10.0

Implement the score as a small NES game subsystem:

  • Reserve three zero-page bytes, storing values from 0 to 99 so each byte represents two score digits. section 10.1
  • Use the three bytes for scores from 0 to 9,999,990, adding more bytes when a game needs a higher range. section 10.1
  • Reserve an update flag so the NMI routine redraws the score only after it changes. section 10.1
  • Reset all three score bytes when a new game starts, before displaying the game screen. section 10.1
Listing 10.1 Adding storage for the player’s score (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         #1
update: .res 1        #2
#1 Player’s current score
#2 Flag so we know when the score has changed

The storage declaration shows the score bytes and the flag that marks pending screen updates. section 10.1

Add points with an 8-bit routine: update the lowest byte, subtract 100 on overflow, carry 1 into the next byte, and repeat. Mark the score changed afterward. section 10.2

Awarding points for a hit

When collision detection confirms that a bullet hit an enemy, erase both objects, clear the enemy data flag, and call add_score with 2, representing 20 points. section 10.2

The third byte also wraps after 99; excess points are ignored so the score returns to zero without display corruption or a crash. The routine assumes no single addition exceeds 99. section 10.2

How Classic Game Programming on the NES: Make your own retro video game covers it

How deep it goes
Implements storage, reset logic, overflow propagation, update signaling, and collision-triggered awards, but only sketches display handling.
Examples
Uses enemy hits for rewards, enemy landings for penalties, three score bytes, and an update flag.
What it assumes
Assumes collision detection and 6502 assembly context while introducing score storage and arithmetic within the NES game.
What you can do after
Build it from scratch by storing, resetting, incrementing, carrying, and flagging a three-byte NES score.
How it connects
Links score updates to collision detection, zero-page memory, and the NMI routine.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Game Programming on the NES: Make your own retro video game. The section links point to the parts of the book it draws on.