-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.py
332 lines (262 loc) · 11.9 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
import pygame, math, my, game, threading, loading, random, lib.delayedfunc
from ui import ui, button, label, slider, checker, bar, input
from functools import partial
BACKGROUND = None
class Menu(ui.UI):
def __init__(self, screen):
ui.UI.__init__(self, screen)
global BACKGROUND
BACKGROUND = pygame.transform.scale(ui.IMAGES['background'], my.SCREEN_SIZE)
self.logo = label.Image([my.SCREEN_HALF_WIDTH, -my.SCREEN_HEIGHT], pygame.image.load("assets/logo.png"),
centralization=ui.BOTTOM)
self.addWidget(self.logo)
self.playOfflineButton = button.ImageButton(lambda: self.playOffline(),
[my.SCREEN_HALF_WIDTH, my.SCREEN_HEIGHT],
text="Jogar Offline",
image_surface=ui.IMAGES['button'],
image_pressed=ui.IMAGES['button_pressed'])
self.playOnlineButton = button.ImageButton(lambda: self.playOnline(),
[my.SCREEN_HALF_WIDTH, my.SCREEN_HEIGHT],
text="Jogar Online",
image_surface=ui.IMAGES['button'],
image_pressed=ui.IMAGES['button_pressed'])
self.optionsButton = button.ImageButton(lambda: self.options(),
[my.SCREEN_HALF_WIDTH, my.SCREEN_HEIGHT],
text="Opções",
image_surface=ui.IMAGES['button'],
image_pressed=ui.IMAGES['button_pressed'])
self.creditsButton = button.ImageButton(lambda: self.credits(),
[my.SCREEN_HALF_WIDTH, my.SCREEN_HEIGHT],
text="Créditos",
image_surface=ui.IMAGES['button'],
image_pressed=ui.IMAGES['button_pressed'])
self.addWidget(self.playOfflineButton)
self.addWidget(self.playOnlineButton)
self.addWidget(self.optionsButton)
self.addWidget(self.creditsButton)
self.addWidget(label.Text([my.SCREEN_WIDTH - 5, my.SCREEN_HEIGHT], "Tanks v" + my.VERSION, 20, centralization=ui.LEFT | ui.UPPER))
self.animation = True
self.readyToNext = False
self.next = self
def update(self, events):
self.screen.blit(BACKGROUND, (0, 0))
ui.UI.update(self, events)
if self.animation:
# TO UP
y = 0
for button in (self.playOfflineButton, self.playOnlineButton, self.optionsButton, self.creditsButton):
if button.pos[1] > my.SCREEN_HALF_HEIGHT + y:
button.pos[1] -= int(math.fabs(my.SCREEN_HALF_HEIGHT + y - button.pos[1]) * 0.1)
y += 60
# TO DOWN
if self.logo.pos[1] < 0:
self.logo.pos[1] += math.fabs(self.logo.pos[1]) * 0.1
else:
# TO UP
y = 0
for button in (self.playOfflineButton, self.playOnlineButton, self.optionsButton, self.creditsButton):
if button.pos[1] < my.SCREEN_HEIGHT:
button.pos[1] += (my.SCREEN_HEIGHT + y - button.pos[1]) * 0.1
y += 60
# TO DOWN
if self.logo.pos[1] < 0:
self.logo.pos[1] += math.fabs(self.logo.pos[1]) * 0.1
return self.next
def playOffline(self):
self.animation = False
self.next = PlayOfflineMenu(self.screen)
def playOnline(self):
self.animation = False
self.next = PlayOnlineMenu(self.screen)
def options(self):
self.animation = False
self.next = OptionsMenu(self.screen)
def credits(self):
self.animation = False
self.next = CreditsMenu(self.screen)
class PlayOfflineMenu(ui.UI):
def __init__(self, screen):
ui.UI.__init__(self, screen)
self.addWidget(label.Text([50, 50], "Configure o jogo:", fontsize=18, centralization=ui.RIGHT))
self.addWidget(input.TextBox(partial(self.inputName), [my.SCREEN_HALF_WIDTH, my.SCREEN_HEIGHT // 6], [300, 40],
'Digite seu nicknme',
box_image=ui.IMAGES['button']))
self.nickname = 'Jogador'
self.enemiesValue = label.Text([my.SCREEN_HALF_WIDTH + 50, my.SCREEN_HALF_HEIGHT // 2 + 40], "5", fontsize=18)
self.addWidget(self.enemiesValue)
self.addWidget(label.Text([my.SCREEN_HALF_WIDTH - 10, my.SCREEN_HALF_HEIGHT // 2 + 40], "Inimigos", fontsize=18))
self.addWidget(slider.SliderBar(partial(self.sliderEnemies), [my.SCREEN_HALF_WIDTH, my.SCREEN_HEIGHT // 3 + 32], (200, 5),
min=1, max=10, step=1,
initial=5,
image_slider=ui.IMAGES['slider'],
image_pointer=ui.IMAGES['slider_pointer']))
self.mapSize = [my.SCREEN_WIDTH, my.SCREEN_HEIGHT + 200]
contents = []
for i in range(0, 500, 100):
contents.append(str(my.SCREEN_WIDTH + i) + ' x ' + str(my.SCREEN_HEIGHT + 200))
self.addWidget(button.Drop(self, contents,
partial(self.selectMapSize),
[my.SCREEN_HALF_WIDTH, my.SCREEN_HALF_HEIGHT],
text="Tamanho do Mapa",
image_surface=pygame.transform.scale(ui.IMAGES['button'], (270, 50)),
image_pressed=pygame.transform.scale(ui.IMAGES['button_pressed'], (270, 50)),
down=True))
self.addWidget(button.ImageButton(lambda: self.back(),
[my.SCREEN_HALF_WIDTH - 20, my.SCREEN_HEIGHT - (my.SCREEN_HEIGHT // 6)],
text="Voltar",
image_surface=ui.IMAGES['button'],
image_pressed=ui.IMAGES['button_pressed'],
centralization=ui.LEFT))
self.addWidget(button.ImageButton(lambda: self.startGame(),
[my.SCREEN_HALF_WIDTH + 20, my.SCREEN_HEIGHT - (my.SCREEN_HEIGHT // 6)],
text="Iniciar Jogo",
image_surface=ui.IMAGES['button_green'],
image_pressed=ui.IMAGES['button_green_pressed'],
centralization=ui.RIGHT))
self.next = self
def update(self, events):
self.screen.blit(BACKGROUND, (0, 0))
ui.UI.update(self, events)
return self.next
def sliderEnemies(self, value):
self.enemiesValue.text = str(value)
def inputName(self, value):
self.nickname = str(value)
def selectMapSize(self, value):
self.mapSize.clear()
self.mapSize.append(int(value.split(' x ')[0]))
self.mapSize.append(int(value.split(' x ')[1]))
def back(self):
self.next = Menu(self.screen)
def startGame(self):
def start():
gameConfigurations = [int(self.enemiesValue.text)]
playerConfigurations = [self.nickname]
mapConfigurations = [self.mapSize[0], self.mapSize[1], random.randint(1000, 10000)]
my.ENGINE.game = game.GameOffline(gameConfigurations, playerConfigurations, mapConfigurations)
my.ENGINE.game.start()
threadStarting = threading.Thread(target=start)
threadStarting.start()
my.ENGINE.game.hud = loading.Loading(my.ENGINE.screen)
self.next = my.ENGINE.game.hud
class PlayOnlineMenu(ui.UI):
def __init__(self, screen):
ui.UI.__init__(self, screen)
self.addWidget(label.Text(my.SCREEN_HALF_SIZE, "Em desenvolvimento...", fontsize=24))
self.addWidget(button.ImageButton(lambda: self.back(),
[my.SCREEN_HALF_WIDTH, my.SCREEN_HEIGHT - (my.SCREEN_HEIGHT // 6)],
text="Voltar",
image_surface=ui.IMAGES['button'],
image_pressed=ui.IMAGES['button_pressed']))
self.next = self
def update(self, events):
self.screen.blit(BACKGROUND, (0, 0))
ui.UI.update(self, events)
return self.next
def back(self):
self.next = Menu(self.screen)
class OptionsMenu(ui.UI):
def __init__(self, screen):
ui.UI.__init__(self, screen)
self.fpsValue = label.Text([my.SCREEN_HALF_WIDTH + 25, my.SCREEN_HEIGHT // 6], str(my.FPS), fontsize=20)
self.addWidget(self.fpsValue)
self.addWidget(label.Text([my.SCREEN_HALF_WIDTH - 25, my.SCREEN_HEIGHT // 6], "FPS", fontsize=20))
self.addWidget(slider.SliderBar(partial(self.sliderFps), [my.SCREEN_HALF_WIDTH, my.SCREEN_HEIGHT // 4], (300, 5), min=20,
max=200, step=1,
initial=my.FPS,
image_slider=ui.IMAGES['slider'],
image_pointer=ui.IMAGES['slider_pointer']))
contents = []
modes = pygame.display.list_modes()
for mode in range(0, len(modes) - 5): # -5 = Tirando os 5 menores valores pois é pequeno até demais pro jogo
contents.append(str(modes[mode][0]) + ' x ' + str(modes[mode][1]) + (' (FULL)' if mode == 0 else ''))
self.addWidget(button.Drop(self, contents,
partial(self.selectResolution),
[my.SCREEN_HALF_WIDTH, my.SCREEN_HALF_HEIGHT - 50],
text="Resolução",
image_surface=ui.IMAGES['button'],
image_pressed=ui.IMAGES['button_pressed'],
down=True))
self.addWidget(label.Text([my.SCREEN_HALF_WIDTH + 30, my.SCREEN_HALF_HEIGHT], "Acelerar CPU (tela cheia)", fontsize=20))
self.addWidget(checker.Checker(partial(self.checkedHardware),
[my.SCREEN_HALF_WIDTH - 150, my.SCREEN_HALF_HEIGHT],
checked=my.HARDWARE_ACCELERATED,
image=ui.IMAGES['box'],
image_checked=ui.IMAGES['box_checked']))
self.addWidget(label.Text([my.SCREEN_HALF_WIDTH + 20, my.SCREEN_HALF_HEIGHT + 40], "Áudio, sons e vozes", fontsize=20))
self.addWidget(checker.Checker(partial(self.checkedAudio),
[my.SCREEN_HALF_WIDTH - 150, my.SCREEN_HALF_HEIGHT + 40],
checked=not my.MUTED,
image=ui.IMAGES['box'],
image_checked=ui.IMAGES['box_checked']))
self.addWidget(button.ImageButton(lambda: self.back(),
[my.SCREEN_HALF_WIDTH - 20, my.SCREEN_HEIGHT - (my.SCREEN_HEIGHT // 6)],
text="Voltar",
image_surface=ui.IMAGES['button'],
image_pressed=ui.IMAGES['button_pressed'],
centralization=ui.LEFT))
self.addWidget(button.ImageButton(lambda: self.save(),
[my.SCREEN_HALF_WIDTH + 20, my.SCREEN_HEIGHT - (my.SCREEN_HEIGHT // 6)],
text="Salvar",
image_surface=ui.IMAGES['button_green'],
image_pressed=ui.IMAGES['button_green_pressed'],
centralization=ui.RIGHT))
self.next = self
def update(self, events):
self.screen.blit(BACKGROUND, (0, 0))
ui.UI.update(self, events)
return self.next
def sliderFps(self, value):
self.fpsValue.text = str(value)
my.CONFIG.set('fps', value)
def selectResolution(self, value):
if '(FULL)' in value:
my.CONFIG.set('windowed', False)
my.CONFIG.set('screen_width', int(value.split(" x ")[0]))
my.CONFIG.set('screen_height', int(value.split(" x ")[1].split(" ")[0]))
else:
my.CONFIG.set('windowed', True)
my.CONFIG.set('screen_width', int(value.split(" x ")[0]))
my.CONFIG.set('screen_height', int(value.split(" x ")[1]))
def checkedHardware(self, value):
my.CONFIG.set('hardware_accelerated', value)
def checkedAudio(self, value):
my.CONFIG.set('muted', not value)
def back(self):
self.next = Menu(self.screen)
def save(self):
my.FPS = my.CONFIG.get('fps')
my.HARDWARE_ACCELERATED = my.CONFIG.get('hardware_accelerated')
my.MUTED = my.CONFIG.get('muted')
oldwidth, oldwindowed = my.SCREEN_WIDTH, my.WINDOWED
my.WINDOWED = my.CONFIG.get('windowed')
my.SCREEN_WIDTH = my.CONFIG.get('screen_width')
my.SCREEN_HEIGHT = my.CONFIG.get('screen_height')
my.SCREEN_HALF_WIDTH = my.CONFIG.get('screen_width') / 2
my.SCREEN_HALF_HEIGHT = my.CONFIG.get('screen_height') / 2
my.SCREEN_SIZE = (my.SCREEN_WIDTH, my.SCREEN_HEIGHT)
my.SCREEN_HALF_SIZE = (my.SCREEN_HALF_WIDTH, my.SCREEN_HALF_HEIGHT)
if my.CONFIG.get('screen_width') != oldwidth or my.CONFIG.get('windowed') != oldwindowed:
my.ENGINE.adaptScreen()
my.CONFIG.save()
self.next = Menu(self.screen)
class CreditsMenu(ui.UI):
def __init__(self, screen):
ui.UI.__init__(self, screen)
self.addWidget(label.Text([my.SCREEN_HALF_WIDTH, 100], "Desenvolvido por:", fontsize=24))
self.addWidget(label.Text([my.SCREEN_HALF_WIDTH, 140], "Willian Gois ~the coder guy", fontsize=20))
self.addWidget(label.Text([my.SCREEN_HALF_WIDTH, 160], "Lucas Verona ~the h4ck3r m4n", fontsize=20))
self.addWidget(label.Text([my.SCREEN_HALF_WIDTH, 220], "Texturas por:", fontsize=24))
self.addWidget(label.Text([my.SCREEN_HALF_WIDTH, 260], "(UI): Kenney Vleugels (www.kenney.nl)", fontsize=20))
self.addWidget(button.ImageButton(lambda: self.back(),
[my.SCREEN_HALF_WIDTH, my.SCREEN_HEIGHT - (my.SCREEN_HEIGHT // 6)],
text="Voltar",
image_surface=ui.IMAGES['button'],
image_pressed=ui.IMAGES['button_pressed']))
self.next = self
def update(self, events):
self.screen.blit(BACKGROUND, (0, 0))
ui.UI.update(self, events)
return self.next
def back(self):
self.next = Menu(self.screen)