2025-07-12 20:04:42 +02:00
|
|
|
from circleshape import CircleShape
|
|
|
|
|
import pygame
|
2025-07-14 16:19:26 +02:00
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
from constants import ASTEROID_MIN_RADIUS
|
2025-07-12 20:04:42 +02:00
|
|
|
|
|
|
|
|
class Asteroid(CircleShape):
|
|
|
|
|
def __init__(self, x, y, radius):
|
|
|
|
|
super().__init__(x,y, radius)
|
|
|
|
|
|
|
|
|
|
def draw(self, screen):
|
|
|
|
|
pygame.draw.circle(screen, (255,255,255), (self.position.x, self.position.y), self.radius)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update(self, dt):
|
|
|
|
|
self.position += self.velocity * dt
|
2025-07-14 16:19:26 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|