forked from ANDRESONGOMES/projetoip1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
178 lines (154 loc) · 8.06 KB
/
menu.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import pygame
import sys
import os
pygame.mixer.init()
bg_image = pygame.transform.scale(pygame.image.load(
os.path.join("assets", "background_menu", "Spectre1.png")), (900, 600))
bg_image_2 = pygame.transform.scale(pygame.image.load(
os.path.join("assets", "background_menu", "SpectreV.png")), (900, 600))
bg_music = pygame.mixer.music.load(os.path.join("assets","musicas", "musicadefundo.mp3"))
victory_music = pygame.mixer.Sound(os.path.join("assets","musicas", "musicavitoria.mp3"))
coin_sound = pygame.mixer.Sound(os.path.join("assets", "musicas", "smw_coin.wav"))
pygame.mixer.music.play(-1)
class Menu:
def __init__(self, game):
self.game = game
self.mid_w, self.mid_h = self.game.DISPLAY_W / 2, self.game.DISPLAY_H / 2
self.run_display = True
self.cursor_rect = pygame.Rect(0, 0, 130, 130)
self.offset = - 100
def draw_cursor(self):
self.game.draw_text('>', 20, self.cursor_rect.x, self.cursor_rect.y)
def blit_screen(self):
self.game.window.blit(self.game.display, (0, 0))
pygame.display.update()
self.game.reset_keys()
class MainMenu(Menu):
def __init__(self, game):
Menu.__init__(self, game)
self.state = "Começar"
self.startx, self.starty = self.mid_w, self.mid_h
self.tutorialx, self.tutorialy = self.mid_w, self.mid_h + 40
self.creditsx, self.creditsy = self.mid_w, self.mid_h + 80
self.exitx, self.exity = self.mid_w, self.mid_h + 120
self.cursor_rect.midtop = (self.startx + self.offset, self.starty)
def display_menu(self):
self.run_display = True
while self.run_display:
self.game.check_events()
self.check_input()
self.game.display.blit(bg_image, (0, 0))
self.game.draw_text("Começar", 20, self.startx, self.starty)
self.game.draw_text('Comandos', 20, self.tutorialx, self.tutorialy)
self.game.draw_text("Créditos", 20, self.creditsx, self.creditsy)
self.game.draw_text("Sair", 20, self.exitx, self.exity)
self.game.draw_text("Voltar: Backspace", 10, self.mid_w - 200, self.mid_h + 190)
self.game.draw_text("Avançar: Enter", 10, self.mid_w + 200, self.mid_h + 190)
self.draw_cursor()
self.blit_screen()
def move_cursor(self):
if self.game.DOWN_KEY:
if self.state == 'Começar':
self.cursor_rect.midtop = (self.tutorialx + self.offset, self.tutorialy)
self.state = 'Comandos'
elif self.state == 'Comandos':
self.cursor_rect.midtop = (self.creditsx + self.offset, self.creditsy)
self.state = 'Créditos'
elif self.state == 'Créditos':
self.cursor_rect.midtop = (self.exitx + self.offset, self.exity)
self.state = 'Sair'
elif self.state == 'Sair':
self.cursor_rect.midtop = (self.startx + self.offset, self.starty)
self.state = 'Começar'
elif self.game.UP_KEY:
if self.state == 'Começar':
self.cursor_rect.midtop = (self.exitx + self.offset, self.exity)
self.state = 'Sair'
elif self.state == 'Sair':
self.cursor_rect.midtop = (self.creditsx + self.offset, self.creditsy)
self.state = 'Créditos'
elif self.state == 'Comandos':
self.cursor_rect.midtop = (self.startx + self.offset, self.starty)
self.state = 'Começar'
elif self.state == 'Créditos':
self.cursor_rect.midtop = (self.tutorialx + self.offset, self.tutorialy)
self.state = 'Comandos'
def check_input(self):
self.move_cursor()
if self.game.START_KEY:
if self.state == 'Começar':
self.game.playing = True
elif self.state == 'Comandos':
self.game.curr_menu = self.game.options
elif self.state == 'Créditos':
self.game.curr_menu = self.game.credits
elif self.state == 'Sair':
sys.exit()
self.run_display = False
class OptionsMenu(Menu):
def __init__(self, game):
Menu.__init__(self, game)
self.tecladox, self.tecladoy = self.mid_w, self.mid_h + 0
self.cimax, self.cimay = self.mid_w, self.mid_h + 60
self.baixox, self.baixoy = self.mid_w, self.mid_h + 90
self.esquerdax, self.esquerday = self.mid_w, self.mid_h + 120
self.direitax, self.direitay = self.mid_w, self.mid_h + 150
self.troca_corx, self.troca_cory = self.mid_w, self.mid_h + 180
def display_menu(self):
self.run_display = True
while self.run_display:
self.game.check_events()
self.check_input()
self.game.display.blit(bg_image_2, (0, 0))
self.game.draw_text("Comandos", 40, self.game.DISPLAY_W / 2, self.game.DISPLAY_H / 2 - 120)
self.game.draw_text("Teclado", 30, self.tecladox, self.tecladoy)
self.game.draw_text("Andar para Cima : Seta Cima", 15, self.cimax, self.cimay)
self.game.draw_text("Andar para Baixo : Seta Baixo", 15, self.baixox, self.baixoy)
self.game.draw_text("Andar para Esquerda : Seta Esquerda", 15, self.esquerdax, self.esquerday)
self.game.draw_text("Andar para Direita : Seta Direita", 15, self.direitax, self.direitay)
self.game.draw_text("Trocar de cor : 1, 2 e 3", 15, self.troca_corx, self.troca_cory)
self.game.draw_text("Voltar: Backspace", 10, self.mid_w - 200, self.mid_h + 250)
self.game.draw_text("Avançar: Enter", 10, self.mid_w + 200, self.mid_h + 250)
self.draw_cursor()
self.blit_screen()
def check_input(self):
if self.game.BACK_KEY:
self.game.curr_menu = self.game.main_menu
self.run_display = False
elif self.game.START_KEY:
pass
class CreditsMenu(Menu):
def __init__(self, game):
Menu.__init__(self, game)
def display_menu(self):
self.run_display = True
while self.run_display:
self.game.check_events()
if self.game.START_KEY or self.game.BACK_KEY:
self.game.curr_menu = self.game.main_menu
self.run_display = False
self.game.display.blit(bg_image_2, (0, 0))
self.game.draw_text("Créditos", 40, self.game.DISPLAY_W / 2, self.game.DISPLAY_H / 2 - 60)
self.game.draw_text("Allysson Fellype Gomes Muniz (afgm2)", 25, self.game.DISPLAY_W / 2, self.game.DISPLAY_H / 2 + 10)
self.game.draw_text("Andreson Gomes de Lima (agl4)", 25, self.game.DISPLAY_W / 2, self.game.DISPLAY_H / 2 + 40)
self.game.draw_text("Cesar Moura (chcm)", 25, self.game.DISPLAY_W / 2, self.game.DISPLAY_H / 2 + 70)
self.game.draw_text("Jorge Francisco (jflj)", 25, self.game.DISPLAY_W / 2, self.game.DISPLAY_H / 2 + 100)
self.game.draw_text("Ruan Anselmo Santos de Lima (rasl)", 25, self.game.DISPLAY_W / 2, self.game.DISPLAY_H / 2 + 130)
self.game.draw_text("Vitor de Almeida Ferreira (vaf)", 25, self.game.DISPLAY_W / 2, self.game.DISPLAY_H / 2 + 160)
self.game.draw_text("Voltar: Backspace", 10, self.mid_w - 200, self.mid_h + 250)
self.game.draw_text("Avançar: Enter", 10, self.mid_w + 200, self.mid_h + 250)
self.blit_screen()
class EndMenu(Menu):
def __init__(self, game):
Menu.__init__(self, game)
def display_menu(self):
self.run_display = True
while self.run_display:
self.game.check_events()
if self.game.START_KEY or self.game.BACK_KEY:
self.game.curr_menu = self.game.main_menu
self.run_display = False
self.game.display.blit(bg_image_2, (0, 0))
self.game.draw_text("obrigado", 40, self.game.DISPLAY_W / 2, self.game.DISPLAY_H / 2)
self.game.draw_text("aperte backpspace para ir ao menu inicial", 20, self.game.DISPLAY_W / 2, self.game.DISPLAY_H / 2 + 60)
self.blit_screen()