0 XP
Chapter 10

Collision Detection

Detect when sprites touch — the heart of game physics.

Core Concept

pygame.sprite.spritecollide() checks if a sprite overlaps with any sprite in a group.

Theory

Check if player hits any enemyhits = pygame.sprite.spritecollide(player, enemies, False) if hits: health -= 10 Kill enemy on bullet hitpygame.sprite.groupcollide(bullets, enemies, True, True) first True = kill bullet, second True = kill enemy

Live Demo — Run & Explore

Try it live
Loading...

Output will appear here…

Exercise 1 / 1

📝 Build a simple dodge game: player moves, enemies move left, if enemy hits player print 'HIT!'

Your solution
Loading...

Output will appear here…

Sprites & Images