don't click here

Sonic 1 / CD / 2 / 3 & Knuckles: Basic breakdown of level designs and collision


    Print

Author Topic: Sonic 1 / CD / 2 / 3 & Knuckles: Basic breakdown of level designs and collision  (Read 22875 times)

0 Members and 1 Guest are viewing this topic.

Offline Thorn

  • wroar
  • Architect emeritus
  • TSC Profile
  • win10 chrome
  • Posts: 1309
  • Former admin, lucid dreamer, lover of burgers
    • View Profile
This post will cover some of the internal mechanics of the classic Sonic games and what quirks arise from their design for the sake of making clearer rules and providing explanation as to why some of TSC's tricks work. If anybody can think of something that needs to be appended or that he/she would like to hear more about, please mention it. Do note that this post isn't for stating level-specific tricks unless they serve as an example of something that needs to be mentioned.



Note: Terminology used within this post is widely used at Sonic Retro and other Sonic hacking sites. Sonic Team may have different terminology. This guide is deliberately dumbed down and may not cover exceptions to the norm, but is largely accurate. This guide is centered around Sonic 1, Sonic CD, Sonic 2 , and Sonic 3 & Knuckles, but most of it can be applied to other games built on a similar structure.

Level design in Sonic 1, Sonic CD, Sonic 2 , and Sonic 3 & Knuckles can be broken down into a combination of things, the most prominent of which are chunks and objects.

Chunks and Divisions Thereof
Level design starts with small 8x8 squares of pixels, typically called tiles. These serve primarily for housing art that is rearranged, flipped, and mirrored throughout the level, and can be set to appear either in front of or behind many objects and the character (an object's tendency to be drawn on top of other things is called its priority). A 2x2 square of tiles in any fashion creates a 16x16 square of pixels called a block. Blocks also have the capacity to be mirrored, flipped, rearranged, etc., and it's here where the level's collision starts to be handled. The next and final step up from here is the chunk, which is 8x8 blocks or 128x128 pixels in Sonic 2 and Sonic 3 & Knuckles and 16x16 blocks or 256x256 pixels in Sonic 1 and Sonic CD. Chunks are never mirrored or flipped: anything that appears so is actually two separate chunks with symmetric designs. Chunks also determine how the collision that is established in blocks is used. Level backgrounds are also made of chunks, but for the purposes of competition on TSC, you won't need to know much about them (although a little knowledge does help explain why the background appears glitchy after you pull off certain tricks that the game didn't intend).

Objects
Take a look at TSC's Sonic & Knuckles maps. With the exception of Mushroom Hill 1 and 2 and Sandopolis 2, the maps lack rings, star posts, badniks, and a slew of other things. These maps only contain the foreground chunks of the level: anything that's missing is an object. Objects still use tiles for art, but they handle collision, movement, and pretty much everything else about them within code specific to that object (although they still use some shared code, such as detecting when they're colliding with blocks and chunks and succumbing to gravity). Many object properties are only considered if the object is on the screen -- taking advantage of this behavior is necessary for several tricks.

In Sonic 1 and 2, objects are set to either get an entry in the respawn table, or to not receive an entry. The respawn table is used to reload objects when appropriate, since they stop being managed as soon as they are off-screen. Objects that require an entry are ones where multiple states need to be remembered that aren't dependent on other conditions of the level: a ring can be either collected or not collected, a monitor or a badnik can be destroyed or not destroyed, etc. Part of the issue with certain charts on TSC is poor respawn decisions on the part of the game designers. Some objects that award points, such as rocks in Hill Top or blocks in Marble, don't remember when they've been destroyed and will revert to their initial state once you move away from them and then put them back on-screen. Sonic 3 & Knuckles has some issues with this as well. If you come across objects that award points infinitely by respawning, check with the rules to make sure that they aren't banned from repeated use.

One object that deserves special mention is the spikes object from Sonic 1. Early revisions of the game were set up so that spikes hurt Sonic in their own special way instead of calling the code that typically hurts Sonic. Since this code was made just for spikes, anybody referring to Sonic 1's spike behavior as a "glitch" or "bug" should be slapped with a large trout.

Level Boundaries and the Camera
Horizontal and vertical level boundaries are defined for every level to prevent the player from moving into the void beyond where the level stops. These values have limits: for example, in Sonic 2 the maximum horizontal distance a level can go is 128 chunks, and the maximum vertical distance is 16 chunks (these values are different in other games, but the concept is the same). When the camera crosses the limit horizontally or vertically, the game simply loops from the beginning. This is how levels such as Metropolis Zone function: the higher and lower vertical level boundaries are set above and below the camera's limits respectively, so reaching the top of the zone brings you to the bottom. This is also why there are areas in levels where you try to move beyond the level's upper boundaries and run into walls: you're bumping into chunks on the bottom of the level. The inverse is true as well: a bottomless pit in line with the bottom of the vertical limit won't kill you if there's a chunk below it or at the level's top due to vertical wrapping, since you'll stand exactly level with it on the bottom of the screen. Horizontal looping can be seen in several tricks in Sonic 3 and Knuckles that send the player beyond the end of the zone, but notice that objects don't loop horizontally.

A screenwrap is performed by utilizing a quirk in the vertical wrapping behavior. On levels that use the same vertical level boundary setup as Metropolis, one can duck to move the camera downwards, then jump off of the screen's top to send the camera scrolling downwards and across the wraparound point in an attempt to find you. Since objects aren't handled unless they're on the screen but block and chunk collision is always handled, you can pass through objects that interfere with your intended route.

Block and Chunk Collision
You've probably noticed that not all "walls" are solid: the same art that's used for a solid wall in Green Hill is also used to show a wall that's "behind" you that you can pass by.

Blocks are assigned a value that tells them which pixels can be make solid and at what angle you move across it. Chunks choose whether or not said pixels actually are solid, and how. There are three main ways collision in a block can be handled:
  • Top Solid: If you land on top of one of the pixels that can be solid, you can stand on it. Often called a one-way floor or a through-floor by gamers, because you can jump up from beneath it and land on top, but not return through it to below. That said, it's possible to cheat your way through these if hit fast enough or at an awkward angle. These blocks are highlighted green on TSC's maps and white in SonED2's collision viewer.
  • Left/Right/Bottom Solid: If you land on top of one of those pixels, it may as well not be solid. If you hit it from the side or bottom, you'll collide with it. These blocks are highlighted red on TSC's maps and yellow in SonED2's collision viewer.
  • All Solid: You'll collide with the pixels no matter how you hit them. In addition, this allows for running on walls provided the angles you've traversed leading up to it have you moving nearly vertically. These tiles are highlighed blue on TSC's maps and black in SonED2's collision viewer.
Note that objects that draw no art can be used to "fake" collision with walls that aren't marked as solid in some areas. Also note that while collision is defined as interacting with level solidity, the terms tend to be used interchangeably.

While cheating through Top Solid blocks is used for a few tricks on TSC, Left/Right/Bottom and All Solid blocks are more interesting, as they allow for zipping a.k.a. wallzipping (although objects can be used to zip too). If you are standing between two tiles with some form of side collision, the game tries to eject you from your spot if you move in the slightest. The ejection is performed in the opposite direction that you try to move (i.e. press right to zip left, and press left to zip right), and it moves you so fast that the game often ends up ignoring other collision in the process, particularly with objects since you can get off-screen from the speed. Hitting the left boundary of a level at zip speeds often causes you to wrap around to the right edge of the level.

Here's a screenwrap-zip combo to try: look at the very center of TSC's Marble Garden 1 map. Find the approximate center of the map, and then zoom in on the big ring just to the lower-right. To the lower-right of that is a blue top object, and to the right of that is a rotating set of platforms with a fire shield item below them. Screenwrap in this area, and maneuver through the fire shield  item to its right side while the camera isn't focuses on you. When the camera returns to you, the fire shield will be on screen, and its collision will be checked. You can zip out from behind it right into the nearby wall. Once in the wall, you can zip again to land on the steep downward slope on the right.

Collision Planes
Once you know how block and chunk collision is set up, this concept is easy. Look at any Sonic 1 map, and you'll notice that the paths never cross. Sonic 1 uses  one plane of collision, so setting up crossing paths is difficult and can only be done in certain ways. Later Sonic games assign two forms of collision to each block in most zones (zones that don't have crossing paths still use only one), and by switching the player between them when appropriate, paths can cross. The invisible object that handles the switching is called a path swapper. Path swappers have the following properties:
  • Length: Some path swappers require you to pass through a small area to trigger them. Others bridge a very large area. It's that simple.
  • Orientation: Path swappers work by passing through them either horizontally or vertically.
  • Collision Plane Switching: As already states, path swappers can put you on different collision planes. This property has two values: one for each direction you can pass through the path swapper.
  • Priority Switching: Path swappers can cause you to abide by the art's settings for when you appear in front of it or behind it, or they can always cause you to appear in front of it. This property has two values as well.
  • Ignore Midair Players: Some path swappers, such as those that make loops function, only act on you if you're walking, running, standing, or rolling -- if you're not hugging a surface, they won't work.
Have you ever approached an area in a Sonic game and found that it suddenly wasn't solid when it usually was, or that you can't pass through it when you usually can? You probably missed a path swapper along the way and are in the wrong collision plane... backing up a little bit and then running to the area again usually fixes the problem, since path swappers are usually found near where a specific collision plane is necessary. Of course, having blocks that aren't solid when they should be can be very beneficial to a speedrunner, so seeking out ways around path swappers is one strategy to finding tricks.

FAQ
Q: Why do objects appear glitchy in debug mode once I reach the boss/signpost? Why does the prison egg look like a garbled mess of item art until I beat the boss?
A: A pattern load cue/queue (depends on who you ask), or PLC, tells the game what art to load into the memory space the game has to store art. Most art is loaded right at the start of the level, but the limited amount of space means that not all of it can be loaded at that time. Boss art and signpost art are loaded as you approach the point where the actual object code is run. This art overwrites art used earlier in the level that won't be seen again since the level is ending. The arrangement of the art data a.k.a. mappings is maintained, but the actual data in place of the old art has changed, or in the case of the prison egg before reaching the boss, not changed.

More to come...?
<RPGnutter> Well I think your reasoning was dumb, so you get sassed
<RPGnutter> Thats how it works

Offline Aitamen

  • TSC Profile
  • win7 firefox
  • Posts: 1130
  • I am a follower of the immortal Dark Falz!
    • View Profile
Only thing I think I know how it works, but I'm still curious about, is the mechanics of the oil, and is it the same as the mechanics of sand in SO?
Year 33 — The Malkavians claim that their greatest practical joke happened during this year, when they perform a bit of graverobbing  in Jerusalem.
-- Vampire: The Masquerade

lol i wouldn't count on any aspect of sonic 2 to mirror exactly that of an aspect of sonic 3/&K. shit's never consistent.

    Print
 

Hits: 12,845 | Hits This Month: 49 | DB Calls: 8 | Mem Usage: 1.06 MB | Time: 0.05s | Printable

The Sonic Center v3.9
Copyright 2003-2011 by The Sonic Center Team.