splitting asteroids, game done

This commit is contained in:
2025-07-14 16:19:26 +02:00
parent b78a164429
commit f08ce54456
4 changed files with 38 additions and 1 deletions

View File

@@ -1,5 +1,8 @@
from circleshape import CircleShape
import pygame
import random
from constants import ASTEROID_MIN_RADIUS
class Asteroid(CircleShape):
def __init__(self, x, y, radius):
@@ -11,3 +14,23 @@ class Asteroid(CircleShape):
def update(self, dt):
self.position += self.velocity * dt
def split(self):
self.kill()
if self.radius <= ASTEROID_MIN_RADIUS:
return
else:
angle = random.uniform(20, 50)
rand_angle1 = self.position.rotate(angle)
rand_angle2 = self.position.rotate(-angle)
new_radius = self.radius - ASTEROID_MIN_RADIUS
asteroid1 = Asteroid(self.position.x, self.position.y, new_radius)
asteroid1.velocity = rand_angle1 * 1.2
asteroid2 = Asteroid(self.position.x, self.position.y, new_radius)
asteroid2.velocity = rand_angle2 * 1.2