diff options
| author | yuzu-eva <stevenhu@web.de> | 2024-09-20 19:21:36 +0200 |
|---|---|---|
| committer | yuzu-eva <stevenhu@web.de> | 2024-09-20 19:21:36 +0200 |
| commit | 294d29c3eaea3f3db1c2134b052ee471c2bf8851 (patch) | |
| tree | 91d4b6dae2d46690b761aa3fbce51dd53f0aadd7 /asteroid.py | |
| parent | 6d45b7245fdaaa0d35e429b69c9ac14ee940a841 (diff) | |
initial push to GitHub
Diffstat (limited to 'asteroid.py')
| -rw-r--r-- | asteroid.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/asteroid.py b/asteroid.py index 3ab16d9..b59f3ff 100644 --- a/asteroid.py +++ b/asteroid.py @@ -1,4 +1,6 @@ +import random from circleshape import * +from constants import * class Asteroid(CircleShape): def __init__(self, x, y, radius): @@ -9,3 +11,18 @@ class Asteroid(CircleShape): def update(self, dt): self.position += self.velocity * dt + + def split(self): + self.kill() + if self.radius <= ASTEROID_MIN_RADIUS: + return + rand_angle = random.uniform(20, 50) + new_radius = self.radius - ASTEROID_MIN_RADIUS + a = self.velocity.rotate(rand_angle) + b = self.velocity.rotate(-rand_angle) + asteroid = Asteroid(self.position.x, self.position.y, new_radius) + asteroid.velocity = a * 1.2 + asteroid = Asteroid(self.position.x, self.position.y, new_radius) + asteroid.velocity = b * 1.2 + + |
