

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Asteroids
incomplete
2: Collisions
incomplete
3: Shooting
incomplete
4: Rate Limit
incomplete
5: Destruction
incomplete
6: Splitting
incomplete
7: Submit Your Repo
incomplete
This lesson's interactive features are locked, please to keep using them
You may have noticed that you can fly through asteroids without any consequences.
We need collision detection. Now, this is a fairly deep topic, but we're going to keep things simple: we'll treat everything (including our triangular ship) as a circle when it comes to collisions.
Detecting a collision between two circles is simple:
r1 and r2.distance is less than or equal to r1 + r2, the circles are colliding. If not, they aren't!Everything that collides inherits from CircleShape, so that seems like a good place to write our collision logic. We also want to log when collisions happen, so we'll use one more function from that logger.py module.
Each CircleShape has a position property that is a pygame.Vector2. You can use the position's distance_to method to get the distance between the two shapes, then use that distance to decide whether to return True or False.
It's okay for asteroids to simply pass through each other for now.
If that worked, run and submit the CLI tests.