Part 12 - Collision Detection

This section will cover how do detect collisions between game items such as players, enemies and obstacles.

Detecting Collisions

What to do/hand in?

1. Read and work through "Part 12 - Detecting Collisions".

GitHub solutions are here:

2. Complete the suggestions at the end of each section.

3. You will submit the program along with as many challenges that you can complete for Part 2 - Colliding Rectangles.

Submit:

1. The Python file that you created for "Part 2 - Determining if 2 Rectangles Collide" of the tutorial, including challenges.

      • You may look at solutions to the main part of the tutorial.
      • For 100% you must implement multiple Challenges, and at least one Extra Challenge.
          • If you are not sure what is meant by a description of a challenge, ask Mr. Aldworth.
          • If you have your own ideas for challenges, please do them and explain in a comment what you added so it can be taken into account.
      • It may not be possible to do all challenges as some of them may interfere with one another.
Part 12 - Detecting Collisions.pdf

Hints and FAQ's

1. Detecting Collisions: It is important to mention here that we are not actually using "Sprites" in Pygame in these example programs. We will look at another way of detecting collisions using real Pygame "Sprites" in a later section. Here we use the Pygame Rect (meaning Rectangle) (https://www.pygame.org/docs/ref/rect.html) class to store the location and size data of each character or item that we are going to display. The Rect for each character/item is passed to the blit method, along with the image so that it can be drawn. This Rect class has built in functionality to detect collisions between rectangles along with other built in functionality. See the API for the Rect class for more: https://www.pygame.org/docs/ref/rect.html.