diff --git a/data/Dymon-ShouXieTi.otf b/data/Dymon-ShouXieTi.otf new file mode 100644 index 0000000..e912992 Binary files /dev/null and b/data/Dymon-ShouXieTi.otf differ diff --git a/src/config/game_config.py b/src/config/game_config.py index 05f7cf4..26daaee 100644 --- a/src/config/game_config.py +++ b/src/config/game_config.py @@ -1,5 +1,16 @@ +import os + + class GameConfig: game_name = "Test Game" window_x = 1920/2 window_y = 1080/2 - bg_color = (0, 0, 0) \ No newline at end of file + bg_color = (0, 0, 0) + +def data_path(): + file_path = os.path.abspath(__file__) + project_path = os.path.dirname(os.path.dirname(os.path.dirname(file_path))) + data_path = os.path.join(project_path, "data") + return data_path + +print(data_path()) \ No newline at end of file diff --git a/src/scenes/main_menu_scene.py b/src/scenes/main_menu_scene.py index 90fed3e..9fb10cf 100644 --- a/src/scenes/main_menu_scene.py +++ b/src/scenes/main_menu_scene.py @@ -1,5 +1,8 @@ +import os + import pygame from src.config.color import Color +from src.config.game_config import data_path, GameConfig from src.scenes.base_scene import BaseScene from src.scenes.game_scene import GameScene @@ -8,14 +11,42 @@ class MainMenuScene(BaseScene): def __init__(self, screen): super().__init__(screen) self.button_status = False + self.debug_status = False + + # 设置字体 + font_file = os.path.join(data_path(),"Dymon-ShouXieTi.otf") + self.font = pygame.font.Font(font_file,16) + + # 文本 + self.game_info_text = self.font.render('按任意键开始游戏', True, Color.white) def update(self): - pygame.draw.rect(self.screen, Color.white, [10,20,30,40]) + # 按键按下则切换场景 if self.button_status: self.switch_to_scene(GameScene) + # 显示提示文本 + + screen_rect = self.screen.get_rect() # 获取屏幕矩形 + text_rect = self.game_info_text.get_rect() # 获取文本矩形 + self.__show(text_rect, (0, 15)) + text_rect.center = screen_rect.center # 将文本居中到屏幕 + self.screen.blit(self.game_info_text, text_rect.topleft) + + self.__show(screen_rect) + self.__show(text_rect,(0,30)) + self.__show(text_rect.center,(0,45)) + def handle_event(self, event): if event.type == pygame.KEYDOWN: self.button_status = True if event.type == pygame.KEYUP: - self.button_status = False \ No newline at end of file + self.button_status = False + + def __show(self, info, dest=(0, 0)): + if not self.debug_status: + return + if not isinstance(info, str): + info = str(info) + info_text = self.font.render(info, True, Color.white) + self.screen.blit(info_text, dest) \ No newline at end of file