forked from zhiyuan/Project1
添加设置场景
This commit is contained in:
1 parent
75a8525985
commit
eed6713e55
3 files changed
+40
-15
No files matched your search
@@ -1,3 +1,4 @@
|
||||
from src.scenes.config_scene import ConfigScene
|
||||
from src.scenes.empty_scene import EmptyScene
|
||||
from src.scenes.main_menu_scene import MainMenuScene
|
||||
from src.scenes.game_scene import GameScene
|
||||
@@ -7,4 +8,5 @@ scene_dict = {
|
||||
"MainMenuScene": MainMenuScene,
|
||||
"GameScene": GameScene,
|
||||
"EmptyScene": EmptyScene,
|
||||
"ConfigScene": ConfigScene,
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import pygame
|
||||
|
||||
from src.scenes.base_scene import BaseScene
|
||||
|
||||
|
||||
class ConfigScene(BaseScene):
|
||||
name = "ConfigScene" # 场景名称
|
||||
|
||||
def __init__(self, screen):
|
||||
super().__init__(screen)
|
||||
|
||||
def update(self, dt=0):
|
||||
"""
|
||||
场景每帧更新逻辑
|
||||
"""
|
||||
|
||||
def handle_event(self, event):
|
||||
"""
|
||||
接收主循环传来的事件并处理
|
||||
"""
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
self.switch_to_scene("MainMenuScene")
|
||||
@@ -140,19 +140,6 @@ class MainMenuScene(BaseScene):
|
||||
# 触发选项处理
|
||||
self.__handle_option()
|
||||
|
||||
def __handle_option(self):
|
||||
"""
|
||||
处理选项,根据id执行
|
||||
"""
|
||||
if self.select_id is None:
|
||||
return
|
||||
elif self.select_id == 0:
|
||||
self.switch_to_scene("GameScene")
|
||||
elif self.select_id == 1:
|
||||
self.switch_to_scene("OptionScene")
|
||||
elif self.select_id == len(self.text_rect_list) - 1:
|
||||
self.exit()
|
||||
|
||||
def __rain_list_append(self, status=0):
|
||||
"""
|
||||
向列表中添加一个雨滴,默认状态为0
|
||||
@@ -169,14 +156,27 @@ class MainMenuScene(BaseScene):
|
||||
def __init_text_list(self):
|
||||
# 文本
|
||||
text_list = [
|
||||
"开始游戏(Z和X)",
|
||||
"开始游戏",
|
||||
"设置",
|
||||
"退出游戏(ESC)",
|
||||
"退出游戏",
|
||||
]
|
||||
# 转换为文本框
|
||||
for text_str in text_list:
|
||||
self.text_rect_list.append(self.font.render(text_str, True, Color.white))
|
||||
|
||||
def __handle_option(self):
|
||||
"""
|
||||
处理选项,根据id执行
|
||||
"""
|
||||
if self.select_id is None:
|
||||
return
|
||||
elif self.select_id == 0:
|
||||
self.switch_to_scene("GameScene")
|
||||
elif self.select_id == 1:
|
||||
self.switch_to_scene("ConfigScene")
|
||||
elif self.select_id == len(self.text_rect_list) - 1:
|
||||
self.exit()
|
||||
|
||||
def __show_ui(self):
|
||||
"""
|
||||
显示所有选项
|
||||
|
||||
Reference in new issue
Block a user