-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage_one.py
561 lines (502 loc) · 23.5 KB
/
stage_one.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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
from random import Random
from time import time
import pygame
from pygame.locals import *
import attacks
import collectibles
import movement
import pause
import player
FPS = 60
SCREEN_WIDTH = 512
SCREEN_HEIGHT = 740
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
TURQUOISE = (0, 255, 255)
YELLOW = (255, 255, 0)
FAST = 5
SLOW = 2.5
vec = pygame.math.Vector2
clear_icon = pygame.image.load("res/img/clear.png")
life_icon = pygame.image.load("res/img/life.png")
def StageOne(boss, magic_circle, bullets, sprites, players, orbs,
screen, font, clock, points, player_one, player_magic_circle,
lives, pause_differential, joysticks, options):
background = pygame.image.load("res/img/background6.png")
best_time = time() - time()
current_time = time() - time()
start_time = time()
rand = Random()
phase_counter = 0
frame_counter = 0
ticker = 0
best_points = 0
death_loc = vec(0, 0)
death = False
death_counter = 1
graze_counter = 0
best_graze = 0
last_graze_hit = False
total_graze = 0
total_gems = 0
extend_10k = False
extend_25k = False
extend_50k = False
inv_text = font.render("INVINCIBLE", True, WHITE)
inv_text_rect = inv_text.get_rect(center=(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 40))
warning_image = pygame.image.load("res/img/warning.png")
stage_one_theme = pygame.mixer.Sound("res/audio/stage_one_theme.ogg")
stage_one_theme.set_volume(float(options["music_volume"]))
player_one.up = False
player_one.down = False
player_one.left = False
player_one.right = False
stage_one_theme.play()
stage = True
while stage:
for event in pygame.event.get():
if event.type == pygame.QUIT:
stage = False
return 0, points, total_graze, total_gems, player_one.clears, \
False, lives, pause_differential, player_one, extend_10k, \
extend_25k, extend_50k
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
player_one.up = True
if event.key == pygame.K_DOWN:
player_one.down = True
if event.key == pygame.K_LEFT:
player_one.left = True
if event.key == pygame.K_RIGHT:
player_one.right = True
if event.key == pygame.K_LSHIFT:
player_one.speed = SLOW
if event.key == pygame.K_p or event.key == pygame.K_ESCAPE:
pygame.mixer.pause()
pause_start = time()
unpause = pause.PauseGame(font, screen, joysticks)
pause_end = time()
pygame.mixer.unpause()
pause_differential += pause_end - pause_start
if unpause == 2:
stage_one_theme.stop()
stage_one_theme.play()
player_one.kill()
for obj in bullets:
obj.kill()
total_graze = 0
current_time = time() - time()
start_time = time()
points = 0
total_gems = 0
frame_counter = 0
phase_counter = 0
ticker = 0
lives = 2
extend_10k = False
extend_25k = False
extend_50k = False
player_one = player.Player(256, 660)
sprites.add(player_one)
players.add(player_one)
if not unpause:
stage = False
return 0, points, total_graze, total_gems, player_one.clears, \
False, lives, pause_differential, player_one, extend_10k, \
extend_25k, extend_50k
if event.key == pygame.K_z and player_one.spawn_timer == 0:
if player_one.clears > 0:
player_one.clears -= 1
for bullet in bullets:
new_orb = collectibles.PointsOrb(bullet.pos.x, bullet.pos.y)
sprites.add(new_orb)
orbs.add(new_orb)
total_gems += bullet.gems
bullet.kill()
if event.type == pygame.KEYUP:
if event.key == pygame.K_UP:
player_one.up = False
if event.key == pygame.K_DOWN:
player_one.down = False
if event.key == pygame.K_LEFT:
player_one.left = False
if event.key == pygame.K_RIGHT:
player_one.right = False
if event.key == pygame.K_LSHIFT:
player_one.speed = FAST
if event.type == JOYBUTTONDOWN:
if event.button == 1 and player_one.spawn_timer == 0:
if player_one.clears > 0:
player_one.clears -= 1
for bullet in bullets:
new_orb = collectibles.PointsOrb(bullet.pos.x, bullet.pos.y)
sprites.add(new_orb)
orbs.add(new_orb)
total_gems += bullet.gems
bullet.kill()
if event.button == 7:
player_one.speed = SLOW
if event.button == 9:
pause_start = time()
unpause = pause.PauseGame(font, screen, joysticks)
pause_end = time()
pause_differential += pause_end - pause_start
if unpause == 2:
player_one.kill()
for obj in bullets:
obj.kill()
total_graze = 0
current_time = time() - time()
start_time = time()
points = 0
total_gems = 0
frame_counter = 0
phase_counter = 0
ticker = 0
lives = 2
extend_10k = False
extend_25k = False
extend_50k = False
player_one = player.Player(256, 660)
sprites.add(player_one)
players.add(player_one)
if not unpause:
stage = False
return 0, points, total_graze, total_gems, player_one.clears, \
False, lives, pause_differential, player_one, extend_10k, \
extend_25k, extend_50k
if event.type == JOYBUTTONUP:
if event.button == 7:
player_one.speed = FAST
if event.type == JOYAXISMOTION:
if event.axis == 4:
if event.value < 0:
player_one.up = True
elif event.value > 0:
player_one.down = True
elif event.value == 0:
player_one.up = False
player_one.down = False
if event.axis == 3:
if event.value < 0:
player_one.left = True
elif event.value > 0:
player_one.right = True
elif event.value == 0:
player_one.left = False
player_one.right = False
if event.type == JOYDEVICEADDED:
joysticks = [pygame.joystick.Joystick(i) for i in range(pygame.joystick.get_count())]
for joystick in joysticks:
print(joystick.get_name())
if event.type == JOYDEVICEREMOVED:
joysticks = [pygame.joystick.Joystick(i) for i in range(pygame.joystick.get_count())]
# PHASE TRANSITION / RESET
if phase_counter < 200:
at_position = movement.FrameMove(boss.pos, vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3))
if not at_position:
magic_circle.fast = True
magic_circle.rect.center = boss.rect.center
# PHASE ONE
if phase_counter <= 1800:
magic_circle.fast = False
if frame_counter % 25 == 0:
if ticker < 20:
ticker += 1
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3), ticker, "b", ticker * 10, bullets,
sprites)
if frame_counter % 100 == 0:
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3), ticker / 2, "w", 0, bullets, sprites)
if frame_counter % 245 == 0 or frame_counter % 250 == 0:
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3), ticker * 2, "s", ticker, bullets,
sprites)
if frame_counter == 500:
frame_counter = 0
# PHASE TRANSITION
if 1800 < phase_counter < 1980:
at_position = movement.FrameMove(boss.pos, vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4))
if not at_position:
magic_circle.fast = True
magic_circle.rect.center = boss.rect.center
# PHASE TWO
if 1980 <= phase_counter <= 3780:
magic_circle.fast = False
if frame_counter % 30 == 0:
if ticker < 30:
ticker += 2
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4),
3, "b", rand.randint(0, 360), bullets, sprites)
if frame_counter % 60 == 0:
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4),
2, "s", rand.randint(0, 360), bullets, sprites)
if frame_counter % 120 == 0:
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4), ticker * 2, "w", 0, bullets, sprites)
if frame_counter == 480:
frame_counter = 0
# PHASE TRANSITION
if 3780 < phase_counter < 3960:
at_position = movement.FrameMove(boss.pos, vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3))
if not at_position:
magic_circle.fast = True
magic_circle.rect.center = boss.rect.center
# PHASE THREE
if 3960 <= phase_counter <= 5760:
magic_circle.fast = False
if frame_counter % 30 == 0:
if ticker < 30:
ticker += 1
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3), ticker, "s2", ticker * 10, bullets,
sprites)
if frame_counter % 100 == 0:
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3), ticker / 5, "s3", ticker * 2, bullets,
sprites)
if frame_counter % 300 == 0:
attacks.BarSpawner(32, 20, 90, "b2", bullets, sprites)
if frame_counter == 600:
frame_counter = 0
# phase transition
if 5760 < phase_counter < 5940:
at_position = movement.FrameMove(boss.pos, vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 8))
if not at_position:
magic_circle.fast = True
magic_circle.rect.center = boss.rect.center
# PHASE FOUR
if 5940 <= phase_counter <= 7740:
magic_circle.fast = False
if frame_counter % 60 == 0:
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 8),
50, "b", rand.randint(45, 135), bullets, sprites)
if frame_counter % 200 == 0:
attacks.BarSpawner(SCREEN_HEIGHT / 8, 20, 90, "w", bullets, sprites)
if frame_counter % 300 == 0:
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2),
25, "s", rand.randint(0, 360), bullets, sprites)
if frame_counter == 600 == 0:
frame_counter = 0
# PHASE TRANSITION
if 7740 < phase_counter < 7800:
at_position = movement.FrameMove(boss.pos, vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 10))
if not at_position:
magic_circle.fast = True
magic_circle.rect.center = boss.rect.center
# PHASE FOUR AND A HALF
if 7800 <= phase_counter <= 8020:
magic_circle.fast = False
if frame_counter % 10 == 0:
attacks.BarSpawner(32, 10, rand.randint(45, 135), "b2", bullets, sprites)
if frame_counter == 60:
frame_counter = 0
# PHASE TRANSITION
if 8020 < phase_counter < 8200:
at_position = movement.FrameMove(boss.pos, vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2))
if not at_position:
magic_circle.fast = True
magic_circle.rect.center = boss.rect.center
if phase_counter == 8199:
for bullet in bullets:
bullet.kill()
# PHASE FIVE
if 8200 <= phase_counter <= 10000:
magic_circle.fast = False
if frame_counter % 30 == 0:
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2),
5, "b2", rand.randint(45, 135), bullets, sprites)
if frame_counter % 90 == 0:
attacks.CircleSpawner(vec(SCREEN_WIDTH / 2, 8),
40, "s3", rand.randint(0, 360), bullets, sprites)
if frame_counter % 180 == 0:
attacks.BarSpawner(SCREEN_HEIGHT - 8, 20, 270, "w", bullets, sprites)
if frame_counter % 360 == 0:
frame_counter = 0
# END STAGE
if phase_counter == 10000:
for bullet in bullets:
bullet.kill()
if phase_counter > 10300:
magic_circle.fast = False
stage = False
return 1, points, total_graze, total_gems, player_one.clears, True, lives, pause_differential, player_one, \
extend_10k, extend_25k, extend_50k
# HANDLE PLAYER
player_one.move()
player_magic_circle.rect.center = player_one.rect.center
for orb in orbs:
if orb.pos != player_one.pos:
if player_one.pos.x - orb.pos.x > 400 or player_one.pos.y - orb.pos.y > 400:
orb.pos += (player_one.pos - orb.pos) / 32
elif player_one.pos.x - orb.pos.x > 200 or player_one.pos.y - orb.pos.y > 200:
orb.pos += (player_one.pos - orb.pos) / 16
elif player_one.pos.x - orb.pos.x > 100 or player_one.pos.y - orb.pos.y > 100:
orb.pos += (player_one.pos - orb.pos) / 8
else:
orb.pos += (player_one.pos - orb.pos) / 4
for bullet in bullets:
player_one_hit = pygame.sprite.collide_mask(player_one, bullet)
if player_one_hit and player_one.spawn_timer == 0:
if options["auto_clear"] == "on" and player_one.clears > 0:
player_one.clears -= 1
for bullet in bullets:
new_orb = collectibles.PointsOrb(bullet.pos.x, bullet.pos.y)
sprites.add(new_orb)
orbs.add(new_orb)
total_gems += bullet.gems
bullet.kill()
else:
death = True
death_loc = player_one.rect.center
player_one.kill()
for obj in bullets:
obj.kill()
if options["keep_graze"] == "off":
total_graze = 0
if lives == 0:
stage = False
return 1, points, total_graze, total_gems, player_one.clears, \
False, lives, pause_differential, player_one, extend_10k, \
extend_25k, extend_50k
else:
lives -= 1
player_one = player.Player(256, 660)
sprites.add(player_one)
players.add(player_one)
if bullet.rect.center[0] < -8:
bullet.kill()
elif bullet.rect.center[0] > SCREEN_WIDTH + 8:
bullet.kill()
elif bullet.rect.center[1] > SCREEN_HEIGHT + 8:
bullet.kill()
elif bullet.rect.center[1] < -8:
bullet.kill()
graze_hit = pygame.sprite.spritecollide(player_one, bullets, False)
if graze_hit:
player_magic_circle.fast = True
player_one.grazing = True
if last_graze_hit:
graze_counter += 1
total_graze += 1
if total_graze != 0 and total_graze % 1000 == 0 and player_one.clears < 5:
player_one.clears += 1
else:
player_magic_circle.fast = False
player_one.grazing = False
if last_graze_hit:
if graze_counter > best_graze:
best_graze = graze_counter
graze_counter = 0
last_graze_hit = player_one.grazing
orb_hits = pygame.sprite.spritecollide(player_one, orbs, True)
if orb_hits:
for hit in orb_hits:
points += 5
# DRAW TO SCREEN
screen.blit(background, background.get_rect())
for obj in sprites:
obj.draw(screen)
obj.update()
player_one.draw(screen)
if death:
explosion = pygame.image.load(f"res/img/pop{death_counter}.png")
explosion_rect = explosion.get_rect(center=death_loc)
screen.blit(explosion, explosion_rect)
if phase_counter % 5 == 0:
death_counter += 1
if death_counter > 5:
death_counter = 1
death = False
points_text = font.render(f"{points}", True, WHITE)
points_text_rect = points_text.get_rect(center=(SCREEN_WIDTH - 80, 40))
total_gems_text = font.render(f"{total_gems}", True, YELLOW)
total_gems_text_rect = total_gems_text.get_rect(center=(80, 40))
graze_count_text = font.render(f"{graze_counter}", True, TURQUOISE)
graze_count_text_rect = graze_count_text.get_rect(center=(SCREEN_WIDTH - 80, 60))
total_graze_text = font.render(f"{total_graze}", True, TURQUOISE)
total_graze_text_rect = total_graze_text.get_rect(center=(80, 60))
if phase_counter < 10000:
screen.blit(points_text, points_text_rect)
else:
if phase_counter % 10 < 5:
screen.blit(points_text, points_text_rect)
screen.blit(total_gems_text, total_gems_text_rect)
screen.blit(graze_count_text, graze_count_text_rect)
screen.blit(total_graze_text, total_graze_text_rect)
if player_one.clears > 0:
clears = player_one.clears
while clears > 0:
screen.blit(clear_icon, clear_icon.get_rect(center=((40 * clears), SCREEN_HEIGHT - 40)))
clears -= 1
if lives > 0:
lives_index = lives
while lives_index > 0:
screen.blit(life_icon,
life_icon.get_rect(center=((SCREEN_WIDTH - (40 * lives_index)), SCREEN_HEIGHT - 40)))
lives_index -= 1
if phase_counter <= 300:
if phase_counter % 60 < 30:
phase_text = font.render("PHASE ONE", True, WHITE)
phase_text_rect = phase_text.get_rect(center=(SCREEN_WIDTH / 2, 40))
screen.blit(phase_text, phase_text_rect)
if 1980 <= phase_counter <= 2280:
if phase_counter % 60 < 30:
phase_text = font.render("PHASE TWO", True, WHITE)
phase_text_rect = phase_text.get_rect(center=(SCREEN_WIDTH / 2, 40))
screen.blit(phase_text, phase_text_rect)
if 3960 <= phase_counter <= 4260:
if phase_counter % 60 < 30:
phase_text = font.render("PHASE THREE", True, WHITE)
phase_text_rect = phase_text.get_rect(center=(SCREEN_WIDTH / 2, 40))
screen.blit(phase_text, phase_text_rect)
if 5940 <= phase_counter <= 6240:
if phase_counter % 60 < 30:
phase_text = font.render("PHASE FOUR", True, WHITE)
phase_text_rect = phase_text.get_rect(center=(SCREEN_WIDTH / 2, 40))
screen.blit(phase_text, phase_text_rect)
if phase_counter % 80 < 50:
if phase_counter % 10 < 5:
warning_image_rect = warning_image.get_rect(
center=(SCREEN_WIDTH / 2, SCREEN_HEIGHT - (SCREEN_HEIGHT / 2)))
screen.blit(warning_image, warning_image_rect)
if 8200 <= phase_counter <= 8500:
if phase_counter % 60 < 30:
phase_text = font.render("PHASE FIVE", True, WHITE)
phase_text_rect = phase_text.get_rect(center=(SCREEN_WIDTH / 2, 40))
screen.blit(phase_text, phase_text_rect)
if phase_counter % 80 < 50:
if phase_counter % 10 < 5:
warning_image_rect = warning_image.get_rect(
center=(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 40))
screen.blit(warning_image, warning_image_rect)
if 10000 <= phase_counter <= 10300:
if phase_counter % 60 < 30:
phase_text = font.render("STAGE CLEAR", True, TURQUOISE)
phase_text_rect = phase_text.get_rect(center=(SCREEN_WIDTH / 2, 40))
screen.blit(phase_text, phase_text_rect)
if player_one.spawn_timer > 0:
if phase_counter % 20 < 10:
screen.blit(inv_text, inv_text_rect)
# FRAME UPKEEP
pygame.display.flip()
clock.tick(FPS)
frame_counter += 1
phase_counter += 1
if phase_counter < 10000:
if player_one.grazing:
if 1000 <= graze_counter < 2500:
points += 3
elif graze_counter > 2500:
points += 4
else:
points += 2
else:
points += 1
if points > 10000 and not extend_10k:
extend_10k = True
if lives < 3:
lives += 1
if points > 25000 and not extend_25k:
extend_25k = True
if lives < 3:
lives += 1
if points > 50000 and not extend_50k:
extend_50k = True
if lives < 3:
lives += 1