More complex platformer

One frquent request from students in 2017/18 was that the sample platformer (included earlier) was fine, but a real platformer involved a large scene that the player moved through. This is me answering that call. I have a video on my youtube channel that walks through the full process of making this and explaining the logic at key parts: https://youtube.com/pbaumgarten

That said, I’ve still left plenty for you to do to complete this game. I’ve only used the pygame shapes, so it still needs sprites and sound effects amongst other things. Also some of the player event detection could be improved (so the player can’t jump up through a platform for instance).

Screenshot of final game

Step 1: Design

In creating a more complex platformer the first step was to design the level that I wanted. To do this I turned to traditional paper and pen. I taped 5 A3 sheets together and spent am hour and half drawing my scene. The result can be sseen below.

Picture of level design

Just to show the level of detail, every platform, wall and firepit had their individual coordinates measured out as you can see in this zoom in:

Zoom in on level design

Step 2: Code the level

I took all the coordinates from the drawing and created a file called levels.py and created several lists containing the coordinates of all the platforms, firepits, walls and coins. An excerpt of that file is below … You’ll have to create your own equivilant of this before you can move onto step 3.

Note: That I converted all these coordinates to millimeters. This turned out to be quite important to provide the level of fine-grained accuracy and movement that you want in game play.

### File:               levels.py
### Grid dimensions:    1710 x 400 millimeters

platforms = [
    [100, 60, 50, 10], 
    [300, 240, 30, 10], 
    [410, 370, 80, 10], 
    [590, 210, 120, 10], 
    [940, 380, 220, 10], 
    [1000, 70, 130, 10], 
    [1510, 40, 10, 10], 
    [1520, 270, 20, 10] 
]

firepits = [
    [100, 310, 30, 10], 
    [340, 380, 50, 10], 
    [720, 210, 80, 10], 
    [1470, 390, 140, 10]
]

walls = [
    [330, 310, 10, 70], 
    [1160, 310, 10, 40]
]

coins = [
    [ 100,  40,  10,  10], 
    [ 100,  160,  10,  10], 
    [ 460,  350,  10,  10], 
    [ 1070,  360,  10,  10], 
    [ 1390,  370,  10,  10], 
    [ 1490,  210,  10,  10], 
    [ 630,  190,  10,  10], 
    [ 1250,  130,  10,  10]
]

goal = [[1580,  30,  10,  10]]

Step 3: Main game code

With the hard work done, it was now simply a matter of writing some Pygame code that used the coordinates. Because all the coordinates are based on rectangles, it makes it really easy to see if the player is touching a wall, firepit or platform.