feat: complete the game

This commit is contained in:
Stevan Freeborn
2026-05-22 09:34:56 -05:00
parent 6f9672beb5
commit 2ad2dfb6f8
9 changed files with 317 additions and 2 deletions
+38
View File
@@ -0,0 +1,38 @@
import random
import pygame
from circleshape import CircleShape
from constants import ASTEROID_MIN_RADIUS, LINE_WIDTH
from logger import log_event
class Asteroid(CircleShape):
def __init__(self, x: float, y: float, radius: float) -> None:
super().__init__(x, y, radius)
def draw(self, screen: pygame.Surface) -> None:
pygame.draw.circle(screen, "white", self.position, self.radius, LINE_WIDTH)
def update(self, dt: float) -> None:
self.position += self.velocity * dt
def split(self) -> None:
self.kill()
if self.radius <= ASTEROID_MIN_RADIUS:
return
log_event("asteroid_split")
angle = random.uniform(20, 50)
v1 = self.velocity.rotate(angle)
v2 = self.velocity.rotate(-angle)
r = self.radius - ASTEROID_MIN_RADIUS
a1 = Asteroid(self.position.x, self.position.y, r)
a1.velocity = v1 * 1.2
a2 = Asteroid(self.position.x, self.position.y, r)
a2.velocity = v2 * 1.2