初步加入音量调节按钮(仅按钮)

This commit is contained in:
星外之神 2022-07-28 13:02:23 +08:00
parent e1d464039a
commit 3a67b414ee
6 changed files with 40 additions and 37 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -70,9 +70,9 @@ RESTART_BUTTON = 'restartButton'
MAINMENU_BUTTON = 'mainMenuButton' MAINMENU_BUTTON = 'mainMenuButton'
LITTLEGAME_BUTTON = 'littleGameButton' LITTLEGAME_BUTTON = 'littleGameButton'
OPTION_BUTTON = 'optionButton' OPTION_BUTTON = 'optionButton'
VOLUME_BUTTON = 'volumeButton'
# 金银向日葵奖杯 # 金银向日葵奖杯
SILVER_SUNFLOWER = 'sunflowerSilver' TROPHY_SUNFLOWER = 'sunflowerTrophy'
GOLDEN_SUNFLOWER = 'sunflowerGolden'
# 小铲子 # 小铲子
SHOVEL = 'shovel' SHOVEL = 'shovel'
SHOVEL_BOX = 'shovelBox' SHOVEL_BOX = 'shovelBox'

View File

@ -91,46 +91,25 @@ class Menu(tool.State):
self.adventure_clicked = False self.adventure_clicked = False
self.option_button_clicked = False self.option_button_clicked = False
def inAreaAdventure(self, x, y): def inArea(self, rect, x, y):
if (x >= self.adventure_rect.x and x <= self.adventure_rect.right and if (x >= rect.x and x <= rect.right and
y >= self.adventure_rect.y and y <= self.adventure_rect.bottom): y >= rect.y and y <= rect.bottom):
return True
else:
return False
def inAreaExit(self, x, y):
if (x >= self.exit_rect.x and x <= self.exit_rect.right and
y >= self.exit_rect.y and y <= self.exit_rect.bottom):
return True
else:
return False
def inAreaOptionButton(self, x, y):
if (x >= self.option_button_rect.x and x <= self.option_button_rect.right and
y >= self.option_button_rect.y and y <= self.option_button_rect.bottom):
return True
else:
return False
def inAreaLittleGame(self, x, y):
if (x >= self.littleGame_rect.x and x <= self.littleGame_rect.right and
y >= self.littleGame_rect.y and y <= self.littleGame_rect.bottom):
return True return True
else: else:
return False return False
def checkHilight(self, x, y): def checkHilight(self, x, y):
# 高亮冒险模式按钮 # 高亮冒险模式按钮
if self.inAreaAdventure(x, y): if self.inArea(self.adventure_rect, x, y):
self.adventure_highlight_time = self.current_time self.adventure_highlight_time = self.current_time
# 高亮退出按钮 # 高亮退出按钮
elif self.inAreaExit(x, y): elif self.inArea(self.exit_rect, x, y):
self.exit_highlight_time = self.current_time self.exit_highlight_time = self.current_time
# 高亮选项按钮 # 高亮选项按钮
elif self.inAreaOptionButton(x, y): elif self.inArea(self.option_button_rect, x, y):
self.option_button_hightlight_time = self.current_time self.option_button_hightlight_time = self.current_time
# 高亮小游戏按钮 # 高亮小游戏按钮
elif self.inAreaLittleGame(x, y): elif self.inArea(self.littleGame_rect, x, y):
self.littleGame_highlight_time = self.current_time self.littleGame_highlight_time = self.current_time
# 检查是否应当高亮并应用结果 # 检查是否应当高亮并应用结果
@ -157,7 +136,7 @@ class Menu(tool.State):
def checkAdventureClick(self, mouse_pos): def checkAdventureClick(self, mouse_pos):
x, y = mouse_pos x, y = mouse_pos
if self.inAreaAdventure(x, y): if self.inArea(self.adventure_rect, x, y):
self.adventure_clicked = True self.adventure_clicked = True
self.adventure_timer = self.adventure_start = self.current_time self.adventure_timer = self.adventure_start = self.current_time
self.persist[c.GAME_MODE] = c.MODE_ADVENTURE self.persist[c.GAME_MODE] = c.MODE_ADVENTURE
@ -168,14 +147,14 @@ class Menu(tool.State):
# 点击到按钮修改转态的done属性 # 点击到按钮修改转态的done属性
def checkExitClick(self, mouse_pos): def checkExitClick(self, mouse_pos):
x, y = mouse_pos x, y = mouse_pos
if self.inAreaExit(x, y): if self.inArea(self.exit_rect, x, y):
self.done = True self.done = True
self.next = c.EXIT self.next = c.EXIT
# 检查有没有按到小游戏 # 检查有没有按到小游戏
def checkLittleGameClick(self, mouse_pos): def checkLittleGameClick(self, mouse_pos):
x, y = mouse_pos x, y = mouse_pos
if self.inAreaLittleGame(x, y): if self.inArea(self.littleGame_rect, x, y):
self.done = True self.done = True
self.persist[c.GAME_MODE] = c.MODE_LITTLEGAME self.persist[c.GAME_MODE] = c.MODE_LITTLEGAME
# 播放点击音效 # 播放点击音效
@ -197,22 +176,44 @@ class Menu(tool.State):
self.return_button_rect.y = 440 self.return_button_rect.y = 440
# 音量+、音量- # 音量+、音量-
frame_rect = (0, 0, 39, 41)
font = pg.font.Font(c.FONT_PATH, 35)
font.bold = True
# 音量+
self.volume_plus_button = tool.get_image_menu(tool.GFX[c.VOLUME_BUTTON], *frame_rect, c.BLACK)
sign = font.render("+", True, c.YELLOWGREEN)
sign_rect = sign.get_rect()
sign_rect.x = 8
sign_rect.y = -4
self.volume_plus_button.blit(sign, sign_rect)
self.volume_plus_button_rect = self.volume_plus_button.get_rect()
self.volume_plus_button_rect.x = 480
# 音量-
self.volume_minus_button = tool.get_image_menu(tool.GFX[c.VOLUME_BUTTON], *frame_rect, c.BLACK)
sign = font.render("-", True, c.YELLOWGREEN)
sign_rect = sign.get_rect()
sign_rect.x = 12
sign_rect.y = -6
self.volume_minus_button.blit(sign, sign_rect)
self.volume_minus_button_rect = self.volume_minus_button.get_rect()
self.volume_minus_button_rect.x = 300
self.volume_minus_button_rect.y = self.volume_plus_button_rect.y = 250
def setupSunflowerTrophy(self): def setupSunflowerTrophy(self):
# 设置金银向日葵图片信息 # 设置金银向日葵图片信息
frame_rect = (0, 0, 157, 269)
if self.game_info[c.LEVEL_COMPLETIONS]: if self.game_info[c.LEVEL_COMPLETIONS]:
if self.game_info[c.LITTLEGAME_COMPLETIONS]: if self.game_info[c.LITTLEGAME_COMPLETIONS]:
self.sunflower_trophy = tool.get_image_menu(tool.GFX[c.GOLDEN_SUNFLOWER], *frame_rect, c.BLACK) frame_rect = (157, 0, 157, 269)
else: else:
self.sunflower_trophy = tool.get_image_menu(tool.GFX[c.SILVER_SUNFLOWER], *frame_rect, c.BLACK) frame_rect = (0, 0, 157, 269)
self.sunflower_trophy = tool.get_image_menu(tool.GFX[c.TROPHY_SUNFLOWER], *frame_rect, c.BLACK)
self.sunflower_trophy_rect = self.sunflower_trophy.get_rect() self.sunflower_trophy_rect = self.sunflower_trophy.get_rect()
self.sunflower_trophy_rect.x = 0 self.sunflower_trophy_rect.x = 0
self.sunflower_trophy_rect.y = 280 self.sunflower_trophy_rect.y = 280
def checkOptionButtonClick(self, mouse_pos): def checkOptionButtonClick(self, mouse_pos):
x, y = mouse_pos x, y = mouse_pos
if self.inAreaOptionButton(x, y): if self.inArea(self.option_button_rect, x, y):
self.option_button_clicked = True self.option_button_clicked = True
# 播放点击音效 # 播放点击音效
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "buttonclick.ogg")).play() pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "buttonclick.ogg")).play()
@ -250,6 +251,8 @@ class Menu(tool.State):
elif self.option_button_clicked: elif self.option_button_clicked:
surface.blit(self.big_menu, self.big_menu_rect) surface.blit(self.big_menu, self.big_menu_rect)
surface.blit(self.return_button, self.return_button_rect) surface.blit(self.return_button, self.return_button_rect)
surface.blit(self.volume_plus_button, self.volume_plus_button_rect)
surface.blit(self.volume_minus_button, self.volume_minus_button_rect)
if (mouse_pos and self.checkReturnClick(mouse_pos)): if (mouse_pos and self.checkReturnClick(mouse_pos)):
self.option_button_clicked = False self.option_button_clicked = False
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "buttonclick.ogg")).play() pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "buttonclick.ogg")).play()