19COLLISION DETECTION

image

Collision detection involves figuring out when two things on the screen have touched (that is, collided with) each other. Collision detection is really useful for games. For example, if the player touches an enemy, they may lose health. Or if the player touches a coin, they should automatically pick it up. Collision detection can help determine whether the game character is standing on solid ground or there’s nothing but empty air beneath them.

In our games, collision detection will determine whether two rectangles are overlapping each other. This chapter’s example program will cover this basic technique. We’ll also look ...

Get Invent Your Own Computer Games with Python , 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.