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)
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:
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)
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)
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)
# 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)