Tiled Platformer Prototype
A Basic Tiled Platformer
Loading...
Searching...
No Matches

1. Introduction

This game is similar to The Top Down Game but there is now gravity pulling the characters down to the bottom of the window, so the horizontal walls now act as platforms. The player character is now a penguin, as shown in the screenshot in Fig. 1.

Fig. 1: A screenshot of The Tiled Platformer.

The remainder of this page is divided into four sections. Section 2 lists the controls and their corresponding actions, Section 3 tells you how to build it, Section 4 gives you a list of actions to take in the game to see some of its important features, Section 5 gives a breakdown of the code, and Section 6 addresses the question "what next?".

2. Controls

Keyboard
Controller
Action
F1
-
Help (this document)
F2
-
Toggle frame rate display
F3
-
Toggle show bounds
A
Digital pad left Walk left
D
Digital pad right Walk right
W
Digital pad up Jump
Backspace
-
Restart game
PrtScr
-
Save screenshot to a PNG file
Esc
-
Quit game and close the window

3. SAGE

This code uses SAGE. Make sure that you have followed the SAGE Installation Instructions. Navigate to the folder 3. Tiled Platformer in your copy of the sage-games repository. Run checkenv.bat to verify that you have set the environment variables correctly. Open Tiled Platformer.sln with Visual Studio and build the Release configuration. The Release executable file Tiled Platformer.exe will appear. Alternatively, run Build.bat to build both Release and Debug configurations.

4. Game Play

Run Tiled Platformer.exe and do the following.

  1. Use the controls (see Section 2) to go to the door at the top left platform. The game will then restart.
  2. Try jumping into the bottom and sides of a platform to see what happens. Also try hitting the corner of a platform.
  3. Move the penguin so that the horizontal center of the sprite is above the edge of a platform (see Fig. 2). Now move it slightly over the edge of the platform by tapping the appropriate key lightly to see the penguin slide gracefully off the platform.
  4. Run into the saw blade to the right of the player (see Fig. 1) to experience death. Try both walking and jumping onto it. See what happens in God mode.
  5. Jump or fall from a high platform to experience death. See what happens in God mode.

Fig. 2: The penguin at the edge of a platform.

5. Code Breakdown

Open Tiled Platformer.sln in Visual Studio and examine the code in the editor while you read the rest of this section. This section assumes that you have read and understood the documentation from SAGE, The Blank Game, The Top Down Game, and The Top Down Tiled Game.

How does this code differ from that of the The Top Down Tiled Game? Firstly, there are a lot of minor changes to take account of the fact that our player sprite doesn't need a center offset and that there aren't any NPCs or any shooting.

CObject is used for the door and the saw and CPlayer, which is derived from CObject, is used for the player. In CPlayer::Move, a constant times the frame time is added to CPlayer::m_vVelocity to simulate acceleration due to gravity. As in The Top Down Tiled Game's CBullet::Move function, a constant times frame time times CPlayer::m_vVelocity is then added to CPlayer::m_vPos. CPlayer::CollisionResponse is now more complicated, for example, it sets a Boolean variable CPlayer::m_bOnGround to true if the player is on top of a platform, that is, the collision normal points vertically upwards. CPlayer::m_bOnGround is set to false at the end of CPlayer::Move (since it may have moved off a platform), then corrected in CPlayer::CollisionResponse and is used in those functions, also in CPlayer::Draw to select between the jumping and other player sprites, and in CPlayer::SetAction to prevent double-jumping.

6. What Next?

Next, take a look at the 2.5D Side Scroller.