diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2023-07-30 15:36:09 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2023-07-30 15:36:09 +0530 |
commit | 1a3a0ba4f986b902e9c958cd10d4be95d4c287d5 (patch) | |
tree | cd7ba431da6620c14a1d8878792a43f1da48d307 | |
parent | d3278cf87722518847e79e56572793d9318043c3 (diff) |
customize asteroids
-rw-r--r-- | asteroid.py | 3 | ||||
-rw-r--r-- | game.py | 5 |
2 files changed, 6 insertions, 2 deletions
diff --git a/asteroid.py b/asteroid.py index 1735c8b..dd80433 100644 --- a/asteroid.py +++ b/asteroid.py @@ -7,6 +7,9 @@ class Asteroid: self.y = 60 # Starting y position at the top self.speed_y = random.randint(1, 3) # Random downward speed + self.width = 92 + self.height = 92 + # Load asteroid image self.asteroid_image = pygame.image.load('res/asteroid.png') @@ -40,7 +40,7 @@ class MyGame: self.cockroaches.append(Cockroach()) # Spawn a new asteroid randomly - if len(self.asteroids) < 5 and random.random() < 0.02: + if len(self.asteroids) < 2 and random.random() < 0.016: self.asteroids.append(Asteroid()) def move_objects(self): @@ -101,7 +101,7 @@ class MyGame: for asteroid in asteroids_to_remove: # TODO: GAME OVER AFTER HITTING 5 - pass + print('detected') def start_game(self): @@ -144,6 +144,7 @@ class MyGame: if largest_contour is not None: x, y, w, h = cv2.boundingRect(largest_contour) self.detect_collision_cockroach(x, y, w, h) + self.detect_collision_asteroid(x, y, w, h) cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) |