In this project, we will transform our animation created in Challenge 7 into a game by adding a score and collision detection. We will cover the following:
Transform your animation into an interactive game! Add a scoring system with a visible score label, and implement collision detection.
This code initialises a score variable, sets up a font for the score label, constructs the score label, and then displays it on the screen using the blit command. This way, players can easily track their scores while enjoying your game!
Collision detection is the process in video games where the system checks if two objects, like a player and an obstacle, overlap or collide in the game world.
As part of this project, we will define two types of collision.
For the Mouse Click Collision, we will click with the mouse on the balloon. This logic should be placed inside a for loop, and we'll add a MOUSEBUTTONDOWN condition. Here's how you can implement it:
For the Object Interaction Collision, we will move the boy up, down, left, and right, attempting to pick up the rolling ball. Once the boy's picture touches the ball picture (i.e., they overlap), this piece of code should be placed outside the for loop. Here's the code snippet:
Here's the final game code:
You have submitted this project.