feat: complete the game
This commit is contained in:
+38
@@ -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
|
||||
Reference in New Issue
Block a user