# SPG:Game Objects

### From Sonic Retro

Notes: Research applies to all four of the Mega Drive games, and Sonic CD. If there are any varying differences between the games, this will be covered below.

## Contents

## Bridges

The bridges in Sonic 1, 2 and 3 are known for their dynamic movement as Sonic moves over them. Bridges are set up with a controller object and an array of log objects which the controller object creates, though this can just be an array of values to represent the segments in most engines now. The controller object contains a few variables: There's the length (in segments) of the bridge, which is usually 12, but it can be longer; there's the index of the segment Sonic is standing on, which starts at 0 for the leftmost segment and ends at length-1.

#### Depression Amount

To get the maximum depression amount in pixels (which will end up being the dip of the lowest log, which is the one Sonic is standing on) the bridge controller uses predetermined values for each log.

The values go up in 2s, starting at 2 and continuing to the middle, with the other side being a mirror of the first half. For example, a bridge with length 5 will have the values 2,4,6,4,2 and a bridge with length 6, the values would be 2,4,6,6,4,2.

So the bridges commonly found in Sonic (12 segments in length) would have the values 2,4,6,8,10,12,12,10,8,6,4,2. This value isn't used directly for any log movement, but the current value is chosen from list at the position of the log that Sonic is standing on for use later. We'll call the current value MaxDepression.

#### Calculating the Log Depressions

The Y position of the segments in the bridge depend on the log that Sonic is currently standing on, as so:

Sonic is on the 5th segment, so:

Segment 0 is 1/5 of the way there, so it's Y is the bridge's Y + MaxDepression * sine(90 * (1/5)).

Segment 1 is 2/5 of the way there, so it's Y is the bridge's Y + MaxDepression * sine(90 * (2/5)).

...

Segment 4 is 5/5 of the way there, so it's Y is the bridge's Y + MaxDepression * sine(90 * (5/5)).

Now, working from the other side:

Segment 11 is 1/8 of the way there, so it's Y is the bridge's Y + MaxDepression * sine(90 * (1/8)).

...

Segment 6 is 6/8 of the way there, so it's Y is the bridge's Y + MaxDepression * sine(90 * (6/8)).

(Since we've already calculated segment 4 from one direction, there's no need to do it from the other).

Meanwhile, all these depression values are multiplied by the sine of the angle in the controller object that counts to 90 when Sonic is standing on top, and down to 0 when Sonic gets off, so the depression will smoothly increase with time when Sonic jumps on to the bridge, and then smoothly decrease when he leaves it.

## End of Level Capsules

### Sonic 1 Method

#### Explosion

For 60 steps, every 8 steps, spawn explosion at capsule position plus random x,y offset (Max horizontal offset of 31 pixels, and according to calculations, vertical is the same). At end of those 60 steps, start with the animals

#### Animals

Switch to exploded frame. Spawn 8 animals at capsule position -28x, +32y, horizontally separated by 7, with alarms starting from 154 and decreasing by 8 per animal (animals don't jump out until their alarm reaches zero).

For 150 steps, every 8 steps, spawn animal at random x position amongst the existing animal group (but tighter in, not near edges), with their alarm set to 12.

When all animal objects have disappeared, run Got Through message.

### Sonic 2 Method

#### Explosion

Spawn explosion at lock's position, move lock at +8x, -4y. Wait 29 steps.

#### Animals

Spawn 8 animals at capsule position -28x, +32y, horizontally separated by 7, with alarms starting from 154 and decreasing by 8 per animal (animals don't jump out until their alarm reaches zero).

For 180 steps, every 8 steps, spawn animal at random x position amongst the existing animal group (but tighter in, not near edges), with their alarm set to 12.

When all animal objects have disappeared, run Got Through message.