Research / Sonic 2 / Collision array and collision index

Collision array and collision index:

*Posted by JoseTheBest.*
*Corrected by Sonic Hachelle-Bee.*

Each sonic game (S1/S2/S3/S&K) has a "main" collision data (usually called collision array), where all the collision blocks used in the game are defined. Then, the collision data for each level just use the possible blocks in the collision array, but that's something that we'll see later. For now, let's look on the collision array.

The collision array:

First, you have to know that the collision blocks are directly applied to the 16x16 tiles of each zone, meaning that each collision block is always 16x16 pixels.

This is basically the table representing a collision block. You probably have noticed that the system looks like X and Y positions. Well, actually, this is even more simple than that. Each block uses 16 ($F) bytes. There isn't any special format in the collision array: the first 16 bytes, the first collision block; the next 16 bytes the second, and so on. But let's look what that 16 bytes mean.

The X position in the table, is just the position of the actual byte. The value of that byte means the Y position. It always create a solid column below the position. In the table, green numbers mean Y value, and blue numbers mean the byte position (or X value) (for now, ignore the grey numbers). For example, if we have this:

00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00

That will create a column in the second position with altitude of 3. Here is a representation of the position:

And because we said that it creates a column below the position, the result in game will be this:

Also, as you can see, a value of 00 create nothing.

Another example more complex this time:

04 05 05 06 06 07 08 08-09 0A 0A 0B 0C 0D 0D 0E

Red boxes mean that these are the actual value of each byte.

Reader: "Okay, and what's about the grey numbers that we have saw before?"

They work like Y positions, but instead of creating a "normal" solid column, it creates one "inverted".

For example:

00 00 00 FE 00 00 00 00 00 00 00 00 00 00 00 00

The position in the table is:

And it creates an inverted column:

That will create the collision, but you have to set to that block the slope effect. This is where the angle data comes. Each byte of this data correspond to one collision block. If the byte is the first, it will take effect on the first collision block in the array. If this is the second, the second block, and so on. The format is simple. To represent the slope just create two imaginary lines. The first nyble of the byte is a point in the left line, and the second in the right line. If you create a line between these points, you will have a representation of the slope. Let's look an example:

Block collision number 04 of Sonic 1:

Now we go to the 4th byte in the angle data in Sonic 1 (see below). It says 90. 9 will be the first point and 0 the second. Here is a representation about that:

That's all about the collision block format and the collision array.

The collision blocks reference for Sonic 2:

Here is just a link to see all collision blocks of Sonic 2:
Sonic 2 collision blocks reference

The collision index:

Instead of using directly the data like in the collision array, each byte of the collision index represents one block from the collision array, and is directly related to the 16x16 tile position. It's easy. If a byte is 00, it means that it will use the first collision block in the collision array (first 16 bytes). If it's 01, it will use the second,...etc.

Reader: "But how the game knows which 16x16 tile use that collision?"

Again very simple. The position of the byte in the collision index, is the position of the tile. I mean, if you use 00 in the first position of the collision index of a level, it will use the block
collision 00 for the first 16x16 tile defined for this level. If it's the second position, the second 16x16 tile. And it continues like that.

Useful addresses:

Now some more info that you maybe want:

Collision Arrays :

Sonic 1 (US version) :
Primary collision array: $62A00
Secondary collision array: $63A00
Angle/curve array: $62900

Sonic 2 :
Collision array: $42E50
Angle/curve array: $42D50

Sonic 3 :
Collision array: $706A0

Sonic & Knuckles :
Collision array: $96100

Collision Indexes :

Sonic 1 (US version) :
GHZ : $64A00
LZ : $64B9A
MZ : $64C62
SLZ : $64DF2
SYZ : $64FE6
SBZ : $651DA

Sonic 2 (Note: Data compressed with Kosinski format) :
Offset index for primary collision indexes: $49E8
Offset index for secondary collision indexes: $4A2C
EHZ and HTZ primary : $44E50
EHZ and HTZ secondary : $44F40
MZ : $45040
OOZ : $45100
MCZ : $45200
CNZ primary : $452A0
CNZ secondary : $45330
CPZ and DEZ primary : $453C0
CPZ and DEZ secondary : $454E0
ARZ primary : $45610
ARZ secondary : $45760
WFZ and SCZ primary : $458C0
WFZ and SCZ secondary : $459A0

Back | Printer friendly
2. Sprites and objects placement >>

© 2004, 2005 drx, Don't copy without permission yadda yadda yadda.