-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
127 lines (109 loc) · 4.58 KB
/
Copy pathmenu.py
File metadata and controls
127 lines (109 loc) · 4.58 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Starting menu
import pygame as pg
class Menu():
def __init__(self, game):
self.screen = game.screen
self.settings = game.settings
self.card_size = self.settings.card_size
self.ng_image = pg.transform.scale(pg.image.load(f'images/NewGameCard.png'), self.card_size)
self.cont_image = pg.transform.scale(pg.image.load(f'images/ContinueCard.png'), self.card_size)
self.exit_image = pg.transform.scale(pg.image.load(f'images/ExitCard.png'), self.card_size)
self.ng_rect = self.ng_image.get_rect()
self.cont_rect = self.cont_image.get_rect()
self.exit_rect = self.exit_image.get_rect()
self.ng_rect.x = 300
self.cont_rect.x = 500
self.exit_rect.x = 700
self.ng_rect.y = self.cont_rect.y = self.exit_rect.y = 400
self.running = True
self.font = pg.font.Font('fonts/chalkduster.ttf', 108)
self.text = self.font.render('PaperCut', True, self.settings.font_color)
self.textRect = self.text.get_rect()
self.textRect.center = (self.settings.window_x // 2, self.settings.window_y // 4)
# Starting menu
import pygame as pg
class Menu():
def __init__(self, game):
self.screen = game.screen
self.settings = game.settings
self.card_size = self.settings.card_size
self.ng_image = pg.transform.scale(pg.image.load(f'images/NewGameCard.png'), self.card_size)
self.cont_image = pg.transform.scale(pg.image.load(f'images/ContinueCard.png'), self.card_size)
self.exit_image = pg.transform.scale(pg.image.load(f'images/ExitCard.png'), self.card_size)
self.ng_rect = self.ng_image.get_rect()
self.cont_rect = self.cont_image.get_rect()
self.exit_rect = self.exit_image.get_rect()
self.ng_rect.x = 300
self.cont_rect.x = 500
self.exit_rect.x = 700
self.ng_rect.y = self.cont_rect.y = self.exit_rect.y = 400
self.running = True
self.font = pg.font.Font('fonts/chalkduster.ttf', 108)
self.text = self.font.render('PaperCut', True, self.settings.font_color)
self.textRect = self.text.get_rect()
self.textRect.center = (self.settings.window_x // 2, self.settings.window_y // 4)
pg.mixer.init()
pg.mixer.music.load('sounds/menu.ogg')
pg.mixer.music.set_volume(0.05)
pg.mixer.music.play()
def select_option(self):
for event in pg.event.get():
if(event.type == pg.MOUSEBUTTONUP):
x, y = pg.mouse.get_pos()
if self.ng_rect.collidepoint(x, y):
self.new_game()
elif self.exit_rect.collidepoint(x, y):
self.exit_game()
def new_game(self):
self.running = False
def exit_game(self):
pg.quit()
quit()
def in_menu(self):
while self.running:
self.update()
def update(self):
self.select_option()
self.draw()
def draw(self):
self.screen.blit(self.ng_image, (self.ng_rect.x, self.ng_rect.y))
self.screen.blit(self.exit_image, (self.exit_rect.x, self.exit_rect.y))
self.screen.blit(self.text, self.textRect)
pg.display.update()
def select_option(self):
for event in pg.event.get():
if(event.type == pg.MOUSEBUTTONUP):
x, y = pg.mouse.get_pos()
if self.ng_rect.collidepoint(x, y):
self.new_game()
pg.mixer.music.load('sounds/background.ogg')
pg.mixer.music.play()
elif self.cont_rect.collidepoint(x, y):
self.load_save()
pg.mixer.music.load('sounds/background.ogg')
pg.mixer.music.play()
elif self.exit_rect.collidepoint(x, y):
self.exit_game()
def new_game(self):
self.running = False
pg.mixer.music.load("sounds/click.wav")
pg.mixer.music.set_volume(0.3)
pg.mixer.music.play()
pg.time.delay(500)
def exit_game(self):
click = pg.mixer.music.load("sounds/click.wav")
pg.mixer.music.set_volume(0.3)
pg.mixer.music.play()
pg.quit()
quit()
def in_menu(self):
while self.running:
self.update()
def update(self):
self.select_option()
self.draw()
def draw(self):
self.screen.blit(self.ng_image, (self.ng_rect.x, self.ng_rect.y))
self.screen.blit(self.exit_image, (self.exit_rect.x, self.exit_rect.y))
self.screen.blit(self.text, self.textRect)
pg.display.update()