O'Reilly logo

Python Game Programming By Example by Joseph Howse, Alejandro Rodas de Paz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required