]> Skullheadx's Git Forge - fruit-ninja.git/commitdiff
bomb
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Thu, 1 Jun 2023 18:22:26 +0000 (14:22 -0400)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Thu, 1 Jun 2023 18:22:26 +0000 (14:22 -0400)
bomb.py [new file with mode: 0644]
fruit.py
game.py
main.py

diff --git a/bomb.py b/bomb.py
new file mode 100644 (file)
index 0000000..dca47dc
--- /dev/null
+++ b/bomb.py
@@ -0,0 +1,8 @@
+from setup import *
+from fruit import Fruit
+
+
+class Bomb(Fruit):
+    RADIUS = 35
+    def draw(self, surf):
+        pygame.draw.circle(surf, BLACK, self.position, self.RADIUS)
index 740dadc7441a156f6737d3edf8993372ad27aae0..3357a9df0b6687a0a9349439a8c3d9ca27948d00 100644 (file)
--- a/fruit.py
+++ b/fruit.py
@@ -1,5 +1,3 @@
-import random
-
 from setup import *
 
 
diff --git a/game.py b/game.py
index de20d9e912e689440f989ab9501abf7910510da2..cd5675f8dc5fb06c190b72a1feb563e72852fc61 100644 (file)
--- a/game.py
+++ b/game.py
@@ -1,13 +1,16 @@
 from setup import *
 from player import Player
 from fruit import Fruit
+from bomb import Bomb
 
 
 class Game:
+    BOMB_CHANCE = 0.5
 
     def __init__(self):
         self.player = Player()
         self.fruits = [Fruit()]
+        self.bombs = []
         self.wave = 1
 
     def update(self, delta):
@@ -27,13 +30,26 @@ class Game:
         for hit in hits:
             self.fruits.remove(hit)
 
+        for bomb in self.bombs:
+            bomb.update(delta)
+            if self.player.hits(bomb):
+                return COMMAND_START
+            br = bomb.get_rect()
+            if (not -bomb.RADIUS <= br.x < WIDTH) or br.y > HEIGHT:
+                self.bombs.remove(bomb)
+
         if len(self.fruits) == 0:
             self.wave += 1
             for i in range(self.wave):
-                self.fruits.append(Fruit())
+                if random.random() < self.BOMB_CHANCE:
+                    self.bombs.append(Bomb())
+                else:
+                    self.fruits.append(Fruit())
 
     def draw(self, surf):
         screen.fill(WHITE)
         for fruit in self.fruits:
             fruit.draw(surf)
+        for bomb in self.bombs:
+            bomb.draw(surf)
         self.player.draw(surf)
diff --git a/main.py b/main.py
index 6972ec4ae06613430d5ba3fc134165ee2ee59348..99fc4ce682c06ca8340e527b9f9cb3caa869e84b 100644 (file)
--- a/main.py
+++ b/main.py
@@ -15,5 +15,8 @@ while is_running:
 
     if status == COMMAND_EXIT:
         is_running = False
+    elif status == COMMAND_START:
+        scene = Game()
+
 
 pygame.quit()