Tuesday, June 20, 2017

Level collision

Solidity information for level terrain is assigned per 16x16 block. Each block picks out from a global collision array that contains the 256 patterns used throughout the entire game. Each pattern is comprised of a 16 pixel-wide "height mask" that defines the shape of the ground, and a slope value which is used to calculate speed, acceleration, and initial jump angle from the given surface.


In turn, for each of their 16x16 blocks, 128x128 chunk definitions have a pair of flags that control their solidity. The first flag makes the block solid from the top, the second flag makes it solid from the sides and from the bottom, and both put together make the block completely solid. SonLVL, a popular level editing program, respectively displays level collision in white, yellow and black, depending on the value of these flags.


Furthermore, each 16x16 block actually picks two collision patterns from the global collision array. By changing which of the two is currently active, the game can essentially set the player on one of two different "paths", which may have distinct solidity. This is what allows loops to work: at the peak of their circumference, the collision is silently swapped, closing off the side from which the player just came, and opening up the path ahead.


Next time, the yellow devil that glues this all together.

No comments:

Post a Comment