feat:增加等級提升下降的音效
This commit is contained in:
parent
35bcd39023
commit
6737efe94b
Binary file not shown.
Binary file not shown.
|
@ -131,8 +131,8 @@ class EasyGame(PaiaGame):
|
||||||
if hits:
|
if hits:
|
||||||
for food in hits:
|
for food in hits:
|
||||||
# self.ball.score += food.score
|
# self.ball.score += food.score
|
||||||
self.ball.eat_food(food)
|
# growth play special sound
|
||||||
# TODO if growth play special sound
|
self.ball.eat_food_and_change_level_and_play_sound(food,self.sound_controller)
|
||||||
self._create_foods(food.__class__, 1)
|
self._create_foods(food.__class__, 1)
|
||||||
if isinstance(food, (GoodFoodLv1,GoodFoodLv2,GoodFoodLv3,)):
|
if isinstance(food, (GoodFoodLv1,GoodFoodLv2,GoodFoodLv3,)):
|
||||||
self.sound_controller.play_eating_good()
|
self.sound_controller.play_eating_good()
|
||||||
|
|
|
@ -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, \
|
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
|
BALL_SIZE_MAX, BALL_GROWTH_VEL_STEP, BALL_VEL_MAX
|
||||||
from games.easy_game.src.foods import Food
|
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
|
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.rect.center = (400, 300)
|
||||||
self._score = 0
|
self._score = 0
|
||||||
self._vel = BALL_VEL
|
self._vel = BALL_VEL
|
||||||
|
self._lv =1
|
||||||
|
|
||||||
def update(self, motion):
|
def update(self, motion):
|
||||||
# for motion in motions:
|
# for motion in motions:
|
||||||
|
@ -49,12 +51,17 @@ class Ball(pygame.sprite.Sprite):
|
||||||
self.color
|
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
|
self._score += food.score
|
||||||
lv = math.ceil((self._score + 1) / BALL_GROWTH_SCORE_STEP)
|
new_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.width = min(BALL_W + new_lv * BALL_GROWTH_SIZE_STEP, BALL_SIZE_MAX)
|
||||||
self.rect.height = min(BALL_H + 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 + lv * BALL_GROWTH_VEL_STEP, BALL_VEL_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
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -25,6 +25,8 @@ class SoundController():
|
||||||
self._eating_good = pygame.mixer.Sound(path.join(SOUND_PATH, "Coin.wav"))
|
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._eating_bad = pygame.mixer.Sound(path.join(SOUND_PATH, "Low Boing.wav"))
|
||||||
self._cheer = pygame.mixer.Sound(path.join(SOUND_PATH, "Cheer.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:
|
except Exception:
|
||||||
self._is_sound_on = False
|
self._is_sound_on = False
|
||||||
|
|
||||||
|
@ -42,3 +44,11 @@ class SoundController():
|
||||||
@sound_enabled
|
@sound_enabled
|
||||||
def play_cheer(self):
|
def play_cheer(self):
|
||||||
self._cheer.play()
|
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()
|
Loading…
Reference in New Issue