summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--asteroid.py17
-rw-r--r--main.py11
3 files changed, 29 insertions, 2 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1ced1a5
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# Asteroids Game
+
+This is a game of Asteroids, created with the help of the guided project course on boot.dev \ No newline at end of file
diff --git a/asteroid.py b/asteroid.py
index 3ab16d9..b59f3ff 100644
--- a/asteroid.py
+++ b/asteroid.py
@@ -1,4 +1,6 @@
+import random
from circleshape import *
+from constants import *
class Asteroid(CircleShape):
def __init__(self, x, y, radius):
@@ -9,3 +11,18 @@ class Asteroid(CircleShape):
def update(self, dt):
self.position += self.velocity * dt
+
+ def split(self):
+ self.kill()
+ if self.radius <= ASTEROID_MIN_RADIUS:
+ return
+ rand_angle = random.uniform(20, 50)
+ new_radius = self.radius - ASTEROID_MIN_RADIUS
+ a = self.velocity.rotate(rand_angle)
+ b = self.velocity.rotate(-rand_angle)
+ asteroid = Asteroid(self.position.x, self.position.y, new_radius)
+ asteroid.velocity = a * 1.2
+ asteroid = Asteroid(self.position.x, self.position.y, new_radius)
+ asteroid.velocity = b * 1.2
+
+
diff --git a/main.py b/main.py
index 2a2328d..8b94acb 100644
--- a/main.py
+++ b/main.py
@@ -1,4 +1,5 @@
import pygame
+import sys
from constants import *
from circleshape import *
from player import *
@@ -32,19 +33,25 @@ def main():
for event in pygame.event.get():
if event.type == pygame.QUIT or pygame.key.get_pressed()[pygame.K_q]:
return
+
screen.fill("black")
for obj in updatable:
obj.update(dt)
+
for asteroid in asteroids:
+
for bullet in shots:
if bullet.collision_check(asteroid):
bullet.kill()
- asteroid.kill()
+ asteroid.split()
+
if asteroid.collision_check(player):
print("Game over!")
- return
+ sys.exit()
+
for obj in drawable:
obj.draw(screen)
+
pygame.display.flip()
dt = clock.tick(60) / 1000