Game Making with Python and Pygame Part 1

in #python5 years ago

Getting Set Up with Python and Pygame

gmwithpp-p1.png

Over the years I've delivered various workshops introducing teachers and others to use Pygame to create games. Many recent workshops have included me using PygameZero instead of Pygame, but for this series of posts I think I'll just focus on vanilla Pygame.

Firstly you need an up-to-date install of Python 3. Newer versions allow you to just pip install pygame which definitely works on Linux, probably works on Windows (as long as you've ticked the box to add the Python Path to the Environment variables) and may work on Mac. The key seems to be to upgrade the version of pip that your Python is using.

Once you've ensured that you have a reasonably up-to-date Python (I've just upgraded top Python 3.7.3), we can upgrade pip by doing the following:

sudo -H python3,7 -m pip install --upgrade pip

This may or may not upgrade things depending upon what you've done previously.

If you haven't installed pygame previously then doing some version of the following should install it for you:

sudo -H python3,7 -m pip install pygame

If you've previously installed it and want to check that the newest version (1.9.5 is the most recent version at the time of writing) us installed then do the following:

sudo -H python3,7 -m pip install --upgrade pygame

To check that everything is working, run your new version of python:

python3.7

Then in the Python Shell which opens (you should be able to see the Python version here too), do:

>>> import pygame

Which should show you the following output for a new version of pygame (it didn't before Pygame 1.9.4 I think).

pygame 1.9.5
Hello from the pygame community. https://www.pygame.org/contribute.html

If you see all of this, with no errors then you should be good to go.

We'll leave this first part at that and continue by actually creating a window, in code in the second part of this guide.

Sort:  

Congratulations @amos1969! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You published more than 60 posts. Your next target is to reach 70 posts.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

I will be following along. Do you do any of this on Raspberry Pi?

I have done in the past. If you can get Pygame installed then everything should work. A game I created originally ran really slowly on the Pi, which is when I discovered the clock.tick() method that I cover later on.

Thanks. I am mostly interested in GUI aspects for the Pi programming I hope to start doing, not actually writing a game.

Posted using Partiko Android

I've used PyQt a little in the past, and have taught people to use Tkinter too (although it's painful to use). Have you thought about GUI libraries already?

If you use Pygame to do anything but the most basic aspects of GUI stuff (not game stuff per se) then you end up having to implement all of it. So if you want a button, you have to handle the whole way in which the button functions, as opposed to using a dedicated GUI library which handles this for you.

Thanks, I have been considering Tkinter as it is included and I am jumping between my Linux PC and a bunch of Raspberry Pi's.

Posted using Partiko Android

Laura and Martin who work at the Raspberry Pi Foundation have a beginners GUI library based on Tkinter called GUIZero that might be worth looking at: https://lawsie.github.io/guizero/

Thanks, I will check it out.

Posted using Partiko Android

Coin Marketplace

STEEM 0.20
TRX 0.14
JST 0.030
BTC 68854.36
ETH 3283.36
USDT 1.00
SBD 2.67