显示选项按钮

This commit is contained in:
wszqkzqk 2022-07-26 22:40:41 +08:00
parent d7c9fb07a5
commit 7aee0662a5
5 changed files with 63 additions and 9 deletions

12
main.py
View File

@ -13,12 +13,12 @@ if __name__=="__main__":
os.makedirs(os.path.dirname(c.USERLOG_PATH)) os.makedirs(os.path.dirname(c.USERLOG_PATH))
logger = logging.getLogger() logger = logging.getLogger()
formatter = logging.Formatter("%(asctime)s: %(message)s") formatter = logging.Formatter("%(asctime)s: %(message)s")
file_handler = RotatingFileHandler(c.USERLOG_PATH, "a", 1024*1024, 0, "utf-8") fileHandler = RotatingFileHandler(c.USERLOG_PATH, "a", 1024*1024, 0, "utf-8")
file_handler.setFormatter(formatter) fileHandler.setFormatter(formatter)
stream_handler = logging.StreamHandler() streamHandler = logging.StreamHandler()
stream_handler.setFormatter(formatter) streamHandler.setFormatter(formatter)
logger.addHandler(file_handler) logger.addHandler(fileHandler)
logger.addHandler(stream_handler) logger.addHandler(streamHandler)
try: try:
# 控制状态机运行 # 控制状态机运行

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -75,6 +75,7 @@ RETURN_BUTTON = 'returnButton'
RESTART_BUTTON = 'restartButton' RESTART_BUTTON = 'restartButton'
MAINMENU_BUTTON = 'mainMenuButton' MAINMENU_BUTTON = 'mainMenuButton'
LITTLEGAME_BUTTON = 'littleGameButton' LITTLEGAME_BUTTON = 'littleGameButton'
OPTION_BUTTON = 'optionButton'
# 小铲子 # 小铲子
SHOVEL = 'shovel' SHOVEL = 'shovel'
SHOVEL_BOX = 'shovelBox' SHOVEL_BOX = 'shovelBox'

View File

@ -30,7 +30,7 @@ class Menu(tool.State):
def setupOptions(self): def setupOptions(self):
# 冒险模式 # 冒险模式
self.adventure_frames = [] self.adventure_frames = []
frame_names = (c.OPTION_ADVENTURE + '_0', c.OPTION_ADVENTURE + '_1') frame_names = (f'{c.OPTION_ADVENTURE}_0', f'{c.OPTION_ADVENTURE}_1')
frame_rect = (0, 0, 330, 144) frame_rect = (0, 0, 330, 144)
for name in frame_names: for name in frame_names:
@ -44,7 +44,7 @@ class Menu(tool.State):
# 退出按钮 # 退出按钮
self.exit_frames = [] self.exit_frames = []
exit_frame_names = (c.EXIT + '_0', c.EXIT + '_1') exit_frame_names = (f'{c.EXIT}_0', f'{c.EXIT}_1')
exit_frame_rect = (0, 0, 47, 27) exit_frame_rect = (0, 0, 47, 27)
for name in exit_frame_names: for name in exit_frame_names:
self.exit_frames.append(tool.get_image_menu(tool.GFX[name], *exit_frame_rect, c.BLACK, 1.1)) self.exit_frames.append(tool.get_image_menu(tool.GFX[name], *exit_frame_rect, c.BLACK, 1.1))
@ -55,12 +55,25 @@ class Menu(tool.State):
self.exit_rect.y = 507 self.exit_rect.y = 507
self.exit_highlight_time = 0 self.exit_highlight_time = 0
# 选项按钮
self.option_button_frames = []
option_button_frame_names = (f'{c.OPTION_BUTTON}_0', f'{c.OPTION_BUTTON}_1')
option_button_frame_rect = (0, 0, 81, 31)
for name in option_button_frame_names:
self.option_button_frames.append(tool.get_image_menu(tool.GFX[name], *option_button_frame_rect, c.BLACK))
self.option_button_frame_index = 0
self.option_button_image = self.option_button_frames[self.option_button_frame_index]
self.option_button_rect = self.option_button_image.get_rect()
self.option_button_rect.x = 560
self.option_button_rect.y = 490
self.option_button_hightlight_time = 0
# 小游戏 # 小游戏
self.littleGame_frames = [] self.littleGame_frames = []
littleGame_frame_names = (c.LITTLEGAME_BUTTON + '_0', c.LITTLEGAME_BUTTON + '_1') littleGame_frame_names = (c.LITTLEGAME_BUTTON + '_0', c.LITTLEGAME_BUTTON + '_1')
littleGame_frame_rect = (0, 7, 317, 135) littleGame_frame_rect = (0, 7, 317, 135)
for name in littleGame_frame_names: for name in littleGame_frame_names:
self.littleGame_frames.append(tool.get_image_menu(tool.GFX[name], *frame_rect, c.BLACK, 1)) self.littleGame_frames.append(tool.get_image_menu(tool.GFX[name], *littleGame_frame_rect, c.BLACK, 1))
self.littleGame_frame_index = 0 self.littleGame_frame_index = 0
self.littleGame_image = self.littleGame_frames[self.littleGame_frame_index] self.littleGame_image = self.littleGame_frames[self.littleGame_frame_index]
self.littleGame_rect = self.littleGame_image.get_rect() self.littleGame_rect = self.littleGame_image.get_rect()
@ -86,6 +99,13 @@ class Menu(tool.State):
else: else:
return False 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): def inAreaLittleGame(self, x, y):
if (x >= self.littleGame_rect.x and x <= self.littleGame_rect.right and if (x >= self.littleGame_rect.x and x <= self.littleGame_rect.right and
y >= self.littleGame_rect.y and y <= self.littleGame_rect.bottom): y >= self.littleGame_rect.y and y <= self.littleGame_rect.bottom):
@ -100,6 +120,9 @@ class Menu(tool.State):
# 高亮退出按钮 # 高亮退出按钮
elif self.inAreaExit(x, y): elif self.inAreaExit(x, y):
self.exit_highlight_time = self.current_time self.exit_highlight_time = self.current_time
# 高亮选项按钮
elif self.inAreaOptionButton(x, y):
self.option_button_hightlight_time = self.current_time
# 高亮小游戏按钮 # 高亮小游戏按钮
elif self.inAreaLittleGame(x, y): elif self.inAreaLittleGame(x, y):
self.littleGame_highlight_time = self.current_time self.littleGame_highlight_time = self.current_time
@ -132,6 +155,30 @@ class Menu(tool.State):
# 播放点击音效 # 播放点击音效
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()
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): def update(self, surface, current_time, mouse_pos, mouse_click):
self.current_time = self.game_info[c.CURRENT_TIME] = current_time self.current_time = self.game_info[c.CURRENT_TIME] = current_time
@ -150,6 +197,11 @@ class Menu(tool.State):
else: else:
self.exit_frame_index = 0 self.exit_frame_index = 0
self.exit_image = self.exit_frames[self.exit_frame_index] self.exit_image = self.exit_frames[self.exit_frame_index]
if (self.current_time - self.option_button_hightlight_time) < 80:
self.option_button_frame_index = 1
else:
self.option_button_frame_index = 0
self.option_button_image = self.option_button_frames[self.option_button_frame_index]
if (self.current_time - self.littleGame_highlight_time) < 80: if (self.current_time - self.littleGame_highlight_time) < 80:
self.littleGame_frame_index= 1 self.littleGame_frame_index= 1
else: else:
@ -175,4 +227,5 @@ class Menu(tool.State):
surface.blit(self.bg_image, self.bg_rect) surface.blit(self.bg_image, self.bg_rect)
surface.blit(self.adventure_image, self.adventure_rect) surface.blit(self.adventure_image, self.adventure_rect)
surface.blit(self.exit_image, self.exit_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) surface.blit(self.littleGame_image, self.littleGame_rect)