加入选项菜单

This commit is contained in:
wszqkzqk 2022-07-26 23:10:46 +08:00
parent ee8de23bd5
commit f3d664b263

View File

@ -14,7 +14,7 @@ class Menu(tool.State):
self.game_info = persist
self.setupBackground()
self.setupOptions()
self.setupOptionButton()
self.setupOptionMenu()
pg.mixer.music.stop()
pg.mixer.music.load(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "music", "intro.opus"))
pg.mixer.music.play(-1, 0)
@ -88,6 +88,7 @@ class Menu(tool.State):
self.adventure_start = 0
self.adventure_timer = 0
self.adventure_clicked = False
self.option_button_clicked = False
def inAreaAdventure(self, x, y):
if (x >= self.adventure_rect.x and x <= self.adventure_rect.right and
@ -131,67 +132,7 @@ class Menu(tool.State):
elif self.inAreaLittleGame(x, y):
self.littleGame_highlight_time = self.current_time
def checkAdventureClick(self, mouse_pos):
x, y = mouse_pos
if self.inAreaAdventure(x, y):
self.adventure_clicked = True
self.adventure_timer = self.adventure_start = self.current_time
self.persist[c.GAME_MODE] = c.MODE_ADVENTURE
# 播放进入音效
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "evillaugh.ogg")).play()
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "lose.ogg")).play()
return False
# 点击到按钮修改转态的done属性
def checkExitClick(self, mouse_pos):
x, y = mouse_pos
if self.inAreaExit(x, y):
self.done = True
self.next = c.EXIT
# 检查有没有按到小游戏
def checkLittleGameClick(self, mouse_pos):
x, y = mouse_pos
if self.inAreaLittleGame(x, y):
self.done = True
self.persist[c.GAME_MODE] = c.MODE_LITTLEGAME
# 播放点击音效
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "buttonclick.ogg")).play()
def setupOptionButton(self):
# 选项菜单框
frame_rect = (0, 0, 500, 500)
self.big_menu = tool.get_image_menu(tool.GFX[c.BIG_MENU], *frame_rect, c.BLACK, 1.1)
self.big_menu_rect = self.big_menu.get_rect()
self.big_menu_rect.x = 150
self.big_menu_rect.y = 0
# 返回按钮
frame_rect = (0, 0, 342, 87)
self.return_button = tool.get_image_menu(tool.GFX[c.RETURN_BUTTON], *frame_rect, c.BLACK, 1.1)
self.return_button_rect = self.return_button.get_rect()
self.return_button_rect.x = 220
self.return_button_rect.y = 440
# 音量+、音量-
# 在选项菜单打开时,检测是否点击到返回
def checkReturnClick(self, mouse_pos):
x, y = mouse_pos
if (x >= self.return_button_rect.x and x <= self.return_button_rect.right and
y >= self.return_button_rect.y and y <= self.return_button_rect.bottom):
return True
return False
def update(self, surface, current_time, mouse_pos, mouse_click):
self.current_time = self.game_info[c.CURRENT_TIME] = current_time
# 没有选到选项时,检查有没有点到选项
if not self.adventure_clicked:
# 先检查选项高亮预览
x, y = pg.mouse.get_pos()
self.checkHilight(x, y)
# 检查是否应当高亮并应用结果
if (self.current_time - self.adventure_highlight_time) < 80:
self.adventure_frame_index = 1
else:
@ -213,11 +154,75 @@ class Menu(tool.State):
self.littleGame_frame_index = 0
self.littleGame_image = self.littleGame_frames[self.littleGame_frame_index]
if mouse_pos:
self.checkExitClick(mouse_pos)
self.checkLittleGameClick(mouse_pos)
self.checkAdventureClick(mouse_pos)
else:
def checkAdventureClick(self, mouse_pos):
x, y = mouse_pos
if self.inAreaAdventure(x, y):
self.adventure_clicked = True
self.adventure_timer = self.adventure_start = self.current_time
self.persist[c.GAME_MODE] = c.MODE_ADVENTURE
# 播放进入音效
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "evillaugh.ogg")).play()
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "lose.ogg")).play()
# 点击到按钮修改转态的done属性
def checkExitClick(self, mouse_pos):
x, y = mouse_pos
if self.inAreaExit(x, y):
self.done = True
self.next = c.EXIT
# 检查有没有按到小游戏
def checkLittleGameClick(self, mouse_pos):
x, y = mouse_pos
if self.inAreaLittleGame(x, y):
self.done = True
self.persist[c.GAME_MODE] = c.MODE_LITTLEGAME
# 播放点击音效
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "buttonclick.ogg")).play()
def setupOptionMenu(self):
# 选项菜单框
frame_rect = (0, 0, 500, 500)
self.big_menu = tool.get_image_menu(tool.GFX[c.BIG_MENU], *frame_rect, c.BLACK, 1.1)
self.big_menu_rect = self.big_menu.get_rect()
self.big_menu_rect.x = 150
self.big_menu_rect.y = 0
# 返回按钮
frame_rect = (0, 0, 342, 87)
self.return_button = tool.get_image_menu(tool.GFX[c.RETURN_BUTTON], *frame_rect, c.BLACK, 1.1)
self.return_button_rect = self.return_button.get_rect()
self.return_button_rect.x = 220
self.return_button_rect.y = 440
# 音量+、音量-
def checkOptionButtonClick(self, mouse_pos):
x, y = mouse_pos
if self.inAreaOptionButton(x, y):
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()
# 在选项菜单打开时,检测是否点击到返回
def checkReturnClick(self, mouse_pos):
x, y = mouse_pos
if (x >= self.return_button_rect.x and x <= self.return_button_rect.right and
y >= self.return_button_rect.y and y <= self.return_button_rect.bottom):
return True
return False
def update(self, surface, current_time, mouse_pos, mouse_click):
self.current_time = self.game_info[c.CURRENT_TIME] = current_time
surface.blit(self.bg_image, self.bg_rect)
surface.blit(self.adventure_image, self.adventure_rect)
surface.blit(self.exit_image, self.exit_rect)
surface.blit(self.option_button_image, self.option_button_rect)
surface.blit(self.littleGame_image, self.littleGame_rect)
# 没有选到选项时,检查有没有点到选项
if self.adventure_clicked:
# 点到后播放动画
if (self.current_time - self.adventure_timer) > 150:
self.adventure_frame_index += 1
@ -227,10 +232,17 @@ class Menu(tool.State):
self.adventure_image = self.adventure_frames[self.adventure_frame_index]
if (self.current_time - self.adventure_start) > 3200:
self.done = True
surface.blit(self.bg_image, self.bg_rect)
surface.blit(self.adventure_image, self.adventure_rect)
surface.blit(self.exit_image, self.exit_rect)
surface.blit(self.option_button_image, self.option_button_rect)
surface.blit(self.littleGame_image, self.littleGame_rect)
elif self.option_button_clicked:
surface.blit(self.big_menu, self.big_menu_rect)
surface.blit(self.return_button, self.return_button_rect)
if (mouse_pos and self.checkReturnClick(mouse_pos)):
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()
else:
# 先检查选项高亮预览
self.checkHilight(*pg.mouse.get_pos())
if mouse_pos:
self.checkExitClick(mouse_pos)
self.checkOptionButtonClick(mouse_pos)
self.checkLittleGameClick(mouse_pos)
self.checkAdventureClick(mouse_pos)