ze game
This commit is contained in:
36
asteroid.py
Normal file
36
asteroid.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import pygame
|
||||
from circleshape import CircleShape
|
||||
from constants import *
|
||||
import random
|
||||
|
||||
class Asteroid(CircleShape):
|
||||
|
||||
def __init__(self, x, y, radius):
|
||||
super().__init__(x, y, radius)
|
||||
|
||||
def draw(self, screen):
|
||||
pygame.draw.circle(screen, pygame.Color(255, 255, 255), 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
|
||||
|
||||
angle = random.uniform(20, 50)
|
||||
|
||||
new1 = Asteroid(self.position.x, self.position.y, self.radius - ASTEROID_MIN_RADIUS)
|
||||
new1.velocity = self.velocity
|
||||
new1.velocity = new1.velocity.rotate(angle)
|
||||
new1.velocity *= 1.2
|
||||
|
||||
new2 = Asteroid(self.position.x, self.position.y, self.radius - ASTEROID_MIN_RADIUS)
|
||||
new2.velocity = self.velocity
|
||||
new2.velocity = new2.velocity.rotate(-angle)
|
||||
new2.velocity *= 1.2
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user