]> Skullheadx's Git Forge - fruit-ninja.git/commitdiff
bomb explode
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Fri, 2 Jun 2023 23:18:25 +0000 (19:18 -0400)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Fri, 2 Jun 2023 23:18:25 +0000 (19:18 -0400)
bomb.py
game.py
setup.py

diff --git a/bomb.py b/bomb.py
index 35da62afb942f2f2704aa5fa67780423ba419be8..3d7e49a3ae064e9f01a5b3ad9d24d2eddc7523db 100644 (file)
--- a/bomb.py
+++ b/bomb.py
@@ -5,5 +5,37 @@ from fruit import Fruit
 class Bomb(Fruit):
     RADIUS = 55
 
+    EXPLOSION_RADIUS = 100
+    POWER = 75
+
+    def __init__(self):
+        super().__init__()
+        self.radius = self.RADIUS
+        self.exploded = False
+        self.exploded_time = 0
+
+    def update(self, delta):
+        super().update(delta)
+        if self.exploded:
+            self.exploded_time += delta ** 2
+
+    def explode(self, fruits, bombs):
+        if self in bombs:
+            self.exploded = True
+        self.velocity = pygame.Vector2(0, 0)
+        self.acceleration = pygame.Vector2(0, 0)
+
+
+
+        for fruit in fruits:
+            fruit.velocity += (fruit.position - self.position).normalize() * self.POWER
+        for bomb in bombs:
+            if not bomb.exploded:
+                bomb.explode(fruits, bombs)
+
     def draw(self, surf):
-        pygame.draw.circle(surf, BLACK, self.position, self.RADIUS)
+        if self.exploded:
+            pygame.draw.circle(surf, DARK_RED, self.position, clamp(self.RADIUS + self.exploded_time / 1000 * 100, 0, 300))
+            pygame.draw.circle(surf, BLACK, self.position, clamp(self.RADIUS + self.exploded_time / 1000 * 100, 0, 300), self.OUTLINE_WIDTH)
+        else:
+            pygame.draw.circle(surf, BLACK, self.position, self.RADIUS)
diff --git a/game.py b/game.py
index 89d62e7306188989c1822c0b46a435f655826771..552b246528819528e5c2b5c1ffe984fae9da0c0c 100644 (file)
--- a/game.py
+++ b/game.py
@@ -10,18 +10,21 @@ class Game:
     BOMB_CHANCE = 0.1
     EFFECT_COUNT_PER_FRUIT = 20
     COMBO_TIME = 250
-
+    GAME_OVER_TIME = 1000
     def __init__(self):
         self.player = Player()
         self.fruits = [Fruit()]
         self.bombs = []
         self.effects = []
         self.combo_counters = []
-        self.wave = 1
+        self.wave = 100
         self.score = 0
         self.time_since_last_hit = 0
         self.current_combo = 0
 
+        self.game_over = False
+        self.game_over_time = 0
+
     def update(self, delta):
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
@@ -29,7 +32,13 @@ class Game:
             if event.type == pygame.KEYUP:
                 if event.key == pygame.K_ESCAPE:
                     return COMMAND_EXIT
-        self.player.update(delta)
+
+        if not self.game_over:
+            self.player.update(delta)
+        else:
+            self.game_over_time += delta
+            if self.game_over_time > self.GAME_OVER_TIME:
+                return COMMAND_START
         hits = []
         for fruit in self.fruits:
             fruit.update(delta)
@@ -70,7 +79,9 @@ class Game:
         for bomb in self.bombs:
             bomb.update(delta)
             if self.player.hits(bomb):
-                return COMMAND_START
+                bomb.explode(self.fruits, self.bombs)
+                self.game_over = True
+                self.player.sliced_points.clear()
             br = bomb.get_rect()
             if ((not -bomb.RADIUS < br.x < WIDTH + bomb.RADIUS) or br.y > HEIGHT) and bomb.velocity.y > 0:
                 self.bombs.remove(bomb)
@@ -87,10 +98,10 @@ class Game:
         screen.fill(BROWN)
         for effect in self.effects:
             effect.draw(surf)
-        for fruit in self.fruits:
-            fruit.draw(surf)
         for bomb in self.bombs:
             bomb.draw(surf)
+        for fruit in self.fruits:
+            fruit.draw(surf)
         for combo in self.combo_counters:
             combo.draw(surf)
         self.player.draw(surf)
index 2b4b01238106dffd58b441851a6caeea09b248d3..11baf4591d77c8dd66bb731bd63b941362b750c1 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -37,11 +37,16 @@ LIGHTEN = {RED: ORANGE, ORANGE: YELLOW, YELLOW: GREEN, GREEN: BLUE, BLUE: PURPLE
 # commands
 COMMAND_EXIT = 0
 COMMAND_START = 1
+COMMAND_GAME_OVER = 2
 
 
 def lerp(start, end, weight):
     return weight * (end - start) + start
 
 
+def clamp(value, minimum, maximum):
+    return min(maximum, max(minimum, value))
+
+
 font = pygame.font.SysFont("Arial", 50)
-font_large = pygame.font.SysFont("Arial", 80)
\ No newline at end of file
+font_large = pygame.font.SysFont("Arial", 80)