From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Thu, 1 Jun 2023 18:22:26 +0000 (-0400) Subject: bomb X-Git-Tag: game~28 X-Git-Url: http://git.skullheadx.com/nixos/static/projects.html?a=commitdiff_plain;h=d0374877a28e05a4a4fd5c6e8a7719a2fc65e3c9;p=fruit-ninja.git bomb --- diff --git a/bomb.py b/bomb.py new file mode 100644 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) diff --git a/fruit.py b/fruit.py index 740dadc..3357a9d 100644 --- a/fruit.py +++ b/fruit.py @@ -1,5 +1,3 @@ -import random - from setup import * diff --git a/game.py b/game.py index de20d9e..cd5675f 100644 --- 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 6972ec4..99fc4ce 100644 --- 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()