This page contains a Flash digital edition of a book.
GAME DESIGN // 2D PLATFORMERS| BUILD


ONE-WAY PLATFORMS One-way platforms are platforms that you can step on, but can also jump through from below. In other words, they count as an obstacle if you’re already on top of them, but are otherwise traversable. That sentence is the key to understanding their behaviour. The algorithm changes as follows: • On the x axis, the tile is never an obstacle. • On the y axis, the tile is only an obstacle. if, prior to the movement, the player was entirely above it (that is, the bottom-most coordinate of player was at least one pixel above top-most coordinate of the one-way platform). To check for this, you will probably want to store the original player position before doing any stepping. • It might be tempting to have it act as an obstacle if the player’s Y speed is positive (that is, if the player is falling), but this behaviour is wrong; it’s possible for the player to jump so he overlaps the platform, but then falls down again without having his feet reach the platform. In that case, he should still fall through. • Some games allow the player to ‘jump down’ from such platforms. There are a few ways to do this, but they are all relatively simple. You could, for example, disable one- way platforms for a single frame and ensure that y speed is at least one (so he’ll be clear of the initial collision condition on the next frame), or you could check if he’s standing exclusively on one-way platforms, and, if so, manually move him one pixel to the bottom.


LADDERS


Ladders might seem complicated to implement, but they are simply an alternate state when you’re in a ladder; you ignore most of the standard collision system, and replace it with a new set of rules. Ladders are typically one tile wide. You can usually enter the ladder state in two ways: • Have your character hitbox overlap with the ladder, either on the ground or in the air, and hit up (some games also allow you to hit down). • Have your character stand on top of a ‘ladder top’ tile (which is often a one-way platform tile as well, so you can walk on top of it), and hit down.


This has the effect of immediately snapping the player’s x coordinate to align with the ladder tiles, and, if going down from the top of the ladder, move the y coordinate so the player is now inside the actual ladder. At this point, some games will use a different hitbox for the purposes of determining whether the player is still on the ladder. Mega Man, for example, seems to use a single tile (equivalent to the top tile of the original character, highlighted in red in the image bottom-left). There are different ways to leave the ladder: • Reaching the top of the ladder. This will usually prompt an animation and move the player several pixels up in Y, so he’s now standing on top of the ladder.


• Reaching the bottom of a hanging ladder. This will cause the player to simply fall, although some games won’t let the player leave the ladder in this way. • Moving left or right. If there is no obstacle on that side; the player may be allowed to leave that way. • Jumping. Some games allow you to release the ladder by doing this.


While on the ladder, the character’s


movement changes so, typically, all he can do is move up and down, and maybe attack.


STAIRS Stairs are a variation of ladders, seen in few games, but notably in the Castlevania series. The actual implementation is very similar to that of ladders, with a few exceptions: • The player moves tile by tile or half-tile by half-tile (as in Dracula X) • Each ‘step’ causes the player to be shifted simultaneously on X and Y coordinates, by a pre-set amount. • Initial overlapping detection when going up might look on the tile ahead instead of just the current overlap one. Other games also have stairs that behave like slopes. In that case, they are simply a visual feature.


MOVING PLATFORMS Moving platforms can seem a little tricky, but are actually fairly simple. Unlike normal platforms, they cannot be represented by fixed tiles (for obvious reasons), and instead should be represented by an AABB; that is, a rectangle that cannot be rotated. It is a normal obstacle for all collision purposes, and if you stop here, you’ll have very slippery moving platforms (that is, they work as intended, except that the character does not move along it on his own).


There are a few different ways to implement that. One algorithm is as follows: • Before anything on the scene is stepped, determine whether the character is standing on a moving platform. This can be done by checking, for example, whether his centre-bottom pixel is just one pixel above the surface of the platform. If it is, store a handle to the platform and its current position inside the character. • Step all moving platforms. Make sure that this happens before you step characters. • For every character that’s standing on a moving platform, figure out the delta-position of the platform, that is, how much it has moved along each axis. Now, shift the character by the same amount. • Step the characters as usual.


OTHER FEATURES Other games have more complicated and exclusive features. The Sonic the Hedgehog series is notable for this. Those are beyond the scope of this article (and my knowledge, for that matter), but might be subject of a future article.


Check back next month for part two of this special feature, where you’ll learn more on the nuance of platforming game design, and gain an understanding of two more implementation approaches


DEVELOP-ONLINE.NET Moving platforms require a special effort to make them workable


Castlevania: Dracula X and its stairs, with tile boundaries


Sonic the Hedgehog demonstrating its complicated platform features, which require skilled implementation


Rodrigo Braz Monteiro designs and programs games, and has done so since 1997. He currently resides in London, UK, working for Bossa Studios as a game developer. He is also a member of the indie group Studio MiniBoss. More of his writing is available at his personal website higherorderfun.com.


JULY 2012 | 59


Page 1  |  Page 2  |  Page 3  |  Page 4  |  Page 5  |  Page 6  |  Page 7  |  Page 8  |  Page 9  |  Page 10  |  Page 11  |  Page 12  |  Page 13  |  Page 14  |  Page 15  |  Page 16  |  Page 17  |  Page 18  |  Page 19  |  Page 20  |  Page 21  |  Page 22  |  Page 23  |  Page 24  |  Page 25  |  Page 26  |  Page 27  |  Page 28  |  Page 29  |  Page 30  |  Page 31  |  Page 32  |  Page 33  |  Page 34  |  Page 35  |  Page 36  |  Page 37  |  Page 38  |  Page 39  |  Page 40  |  Page 41  |  Page 42  |  Page 43  |  Page 44  |  Page 45  |  Page 46  |  Page 47  |  Page 48  |  Page 49  |  Page 50  |  Page 51  |  Page 52  |  Page 53  |  Page 54  |  Page 55  |  Page 56  |  Page 57  |  Page 58  |  Page 59  |  Page 60  |  Page 61  |  Page 62  |  Page 63  |  Page 64  |  Page 65  |  Page 66  |  Page 67  |  Page 68  |  Page 69  |  Page 70  |  Page 71  |  Page 72  |  Page 73  |  Page 74  |  Page 75  |  Page 76  |  Page 77  |  Page 78  |  Page 79  |  Page 80  |  Page 81  |  Page 82  |  Page 83  |  Page 84