Developing PyPlatformer

With this architectural background, we can start crafting the custom components of our platformer game. The Component API may look simple, but it allows us to implement the functionality in a succinct manner.

Creating the platforms

Each platform of our game is nothing but a cube with a static rigid body. However, since we will create several instances with these components, it is convenient to define a class to avoid repeating this kind of instantiation:

class Platform(GameObject):
    def __init__(self, x, y, width, height):
        super(Platform, self).__init__(x, y)
        color = (0.2, 1, 0.5, 1)
        self.add_components(Cube(color, size=(width, height, 2)),
                            BoxCollider(width, height))

Adding pickups

In platformer games, it is common that the ...

Get Python Game Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.