From 9c8bb2162fb5a12288b629f8ef5ba357055508dd Mon Sep 17 00:00:00 2001 From: chicrobot Date: Sun, 26 Jul 2026 02:05:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AE=BE=E7=BD=AE=E3=80=81?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E3=80=81=E5=9C=BA=E6=99=AF=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=9C=BA=E6=99=AF=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E6=94=BE=E5=88=B0=E5=8D=95=E7=8B=AC=E6=96=87=E4=BB=B6=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/color.py | 6 ++++++ src/config/game_config.py | 5 +++++ src/scenes/base_scene.py | 5 +++++ src/scenes/main_menu_scene.py | 9 +++++++++ start.py | 10 ++++------ 5 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 src/config/color.py create mode 100644 src/config/game_config.py create mode 100644 src/scenes/base_scene.py create mode 100644 src/scenes/main_menu_scene.py diff --git a/src/config/color.py b/src/config/color.py new file mode 100644 index 0000000..2257750 --- /dev/null +++ b/src/config/color.py @@ -0,0 +1,6 @@ +class Color: + black = (0, 0, 0) + white = (255, 255, 255) + a = (255, 0, 0) + b = (0, 255, 0) + c = (0, 0, 255) \ No newline at end of file diff --git a/src/config/game_config.py b/src/config/game_config.py new file mode 100644 index 0000000..05f7cf4 --- /dev/null +++ b/src/config/game_config.py @@ -0,0 +1,5 @@ +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 diff --git a/src/scenes/base_scene.py b/src/scenes/base_scene.py new file mode 100644 index 0000000..8ac5734 --- /dev/null +++ b/src/scenes/base_scene.py @@ -0,0 +1,5 @@ +import pygame + +class BaseScene: + def __init__(self, screen: pygame.Surface): + self.screen = screen diff --git a/src/scenes/main_menu_scene.py b/src/scenes/main_menu_scene.py new file mode 100644 index 0000000..df928a7 --- /dev/null +++ b/src/scenes/main_menu_scene.py @@ -0,0 +1,9 @@ +import pygame +from src.config.color import Color +from src.scenes.base_scene import BaseScene + + +class MainMenuScene(BaseScene): + + def update(self): + pygame.draw.rect(self.screen, Color.white, [10,20,30,40]) \ No newline at end of file diff --git a/start.py b/start.py index 3f61c8f..273ee7e 100644 --- a/start.py +++ b/start.py @@ -1,9 +1,8 @@ import pygame -from src.config.color import Color from src.config.game_config import GameConfig +from src.scenes.main_menu_scene import MainMenuScene -rect = [10,20,30,40] class Game: def __init__(self): @@ -29,15 +28,14 @@ class Game: if event.type == pygame.QUIT: self.running = False + # 清屏 self.screen.fill(GameConfig.bg_color) - self.update() + # 场景每帧更新逻辑运行 + MainMenuScene(self.screen) # 更新显示 pygame.display.update() - def update(self): - pygame.draw.rect(self.screen, Color.white, rect) - if __name__ == "__main__": Game() \ No newline at end of file