Pygame is daunting to look at understand initially. Especially to those uninitiated to programming or just initiated to block based languages like Scratch.
As a part of my work for a summer camp at Curiositygym, Mumbai, I dived into it and here is my walkthrough for all levels from super easy to hard.
We shall write a game to draw circles and rectangles and create walls and things.
The circle can be drawn on key and mouse movements and the circle can be drawn when the mouse moves and also change the colour of the cirlce when space is pressed. Basic event recognition and management will be covered here.
The circles are so powerful that when it comes in contact with the walls/things, it has the special power to destroy it.
Reach till here and you have covered all aspects of pygame and learn why Object-oriented programming is required.
Post this you can write any game you want, strategy, simulations or tile based games.
All this code you can find in the github repository and two additional tile based games with increasing complexity.
- Memory game – Tile based game where you remember the numbers displayed and find pairs.
- Just10 – Tile based game to form pairs of numbers adding up to 10
The tutorial has 19 parts to it:
- Part 1 – pygame building blocks
- Part 2 – Part 2 – Draw shapes
- Part 3 – Draw shapes at random positions on the screen
- Part 4 – Events – Draw the circle wherever the mouse is clicked
- Part 5 – Events- Change the colour of the circle on space key press
- Part 6 – Events – Change colour on key press and draw circles on mouse movement
- Part 7 – Events- Draw circles of different colours at the mouse position on space key press
- Part 8 – Move the circle (up, down, left and right) on key movement
- Part 9 – Add support for WASD keys too
- Part 10 – Detect collision
- Part 11 – OOP Introduced – Detect collision for multiple objects
- Part 12 – Objects as pygame Sprites
- Part 13 – More sprites – Cannons and rockets together!
- Part 14 – Collision of cannons and rockets
- Part 15 – Part 15: Changing the cannon balls to ball images
- Part 16 – Game over screen
- Part 17 – Store scores!
- Part 18 – Add some music and add some spice!
- Part 19 – Add levels, the last leg – using nested lists in python
Go to Part 1 and have loads of fun and learning!