liveBook · Manning

Animate_stars

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

animate_stars is a Megablast function that alternates the graphical patterns displayed at stored star locations.

animate_stars makes stored stars twinkle by alternating the tile pattern written to each star location. It checks the time counter, updates only on selected ticks, and writes through the PPU during the NMI update. section 13.2.1

The function follows a small update loop:

  • Use the time counter to decide whether this update should run. section 13.2.1
  • Read each stored VRAM address and skip processing when the location is empty. section 13.2.1
  • Select one of two star patterns from the time counter and write it to PPU_VRAM_IO. section 13.2.1
  • Call the function from NMI, then clear stored locations when returning to the title screen. section 13.2.1

Twinkling stars

After compiling and running in the emulator, the game places 10 stars randomly and alternates their two graphical patterns, making them appear to twinkle. section 13.2.1

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

How deep it goes
Explains timing, address validation, PPU writes, looping, and title-screen cleanup, but not the underlying tile graphics.
Examples
Uses 10 randomly positioned stars that alternate between two graphical patterns in an emulator.
What it assumes
Assumes star locations and patterns already exist, while demonstrating the update loop and screen-reset cleanup.
What you can do after
Build it from scratch by storing star locations, selecting patterns from time, and updating each location through the PPU.
How it connects
Connects time counters, VRAM addresses, PPU writes, NMI, tile patterns, and title-screen state.

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.