liveBook · Manning

Enemy type

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

A classification identifying an enemy variant whose behavior can differ from other enemy variants.

An enemy type identifies an enemy variant whose appearance, movement, animation, collision size, score value, and sprite attributes can differ from other variants. A ROM definition table supplies these values when an enemy is created, while the RAM record stores them for active enemies. section 12.0 section 12.2

Define each enemy type with attributes such as:

  • Starting and ending sprite patterns, plus the number of patterns used for animation. section 12.1
  • Initial horizontal and vertical movement changes. section 12.1
  • Score value, collision width and height, and sprite attributes such as palette selection. section 12.1
  • A type number in each RAM record, allowing spawning and movement code to customize behavior. section 12.2
Table 12.1 Enemy definition table (view table figure)

Name

Bytes

Description

Starting shape

1

Starting sprite pattern number

Ending shape

1

Ending sprite pattern number

Patterns

1

Number of patterns (and sprites) used

DX

1

Any starting change in X (we will randomly choose the direction)

DY

1

Any starting change in Y

Score

1

The value added to the player’s score when destroyed

Width

1

The width of our enemy for collision detection

Height

1

The height of our enemy for collision detection

Attributes

1

The sprite attributes to use (mainly used here to set the palette)

Use the enemy definition table as the compact schema for the nine-byte ROM record assigned to each type. section 12.1

Type identifiers in active enemy data

The tracking table records enemy type 1 as a large meteor, 2 as a small meteor, 3 as a smart bomb, and 4 as an explosion. Each active enemy uses ten RAM bytes: the type plus the copied definition data. section 12.2

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

How deep it goes
Defines nine ROM attributes and adds a tenth RAM field, while deferring more complex attack patterns to future extensions.
Examples
Uses large meteors, small meteors, smart bombs, and enemy explosions as distinct type records.
What it assumes
Assumes an existing NES game with enemy spawning, movement, sprite patterns, and RAM tables.
What you can do after
Build it from scratch by defining enemy data in ROM, copying it into RAM, and varying movement, appearance, and scoring.
How it connects
Connects enemy spawning, enemy movement, animation, collision detection, sprites, and smart bomb behavior.

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.