Lesson 16: Shooting Aliens โ groupcollide + Fleet Respawn (Matthes Ch 13 ยง5)
Learning Intentions
- Detect bullet-alien collisions with one Pygame function.
- respawn a new fleet when the current one is empty.
Success Criteria
- Bullets destroy aliens on contact (both disappear).
- When the fleet is empty, a new fleet appears.
- I can explain what groupcollide(a, b, True, True) does with those True/True args.
๐ Do Now โ Error of the Day
Predict: pygame.sprite.groupcollide(bullets, aliens, True, True) โ what does it return if 2 bullets hit 3 aliens? (Dict? List? Integer?)
๐ I Do โ Teacher Demo
Live-code _check_bullet_alien_collisions(). Print the groupcollide return value to see it IS a dict. Add the respawn pattern if not self.aliens: ... self._create_fleet().
๐ค We Do โ Build Together
Class wires up collisions. Shoot aliens โ they disappear. Clear the fleet โ new fleet respawns. Pure satisfaction.
๐ You Do โ Your Turn
Tune ship_speed, bullet_speed, alien_speed to find the 'feel' you like. Arcade quests cover groupcollide + respawn patterns.
- Add self._check_bullet_alien_collisions() call after self.bullets.update()
- Inside: pygame.sprite.groupcollide(self.bullets, self.aliens, True, True)
- If not self.aliens: self.bullets.empty() + self._create_fleet()
- Tune speed values โ does the loop feel good?
๐ฎ Practice Quests โ work through these
Loading practice quests for this lesson...
Three tiers โ pick yours
Support
collision code pre-written
Core
write from scratch
Extension
piercing + indestructible alien variants
Extensions
- Piercing bullets: change True, True to False, True.
- Print the collision dict to console to see what groupcollide returns.
๐ Exit Ticket โ Coding Journal
Journal: what did it feel like when your first alien disappeared from a bullet hit?
Evidence of Learning
Playable: shoot aliens, see them disappear, fleet respawns when clear.