Movement patterns

Tiles, pixels and vectors

The pacman screen consists of 28 x 36 "tiles" which are 8 x 8 characters.  The number of pixels is then 224 x 288.  Each character has a 2-byte XY value for their current and next tile as well as a pixel XY position.  The tiles are used primarily when it comes to deciding in what direction a character moves.

Each character also has a current and next vector.  This is an XY pair which is determines the direction of movement.  The "origin" is the top right corner. Finally each character has a "target" tile which is the tile they are trying to get to. A table at location #32ff contains two copies of the vectors as follows:
direction X vector Y vector
Right -1 0
Down 0 1
Left 1 0
Up 0 -1
A current and next orientation flag is maintained for each character. Adding 1 to the orientation flag rotates the character orientation clockwise. Characters continue moving in their current orientation until they hit a maze wall or are told to reverse direction. The function findBestOrientation_2966 finds the best orientation for a character by trying each orientation in a clockwise direction. It calculates the distance from the current tile with the a trial orientation vector to the target tile and chooses the orientation that would result in moving to a tile that is closer to the target. Target tiles The target tile for a character depends on the "mode" of the character. Ghosts always have a target and pacman has a target tile when in the demo mode. The modes are:
  • Scatter - each ghost targets a tile off the screen near their home current
  • Chase - each ghost chases pacman using a different algorithm
  • Frightened - no target, just random movement
  • Dead - the target is the ghost house

Pacman in demo mode has two possible targets depending on whether or not Blinky is edible.  If Blinky is edible, pacman chases Pinky by using Pinky's tile as his target tile.  If blinky is not edible, pacman generates a target tile which is the opposite direction from Pinky.  For example, if Pinky is 4 tiles above pacman and 3 tiles to the left, then pacman will target a tile that is 4 tiles below and 3 tiles to the right,  effectively running away from Pinky.  The position of the other ghosts is not factored into demo pacmans movements.

There is a very thorough explanation of the character movement algorithms in the pacman dossier here.

Movement speed

Each of the ghosts and pacman himself have movement patterns to determine primarily their speed. The values that drive the speed are simple 32-bit constants in ROM. These movement patterns are rotated by one bit each clock cycle (60Hz). If the bit in the 16th bit position (& 0x10000) is a zero then no movement occurs, otherwise the character moves by one pixel. 

Pacman has two move patterns - "normal" and "powerup". In addition, pacman pauses for one clock when eating a pill and for 6 clocks when eating a powerup.

Each of the ghosts has three movement patterns - "normal", "edible" and "tunnel". Ghosts move more slowly when they are edible and very slowly when they are in the tunnel.  There is also another state "dead" in which the ghosts' eyes move at top speed back to the ghost house.  There is no movement pattern for this as it is always at full speed.

In addition to the ghost movement patterns, blinky has two additional move patterns known as "cruise elroy" modes. CRUISE_ELROY_MODE_1 is set when the value PILLS_REM_DIFF1 is less than 229 minus the pills eaten in this level.  CRUISE_ELROY_MODE_2 is set when the PILLS_REM_DIFF2 count is less than 229 minus the pills eaten count.   For the first level these values are 20 and 10 pills respectively but they increase gradually up to 140 and 70.  So Blinky gets faster earlier the higher the level. In addition, when CRUISE_ELROY_MODE_1 is set, Blinky continues chasing even when the ghosts are in "scatter" mode.

ROM configuration tables

A table at address #0796 contains 21 entries of 6 bytes. The meaning of each of the 6 bytes is: 
  • byte 0 - move pattern. 
    • Starts at 3 and increases to 6 
  • byte 1 - relative difficulty.
    • This value varies between 0 and 2 but doesn't seem to be used anywhere
  • byte 2 - leave home counter index 
    • A table at 0843 contains actual counters.
    • Value is 1 for level 1, 2 for level 2 and 3 for all other levels. 
    • entry 3 is all zeros so ghosts leave the house immediately
  • byte 3 - pills remaining difficulty. 
    • A table at 084f contains these.
    • Number of pills remaining before Blinky goes into cruise Elroy mode
    • Starts at 0 and increases to maximum 7 
  • byte 4 - ghost edible time.
    • Index into table at 0861.
    • Starts at 2 and increases to 8 
  • byte 5 - leave home units index
    • Index into table at 0873.
    • 0 for levels 1 and 2, 1 for levels 3 and 4 and 2 for all other levels

Move pattern speed analysis


The move pattern values for level 1 are as follows:

bit pattern character effect bit count speed percent
55 2a 55 2a pacman normal 14 of 32 44%
55 55 55 55 pacman powered 16 of 32 50%
55 2a 55 2a blinky difficulty2 14 of 32 44%
52 4a a5 94 blinky difficulty1 13 of 32 41%
25 25 25 25 ghost normal 12 of 32 37.5%
22 22 22 22 ghost edible 8 of 32 25%
01 01 01 01 ghost tunnel 4 of 32 12.5%

Whereas the most difficult move patterns are as follows:

 
bit pattern character effect bit count speed percent
d5 6a d5 6a pacman normal 18 of 32 56%
d5 6a d5 6a pacman powered 18 of 32 56
b6 6d 6d db blinky difficulty2 21 of 32 66%
6d 6d 6d 6d blinky difficulty1 20 of 32 62.5%
d6 5a ad b5 ghost normal 19 of 32 59%
48 24 22 91 ghost edible 9 of 32 28%
92 24 92 24 ghost tunnel 10 of 32 31%

As can be seen, the ghosts normal speed is faster than pacman before he eats any pills!

No chase areas

There are a few areas of the maze that are marked with a different colour to the rest.  Colour 0x1b is used to mark the tunnel which as above slows the ghosts down.  Colour 0x1a is used to create two guard bands, one above the ghost house and one around the pacman start position.  When the ghosts are in this band, they will not chase Pacman.  This creates an unusual effect where Pacman can "hide" in the location shown below and the ghosts will just circle around him.  



Comments

Popular posts from this blog

Translating pacman into C