~ Pygame: Challenges and Learn


Introduction -Creating an class based ball game in Pygame and Python - step by step

This tutorial/set of challenges assumes you have worked through Solve and Learn Series 1 to 4, and especially Series 4 which looks at OOP and Class based programming in general. In this series you will be given some code (which works) and then asked to extend its functionality. The answer is of course on the next challenge. You can either follow each challenge through like a tutorial, or try and implement each step yourself as you go along! Teachers wishing to deliver this as a challenge may chose to give students the source code and take them through each step (withholding the solutions)

Understanding OOP concepts and the use of classes

The main characters in this game are all 'balls' but they will help you understand some of the basic principles of game design in pygame. The breakdown of what is included is below:

Using Pygame and Python 3

Python File 1. Create a ball class with a simple sphere (ball1) on the screen (no movement)

Python File 2. Create user key (up, down, left right arrow key) movement for the ball

Python File 3. Add a score variable and add a smaller GREEN ball (ball2) (inherits from the ball class) that randomly moves about the screen. When ball1 touches the green ball, the score increments by +10.

Python File 4. Create a red ball (ball 3) When ball 1 touches the red ball, the score decrements by -10.

Python File 5. Add a "Game over" feature. When the score reaches 1000 (You Win) or when the score reaches -1000 (You lose)

All the best!