Pygame and Python

Pygame and Python

  • mdo  DigitalBox
  •   Gaming
  •   January 3, 2025

Pygame is a Python module designed to facilitate the writing of games and has the advantage of being cross platform.

This module is written on top the SDL library and is available on Haiku.

If you're comfortable with Python and would like to write games, read carefully this article :)

Installation

On a fresh new Haiku system, if you would like to use the Pygame module, you need to install it first.

In a Terminal, type the below command :

pkgman install pygame_python310

Excellent, you are now ready for the adventure !

Learning

If you already know the Python language but are new to Pygame, there's a very good tutorial to learn you the basics.

The advantage of this tutorial is that - at the end - you will be able to play your first platform game... written by you :)

If you're interested, go to the Coders Legacy website at the URL below :

https://coderslegacy.com/python/pygame-platformer-game-development/

If you follow the various chapters until the end, you will be able to play this simple but efficient game :

You may ask now : is there any game on Haiku written with the Pygame module ?

The answer is yes :)

MonsterZ on Haiku

The game can be installed via Haiku Depot :

It's a puzzle game where the goal is to create rows of similar monsters, either horizontally or vertically :

If you select the classic game mode, you will start with the below screen :

If you would like to learn how this game is created, you can download the Python source code at the following URL:

http://sam.zoy.org/monsterz/monsterz-0.7.1.tar.gz

FlappyBird

The FlappyBird game is not directly available on Haiku, however as the source code is available, why not trying it ?

Download the source code by cloning the below github repository :

https://github.com/sourabhv/FlapPyBird

If you have followed the article named "PyCharm Community Edition", launch PyCharm.

Then open the folder where FlappyBird sources are :

Confirm the below with "This Window" :

Then open the "main.py" file :

Run the game :

Yes FlappyBird is working fine !

The aim of this game is to jump the maximum number of tubes like below :

It seems to be simple, but if you give it a try, you will see it's not so easy :)

Going back to PyCharm, the IDE allow code completion on the Pygame API.

Below -on the left- is the flip() method proposed by PyCharm while typing the code, and -on the right- the API documentation available on the official Pygame website :

The code completion is great, in case you have some doubts on which method or which signature to use.

DaFluffyPotato

Now the interesting part.

I repeat : now the interesting part :)

DaFluffyPotato is a game developer who is doing solo indie game development since more than 10 years.

If you would like to see his skills, you can check the DaFluffyPotato website.

He's using a lot Python and Pygame for writing his games, and he has proposed graciously several tiny games with their source code.

Most of the time, these tiny games are available for free, but you can make a donation if you want to thank him.

Let's review some of them, and check if they are working fine on Haiku.

Lollipop Ninja

In this game, you are a ninja who try to get the lollipop on the various levels, and you hates being looked at.

You need to make sure nobody can stare at you while you search for the lollipop.

What a simple and great scenario :)

The gameplay is really great, and you can jump between walls like below :

This game was originally made in 48 hours for the 2nd Alakajam solo game development competition.

Really impressive.

Cavyn

Cavyn is a simple and nice game where the aim is to not get crushed while the cave collapses.

I find the graphics nicely done and the gameplay is really really good :

You can give it a try on Haiku to verify by yourself.

Aeroblaster

Aeroblaster is a platformer shooter.

Your objective is to shoot the cores while avoiding the projectiles.

Like in the previous games, physics and collisions have been nicely implemented.

Lynez

What a strange game.

It's a about a bouncing ball, and you need to build a continuous platform to make the ball raising the maximum height.

Simple but great idea :)

Wandering Soul

In this game you are going through underground ruins and try to avoid death.

What is interesting here, is that you have a mode where your soul goes outside your body, so that it will allow you to reach additional areas.

If you want to know more on the "behind the scenes" for this python game, you can check the below video: https://www.youtube.com/playlist?list=PLX5fBCkxJmm0YsJoS6JhVARnduNmcJ5I3

Shifting Edge

Now the last game I will talk about.

Shifting Edge is an action game where you destroy monster bushes :

What is interesting in this game, is the way the level is visible.

It's not displayed in one shot, but instead the cubes of the world are rendered progressively : once a cube must appear in the game, there's a nice animation from the bottom of the world until the floor.

Maybe it's a little bit hard to explain, but you can check the corresponding video on DaFluffyPotato's website to see the graphical effect.

It's really great to have the source code provided, because it means you can learn many things for your own games.

Below is the game launched from PyCharm:

If you would like to test the remaining games - I've got 15 of them running fine on Haiku - you can check the following URL : https://dafluffypotato.itch.io/

Moving forward

All I can say is that, if you are a talented developer, you can create responsive and great 2D games under Haiku up to Python and Pygame.

You can for sure keep on using Haiku API and SDL in C++, if it's your preferred programming language.

For more information on the Pygame API, you can check the official documentation on this website: https://www.pygame.org/docs/

Happy game writing under Haiku :)


Powered by Bludit - Hosted by Planet Hoster
© 2025 Haiku Insider