Difference between revisions of "Beetlejuice (NES)/Game Mechanics and Techniques"

From SDA Knowledge Base

Jump to: navigation, search
(Enemies and objects)
(Enemies and objects)
Line 75: Line 75:
  
 
==Enemies and objects==
 
==Enemies and objects==
 +
===1st boss (Level 1)===
 +
[[File:1st_boss.PNG|75px]]<br  />
 +
* $5E9/$5E8 - Small/Sub x-position of shots
 +
* $5EC/$5EB - Small/Sub x-speed of shots
 +
* $535/$536 - x/y boss
 +
* $5E7 – Shot flag
 +
<br  />
 +
 +
When the shot flag is not set, the RNG function is called every 16 frames, based on the global timer ($3BB). One of the results is compared with 0x46 (instruction $C8F9). If it's less, the boss will shoot a puff of bug spray. Since the player neither knows the global timer, nor the RNG values, shots can be considered random and outside player control with a probability of (1/16)*(72/256) ~ 1/57 per frame.<br  /><br  />
 +
 +
The speed of the puff is either 1 or 2 pixels/frame and with a sub-speed that is a multiple of 0x40 (a sub-speed >0 slows down the puffs). The speed of both components (main and sub) directly depends on $24 (the first RNG-address) and should therefore be equally distributed with no possibility to predict in real-time.<br  />
 +
 +
===2nd boss (Level 2)===
 +
[[File:2nd_boss.PNG|75px]]<br  />
 +
This boss works in essentially the same way as the first one, but with a few different parameters. The ball speed is always 1 pixel/frame (instruction $C95D). The boss kicks a ball based on a check every 16 frames (based on the global timer in $3BB) with a 50% chance (instruction $C93C).<br  />
 +
 +
===3rd boss (Level 3-4)===
 +
[[File:3rd_boss.PNG|75px]]<br  />
 +
* $537 - Magic timer
 +
<br  />
 +
 +
If the boss isn't already casting magic, the game calls the RNG function every second frame. The check that follows has a 5/256 ~ 1/51 chance to pass (instruction $C85A), resulting in the boss casting magic. The duration of the spell is always 22 or 24 frames.<br  />
 +
 
===Delia's art pieces===
 
===Delia's art pieces===
 
[[File:Art_piece1.PNG]] [[File:Art_piece2.PNG]] [[File:Art_piece3.PNG]]<br  />
 
[[File:Art_piece1.PNG]] [[File:Art_piece2.PNG]] [[File:Art_piece3.PNG]]<br  />
Line 112: Line 135:
  
 
===Cavern monsters===
 
===Cavern monsters===
 +
[[File:Cavern_monster.PNG|75px]]<br  />
 +
* $5E9/$5E8 - Small/Sub x-position of shots
 +
* $5EC/$5EB - Small/Sub x-speed of shots
 +
* $5EF/$5EE - Small/Sub y-position of shots
 +
* $5F2/$5F1 - Small/Sub y-speed of shots
 +
* $5F4 – Shoot timer
 +
<br  />
 +
 +
The shoot timer counts down from 0x3F. When it reaches 0, the current shot disappears and a new one appears. The speed (0-4 pixels/frame + sub-pixel speed) depends on Beetlejuice's position and the RNG. The x- and y-speeds are calculated independently. The monsters will always fire in the direction of Beetlejuice. However, when the main x-speed is 0, the sub x-speed can make the shots fly in the opposite direction from Beetlejuice. Those shots will therefore always be slow, while shots in Beetlejuice's direction can be faster.<br  /><br  />
 +
 +
A full disassembly of the direction of shots hasn't been done, but a preliminary investigation did not find any manipulation possibilities.
 +
<br  />
 +
 
===Cloud elevators===
 
===Cloud elevators===
 +
[[File:Cloud_elevator.PNG]]<br  />
 +
* $463 - Elevator counter
 +
* $5D - y-position of the elevator currently on screen, an offset of $463
 +
<br  />
 +
 +
$463 runs in the background when entering the house (level 1). When a switch is flipped, the corresponding elevator will teleport to wherever in the cycle $463 is and starts to move from there.<br  />
 +
 
==="Fish in cauldron"===
 
==="Fish in cauldron"===
 +
[[File:Fish_in_cauldron.PNG|75px]]<br  />
 +
* $5B2+X - y-position
 +
* $5A6+X - y-speed
 +
<br  />
 +
 +
Every 16 frames, the game calls the RNG function and calculates a number between 0 and 7. If the number is in the range 0-4 (instruction $AC82) and the corresponding fish is in its cauldron (instruction $AC85), it will initiate a jump of that fish with a set trajectory.<br  />
 +
 
===Flies (overhead sections)===
 
===Flies (overhead sections)===
===First boss===
+
[[File:Fly.PNG]]<br  />
 +
* $5AC/$5B2+X – x/y-window position
 +
* $5BE/$5C4+X – x/y-speed (relative to the window position)
 +
<br  />
 +
 
 +
The flies get a 1 pixel/frame speed change every 4 frames (instruction $A1CB and onwards). The speed is capped at 3 pixels/frame in both directions. The calculation is only based on the RNG. It's therefore difficult to see how their movement could be possible to manipulate in real-time. It's worth noting that the speed is relative to the window position. When Beetlejuice is hit, the flies will only follow the screen during the invincibility period, which can allow for free hits by aligning flies with the swatter.
 +
The RNG is updated before each speed calculation, so each fly moves independently of the others.<br  />
 +
 
 +
 
 
===Flowers===
 
===Flowers===
 
===Football legs===
 
===Football legs===

Revision as of 08:12, 20 March 2023

Animations

Movement mechanics

Time cost comparisons

Scares

Name Cost Shots Special ability Comments
Medusa.png Medusa head 100 1 Freezes "floating skulls" (found in some bug holes)
Birdman.png Birdman 150 2 Increases jump height The jump ability allows for shortcuts and is very useful in a speedrun
Two-headed man.png Two-headed man 200 3 1-hit kills the sandworm on Saturn
Skeleton.png Skeleton 250 5 No damage from bees, 1-hit kills the beehives (both only found in level 1)
Umbrella.png Umbrella head 400 9 None? The manual hints about giving some sort of advantage against the octopuses in the sewer stage
Ogre.png Ogre 500 12 1-hit kills the cavern monsters in level 2 (Storm drains)
Ghost.png Ghost (called "spooksheet" in the game) 600 15 None? Only available in the graveyard level. The manual does not seem to hint about any special ability. It sounds more like it's an "all-purpose" scare with lots of shots.
Snake.png Snakeman 750 19 None? Same comments as for the ghost scare.


RNG

The RNG-addresses in RAM are $24-$27. They're calculated by various operations between themselves and take the result of the previous set of RNG and the global timer ($3BB) as seeds.

The RNG-function is called by various events that require a new set of RNG. This can result in the RNG being calculated from several times per frame to every few frames or not all (if nothing loaded in memory requires RNG-values.

There is no indication that the RNG-values would be possible to manipulate in real-time. In TAS-conditions, the RNG can be manipulated to a certain extent by performing actions that trigger the RNG-function to be called. Beetlejuice's movements don't impact the RNG-function, but e.g. throwing a potion (in the overhead section) will create additional calls of the RNG-function.

Things impacted by RNG

Enemies and objects

1st boss (Level 1)

1st boss.PNG

  • $5E9/$5E8 - Small/Sub x-position of shots
  • $5EC/$5EB - Small/Sub x-speed of shots
  • $535/$536 - x/y boss
  • $5E7 – Shot flag


When the shot flag is not set, the RNG function is called every 16 frames, based on the global timer ($3BB). One of the results is compared with 0x46 (instruction $C8F9). If it's less, the boss will shoot a puff of bug spray. Since the player neither knows the global timer, nor the RNG values, shots can be considered random and outside player control with a probability of (1/16)*(72/256) ~ 1/57 per frame.

The speed of the puff is either 1 or 2 pixels/frame and with a sub-speed that is a multiple of 0x40 (a sub-speed >0 slows down the puffs). The speed of both components (main and sub) directly depends on $24 (the first RNG-address) and should therefore be equally distributed with no possibility to predict in real-time.

2nd boss (Level 2)

2nd boss.PNG
This boss works in essentially the same way as the first one, but with a few different parameters. The ball speed is always 1 pixel/frame (instruction $C95D). The boss kicks a ball based on a check every 16 frames (based on the global timer in $3BB) with a 50% chance (instruction $C93C).

3rd boss (Level 3-4)

3rd boss.PNG

  • $537 - Magic timer


If the boss isn't already casting magic, the game calls the RNG function every second frame. The check that follows has a 5/256 ~ 1/51 chance to pass (instruction $C85A), resulting in the boss casting magic. The duration of the spell is always 22 or 24 frames.

Delia's art pieces

Art piece1.PNG Art piece2.PNG Art piece3.PNG
The following description refers to the art pieces' x-position, the y-position works in an analogue way. The description is applicable to both the objects in room 0x13 and 0x15 (from $55).

Every 16th frame, the RNG function is called and through various calculations updates [$5CA+X]. This address has double purposes. First it determines a base movement of the object for the next 16 frames. This base movement is either move left or stand still. Then through logical manipulations, it adds a number to [$5D0+X] every frame. The new x-position (5AC+X) is then calculated by taking ”move left or standstill” plus if there was a carry in the calculation of the new [$5D0+X].

Several steps have been skipped in the description above, but the end result and conclusion are that the game achieves something similar to a sub-pixel movement. During 16 frames, the art piece will move 0 or 1 pixel every frame, depending on how often the carry is produced in the calculation of [$5D0+X].

With the art pieces' movement at the core relying on RNG, it's difficult to see how any manipulation would be possible.

Beetles (side view levels)

Beetle (side view levels).PNG

  • $41X - position and object occupied
  • $42F+X - Beetle type (0 – 10, 1 – 25, 2 – 50, 3 – 75)


Every 4 frames, the RNG function is called and a result is compared with 0x32 (instruction $A835). If it's smaller, another check is done with a 1/4 chance of passing per active beetle hole on screen (instruction $A83F). A beetle will then spawn from the corresponding hole.

The type of bug is again determined by running the RNG function. The result is this time compared with 0x50 (instruction $A875). If it's smaller, a red beetle (worth 10 vouchers) will spawn. If it's greater, another check is done with equal probability of the remaining 3 types (instruction $A879).

In summary, as long as the three available beetle memory addresses aren't filled, the probability of one of the 3 more valuable types spawning per second and per hole is 15*(48/256)*(1/4)*(166/256) ~ 46%.

Beetles (overhead levels)

Beetle (overhead levels).PNG

  • $60C – Beetle flag
  • $611/$60E/$60D – Big/Small/Sub x-position
  • $610/$60F – Small/Sub x-speed
  • $619/$616/$615 – Big/Small/Sub y-position
  • $617/$618 – Small/Sub x-speed


There is a 75% chance that an enemy drops a beetle (instruction $9E8C, when enemy health goes to 0). Same for all enemy types. There can however only be one beetle at a time (controlled by the beetle flag).

The speed is recalculated every second frame as the current speed and an addition based on a result from calling the RNG function (see e.g. Instruction $BD50).

Cavern monsters

Cavern monster.PNG

  • $5E9/$5E8 - Small/Sub x-position of shots
  • $5EC/$5EB - Small/Sub x-speed of shots
  • $5EF/$5EE - Small/Sub y-position of shots
  • $5F2/$5F1 - Small/Sub y-speed of shots
  • $5F4 – Shoot timer


The shoot timer counts down from 0x3F. When it reaches 0, the current shot disappears and a new one appears. The speed (0-4 pixels/frame + sub-pixel speed) depends on Beetlejuice's position and the RNG. The x- and y-speeds are calculated independently. The monsters will always fire in the direction of Beetlejuice. However, when the main x-speed is 0, the sub x-speed can make the shots fly in the opposite direction from Beetlejuice. Those shots will therefore always be slow, while shots in Beetlejuice's direction can be faster.

A full disassembly of the direction of shots hasn't been done, but a preliminary investigation did not find any manipulation possibilities.

Cloud elevators

Cloud elevator.PNG

  • $463 - Elevator counter
  • $5D - y-position of the elevator currently on screen, an offset of $463


$463 runs in the background when entering the house (level 1). When a switch is flipped, the corresponding elevator will teleport to wherever in the cycle $463 is and starts to move from there.

"Fish in cauldron"

Fish in cauldron.PNG

  • $5B2+X - y-position
  • $5A6+X - y-speed


Every 16 frames, the game calls the RNG function and calculates a number between 0 and 7. If the number is in the range 0-4 (instruction $AC82) and the corresponding fish is in its cauldron (instruction $AC85), it will initiate a jump of that fish with a set trajectory.

Flies (overhead sections)

Fly.PNG

  • $5AC/$5B2+X – x/y-window position
  • $5BE/$5C4+X – x/y-speed (relative to the window position)


The flies get a 1 pixel/frame speed change every 4 frames (instruction $A1CB and onwards). The speed is capped at 3 pixels/frame in both directions. The calculation is only based on the RNG. It's therefore difficult to see how their movement could be possible to manipulate in real-time. It's worth noting that the speed is relative to the window position. When Beetlejuice is hit, the flies will only follow the screen during the invincibility period, which can allow for free hits by aligning flies with the swatter. The RNG is updated before each speed calculation, so each fly moves independently of the others.


Flowers

Football legs

Lights

Mouse

Second boss

Spiders

Sweepers

"Urn with bouncing ball"

Buffered inputs

Glitches

Screen warping in the overhead levels (TAS-only)

Softlocks

Open questions

Brick

Toilet paper

Additional scares with special abilities

Selection of known RAM-addresses

Personal tools