-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathStart.py
More file actions
329 lines (171 loc) · 6.42 KB
/
Start.py
File metadata and controls
329 lines (171 loc) · 6.42 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
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
#!/usr/bin/env python
#
#
#
#
import pygame
import math
import os
import re
class Start:
def __init__(self, screen, menus):
self.screen = screen
self.channels = [pygame.mixer.Channel(0), pygame.mixer.Channel(15)]
self.menus = menus
self.images = self._load_images()
self.audio = self._load_audio()
# Animation
self.opacity = 255
self.opacity_fadespeed = 15
self.text = Text("LEGEND HAS IT THERE IS A BABE AT THE TOP...")
self.title_logo = Title(self.images)
self.Nexile_Logo_Counter = 500
self.complete = False
def _load_audio(self):
audio = {}
for audio_name in os.listdir("audio\\start"):
audio[re.match(r"[^.]+", audio_name).group()] = pygame.mixer.Sound(f"audio\\start\\{audio_name}")
return audio
def _load_images(self):
images = {}
for image_name in os.listdir("images\\logos"):
images[re.match(r"[^.]+", image_name).group()] = pygame.image.load(f"images\\logos\\{image_name}").convert_alpha()
return images
def blit_nexile_logo(self):
if self.Nexile_Logo_Counter > 100:
self.screen.fill((255, 255, 255))
self.screen.blit(self.images["JK_Nexile_Logo"], ((self.screen.get_width() - self.images["JK_Nexile_Logo"].get_width()) / 2, (self.screen.get_height() - self.images["JK_Nexile_Logo"].get_height()) / 2))
self.Nexile_Logo_Counter -= 1
def blitme(self):
if not os.environ["start"]:
if self.Nexile_Logo_Counter:
self.blit_nexile_logo()
else:
self.title_logo.blitme(self.screen)
else:
self.title_logo.blitme(self.screen)
if os.environ["active"]:
if not self.title_logo.fadecomplete:
self.title_logo.blitme(self.screen)
elif self.title_logo.fadecomplete and not self.text.fadecomplete:
self.text.blitme(self.screen)
def update(self):
if not os.environ["start"]:
if self.Nexile_Logo_Counter:
pass
elif self.title_logo.y != self.title_logo.end and not self.title_logo.complete:
if not self.channels[0].get_busy():
self.channels[0].play(self.audio["menu_intro"])
self.title_logo.move_up()
self.title_logo.brighten()
else:
if not self.title_logo.complete:
self.channels[1].play(self.audio["title_hit"])
if not self.channels[0].get_busy():
self.channels[0].play(self.audio["menu_loop"])
self.title_logo.complete = True
self.title_logo.shake()
self.menus.current_menu = self.menus.menus["Press_Start"]
self.menus.current_menu.active = True
if os.environ["active"]:
self.title_logo.fade()
for channel in self.channels:
channel.stop()
if self.title_logo.fadecomplete and not self.text.complete:
self.text.brighten()
elif self.text.complete and not self.text.fadecomplete:
self.text.fade()
elif self.text.fadecomplete and not self.complete:
self.fade()
elif self.complete:
self.reset()
os.environ["gaming"] = "1"
os.environ["pause"] = ""
def fade(self):
if self.opacity > 0:
self.opacity -= self.opacity_fadespeed
elif self.opacity == 0:
self.complete = True
def reset(self):
self.opacity = 255
self.Nexile_Logo_Counter = 500
self.complete = False
self.title_logo.reset()
self.text.reset()
class Title:
def __init__(self, images):
self.images = images
self.shake_counter, self.shake_interval, self.shake_length = 21, 3, 5
self.start, self.end = round(int(os.environ.get("screen_width")) / 4), round(int(os.environ.get("screen_height")) / 8)
self.opacity = 0
self.opacity_fadespeed = 5
self.speed = 0.5
self.width, self.height = self.images["title_logo"].get_size()
self.x, self.y = round((int(os.environ.get("screen_width")) - self.width) / 2), self.start
self.complete = False
self.fadecomplete = False
self.inititated = False
def reset(self):
self.shake_counter, self.shake_interval, self.shake_length = 21, 3, 5
self.start, self.end = round(int(os.environ.get("screen_width")) / 4), round(int(os.environ.get("screen_height")) / 8)
self.opacity = 0
self.opacity_fadespeed = 5
self.speed = 0.5
self.width, self.height = self.images["title_logo"].get_size()
self.x, self.y = round((int(os.environ.get("screen_width")) - self.width) / 2), self.start
self.complete = False
self.fadecomplete = False
self.inititated = False
def brighten(self):
self.opacity = int(255 * (1 - (self.y - self.end) / (self.start - self.end)))
def fade(self):
if self.opacity > 0:
self.opacity -= self.opacity_fadespeed
else:
self.fadecomplete = True
def shake(self):
if self.shake_counter:
if not self.shake_counter // self.shake_interval % 2:
self.y = self.end - self.shake_length
elif self.shake_counter // self.shake_interval % 2:
self.y = self.end + self.shake_length
self.shake_counter -= 1
def blitme(self, screen):
image = self.images["title_logo"].copy()
middle_screen = pygame.Surface(image.get_size(), pygame.SRCALPHA)
middle_screen.fill((255, 255, 255, self.opacity))
image.blit(middle_screen, (0, 0), special_flags = pygame.BLEND_RGBA_MULT)
screen.blit(image, (int(self.x), int(self.y)))
def move_up(self):
self.y -= self.speed
class Text(Title):
def __init__(self, text):
self.font = pygame.font.Font("Fonts\\ttf_pixolde_bold.ttf", 20)
self.text = self._fold(text)
self.opacity = 0
self.opacity_fadespeed = 1
self.complete = False
self.fadecomplete = False
def reset(self):
self.opacity = 0
self.opacity_fadespeed = 1
self.complete = False
self.fadecomplete = False
def _fold(self, text):
t = []
for index, line in enumerate(map(lambda x: x[0], re.findall(r"(([^ .,!?]+[ .,!?]*){0,6})", text))):
t.append(self.font.render(line, True, (255, 255, 255)))
return t
def blitme(self, screen):
text_screen = pygame.Surface((max([text.get_width() for text in self.text]), sum([text.get_height() for text in self.text])), pygame.SRCALPHA)
middle_screen = pygame.Surface(text_screen.get_size(), pygame.SRCALPHA)
middle_screen.fill((255, 255, 255, self.opacity))
for index, text in enumerate(self.text):
text_screen.blit(text, ((text_screen.get_width() - text.get_width()) / 2, (index)*text.get_height()))
text_screen.blit(middle_screen, (0, 0), special_flags = pygame.BLEND_RGBA_MULT)
screen.blit(text_screen, ((screen.get_width() - text_screen.get_width()) / 2, (screen.get_height() - text_screen.get_height()) / 2))
def brighten(self):
if self.opacity != 255:
self.opacity += self.opacity_fadespeed
elif self.opacity == 255:
self.complete = True