-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStoryLobbyPage.py
85 lines (70 loc) · 2.98 KB
/
StoryLobbyPage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import pygame
from Button import Button
from Colors import *
fps = 60
fpsClock = pygame.time.Clock()
class StoryLobbyPage:
def __init__(self, screen, setting):
self.screen = screen
self.screen_width, self.screen_height = pygame.display.get_surface().get_size()
self.setting = setting
self.game0 = False
self.game1 = False
self.game2 = False
self.game3 = False
self.key_idx = 0
self.start_btn = Button(0.5, 0.3, 200, 50, 'START', text_size=32)
self.start_btn.key_hovered = True
self.map_btn = Button(0.5, 0.4, 200, 50, "MAP",text_size=32)
self.exit_btn = Button(0.5, 0.5, 200, 50, 'EXIT', text_size=32)
self.buttons = [self.start_btn, self.map_btn, self.exit_btn]
def running(self, game_level):
self.screen.fill(WHITE)
self.game_level = game_level
for event in pygame.event.get():
if event.type == pygame.QUIT:
return "exit"
if event.type == pygame.MOUSEBUTTONDOWN:
if self.start_btn.rect.collidepoint(event.pos):
if self.game_level == 0:
return "game_level0"
elif self.game_level == 1:
return "game_level1"
elif self.game_level == 2:
return "game_level2"
elif self.game_level == 3:
return "game_level3"
elif self.map_btn.rect.collidepoint(event.pos):
return "map"
elif self.exit_btn.rect.collidepoint(event.pos):
return "exit"
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
self.key_idx += 1
self.key_idx %= len(self.buttons)
self.buttons[(self.key_idx - 1) % len(self.buttons)].key_hovered = False
self.buttons[self.key_idx].key_hovered = True
elif event.key == pygame.K_UP:
self.key_idx -= 1
self.key_idx %= len(self.buttons)
self.buttons[(self.key_idx + 1) % len(self.buttons)].key_hovered = False
self.buttons[self.key_idx].key_hovered = True
elif event.key == pygame.K_RETURN:
if self.key_idx == 0:
return "game_level0"
elif self.key_idx == 1:
return "map"
elif self.key_idx == 2:
return "exit"
for button in self.buttons:
button.process(self.screen)
pygame.display.flip()
fpsClock.tick(fps)
if self.game_level == 0:
return "story_lobby_0"
elif self.game_level == 1:
return "story_lobby_1"
elif self.game_level == 2:
return "story_lobby_2"
elif self.game_level == 3:
return "story_lobby_3"