From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Fri, 2 Jun 2023 23:18:25 +0000 (-0400) Subject: bomb explode X-Git-Tag: game~16 X-Git-Url: http://git.skullheadx.com/links.html?a=commitdiff_plain;h=5d8c3239040b30883714e102efbbfaec05c0abe9;p=fruit-ninja.git bomb explode --- diff --git a/bomb.py b/bomb.py index 35da62a..3d7e49a 100644 --- 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 89d62e7..552b246 100644 --- 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) diff --git a/setup.py b/setup.py index 2b4b012..11baf45 100644 --- 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)