添加鼠标点击功能
This commit is contained in:
1 parent
887bef6035
commit
e71c302c23
1 file changed
+9
-2
@@ -64,7 +64,7 @@ class MainMenuScene(BaseScene):
|
|||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
keys = pygame.key.get_pressed() # 获取所有按键状态,用于组合按键判断
|
keys = pygame.key.get_pressed() # 获取所有按键状态,用于组合按键判断
|
||||||
if event.key == pygame.K_ESCAPE:
|
if event.key == pygame.K_ESCAPE:
|
||||||
return "exit" # 主循环接收返回,为exit时设置running为False,退出游戏
|
self.exit() # 退出游戏
|
||||||
elif keys[pygame.K_z] and keys[pygame.K_x]: # 同时按下Z和X
|
elif keys[pygame.K_z] and keys[pygame.K_x]: # 同时按下Z和X
|
||||||
self.button_status = True
|
self.button_status = True
|
||||||
|
|
||||||
@@ -122,11 +122,18 @@ class MainMenuScene(BaseScene):
|
|||||||
text_rect.centerx = screen_rect.centerx # 将文本居中到屏幕
|
text_rect.centerx = screen_rect.centerx # 将文本居中到屏幕
|
||||||
text_rect.y = screen_rect.y + count * 2 * text_rect.height + screen_rect.centerx/2
|
text_rect.y = screen_rect.y + count * 2 * text_rect.height + screen_rect.centerx/2
|
||||||
self.screen.blit(text, text_rect.topleft)
|
self.screen.blit(text, text_rect.topleft)
|
||||||
count += 1
|
|
||||||
# 是否高亮显示
|
# 是否高亮显示
|
||||||
if text_rect.y < self.mouse_pos[1] < text_rect.y + text_rect.height \
|
if text_rect.y < self.mouse_pos[1] < text_rect.y + text_rect.height \
|
||||||
and text_rect.x < self.mouse_pos[0] < text_rect.x + text_rect.width:
|
and text_rect.x < self.mouse_pos[0] < text_rect.x + text_rect.width:
|
||||||
pygame.draw.rect(self.screen, Color.white, text_rect, 1)
|
pygame.draw.rect(self.screen, Color.white, text_rect, 1)
|
||||||
|
# 如果点击鼠标
|
||||||
|
if self.mouse_status:
|
||||||
|
# 点击第一个选项
|
||||||
|
if count == 0:
|
||||||
|
self.switch_to_scene("GameScene")
|
||||||
|
else:
|
||||||
|
self.exit()
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
|
||||||
def init_rain(self, max_num):
|
def init_rain(self, max_num):
|
||||||
|
|||||||
Reference in new issue
Block a user