diff --git a/asset/sounds/lv_down.wav b/asset/sounds/lv_down.wav new file mode 100644 index 0000000..943843c Binary files /dev/null and b/asset/sounds/lv_down.wav differ diff --git a/asset/sounds/lv_up.wav b/asset/sounds/lv_up.wav new file mode 100644 index 0000000..b1cc725 Binary files /dev/null and b/asset/sounds/lv_up.wav differ diff --git a/src/game.py b/src/game.py index 52aa4d9..26ae6c0 100644 --- a/src/game.py +++ b/src/game.py @@ -131,8 +131,8 @@ class EasyGame(PaiaGame): if hits: for food in hits: # self.ball.score += food.score - self.ball.eat_food(food) - # TODO if growth play special sound + # growth play special sound + self.ball.eat_food_and_change_level_and_play_sound(food,self.sound_controller) self._create_foods(food.__class__, 1) if isinstance(food, (GoodFoodLv1,GoodFoodLv2,GoodFoodLv3,)): self.sound_controller.play_eating_good() diff --git a/src/game_object.py b/src/game_object.py index d24f1e6..252287e 100644 --- a/src/game_object.py +++ b/src/game_object.py @@ -5,6 +5,7 @@ import pygame.sprite from games.easy_game.src.env import BALL_COLOR, BALL_VEL, BALL_H, BALL_W, BALL_GROWTH_SCORE_STEP, BALL_GROWTH_SIZE_STEP, \ BALL_SIZE_MAX, BALL_GROWTH_VEL_STEP, BALL_VEL_MAX from games.easy_game.src.foods import Food +from games.easy_game.src.sound_controller import SoundController from mlgame.view.view_model import create_rect_view_data @@ -18,6 +19,7 @@ class Ball(pygame.sprite.Sprite): self.rect.center = (400, 300) self._score = 0 self._vel = BALL_VEL + self._lv =1 def update(self, motion): # for motion in motions: @@ -49,12 +51,17 @@ class Ball(pygame.sprite.Sprite): self.color ) - def eat_food(self, food: Food): + def eat_food_and_change_level_and_play_sound(self, food: Food,sound_controller:SoundController): self._score += food.score - lv = math.ceil((self._score + 1) / BALL_GROWTH_SCORE_STEP) - self.rect.width = min(BALL_W + lv * BALL_GROWTH_SIZE_STEP, BALL_SIZE_MAX) - self.rect.height = min(BALL_H + lv * BALL_GROWTH_SIZE_STEP, BALL_SIZE_MAX) - self._vel = min(BALL_VEL + lv * BALL_GROWTH_VEL_STEP, BALL_VEL_MAX) + new_lv = math.ceil((self._score + 1) / BALL_GROWTH_SCORE_STEP) + self.rect.width = min(BALL_W + new_lv * BALL_GROWTH_SIZE_STEP, BALL_SIZE_MAX) + self.rect.height = min(BALL_H + new_lv * BALL_GROWTH_SIZE_STEP, BALL_SIZE_MAX) + self._vel = min(BALL_VEL + new_lv * BALL_GROWTH_VEL_STEP, BALL_VEL_MAX) + if new_lv > self._lv: + sound_controller.play_lv_up() + elif new_lv < self._lv: + sound_controller.play_lv_down() + self._lv=new_lv pass @property diff --git a/src/sound_controller.py b/src/sound_controller.py index 284109d..f755ed3 100644 --- a/src/sound_controller.py +++ b/src/sound_controller.py @@ -25,6 +25,8 @@ class SoundController(): self._eating_good = pygame.mixer.Sound(path.join(SOUND_PATH, "Coin.wav")) self._eating_bad = pygame.mixer.Sound(path.join(SOUND_PATH, "Low Boing.wav")) self._cheer = pygame.mixer.Sound(path.join(SOUND_PATH, "Cheer.wav")) + self._lv_up = pygame.mixer.Sound(path.join(SOUND_PATH, "lv_up.wav")) + self._lv_down = pygame.mixer.Sound(path.join(SOUND_PATH, "lv_down.wav")) except Exception: self._is_sound_on = False @@ -42,3 +44,11 @@ class SoundController(): @sound_enabled def play_cheer(self): self._cheer.play() + + @sound_enabled + def play_lv_up(self): + self._lv_up.play() + + @sound_enabled + def play_lv_down(self): + self._lv_down.play() \ No newline at end of file