Addressing collisions

To recap, answer the following question: When do we know when two game objects have collided? Do you have your answer? Whenever two objects are in the same location within the coordinate system, they are said to have collided. However, in the case of pymunk, we don't have to check whether a collision has occurred or not. Rather, a single method call will check this for us. For example, a call to space.add_collision_handler(0, 1) will add a collision handler to check whether there has been a collision between the Bird and Pig characters. Here, the 0 integer represents the collision_type that's defined inside the Bird class. The collision_type that's defined for the Pig class is 1. Thus, these collision_type must be unique ...

Get Learning Python by Building Games now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.