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…
Ask AI Tutor
AI Tutorgemini-3.1-flash-lite-preview
AI
Hi! I'm your AI tutor for Collision Detection. 🎓
Ask me anything about this lesson — what a variable is, why loops are useful, or "why is my code not working?". I'm here to help you understand, not just give you answers!
What's on your mind? 😊