the game is gamin
This commit is contained in:
31
asteroid.py
Normal file
31
asteroid.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import random
|
||||
import pygame
|
||||
from circleshape import CircleShape
|
||||
from constants import ASTEROID_MIN_RADIUS
|
||||
|
||||
class Asteroid(CircleShape):
|
||||
def __init__(self, x, y, radius):
|
||||
super().__init__(x, y, radius)
|
||||
|
||||
def draw(self, screen):
|
||||
pygame.draw.circle(screen, "white", self.position, self.radius, 2)
|
||||
|
||||
def update(self, dt):
|
||||
self.position += self.velocity * dt
|
||||
|
||||
def split(self):
|
||||
self.kill()
|
||||
if self.radius <= ASTEROID_MIN_RADIUS:
|
||||
return
|
||||
|
||||
new_angle = random.uniform(20,50)
|
||||
new_velocity_1 = self.velocity.rotate(new_angle)
|
||||
new_velocity_2 = self.velocity.rotate(-new_angle)
|
||||
|
||||
new_radius = self.radius - ASTEROID_MIN_RADIUS
|
||||
|
||||
new_asteroid_1 = Asteroid(self.position[0], self.position[1], new_radius)
|
||||
new_asteroid_2 = Asteroid(self.position[0], self.position[1], new_radius)
|
||||
|
||||
new_asteroid_1.velocity = new_velocity_1 * 1.2
|
||||
new_asteroid_2.velocity = new_velocity_2 * 1.2
|
||||
Reference in New Issue
Block a user