generated from StRobertCHSCS/python-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaser_animation.py
826 lines (605 loc) · 28.4 KB
/
laser_animation.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
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
import random
import arcade
WIDTH = 1000
HEIGHT = 750
#rain = arcade.ShapeElementList()
# first set up empty lists
human_x_positions = []
human_y_positions = []
alien_x_positions = []
alien_y_positions = []
meteor_x_positions = []
meteor_y_positions = []
alien_meteor_x_positions = []
alien_meteor_y_positions = []
human_x_positions_shooting_star = []
human_y_positions_shooting_star = []
alien_x_positions_shooting_star = []
alien_y_positions_shooting_star = []
human_x_positions_laser = []
human_y_positions_laser = []
alien_x_positions_laser = []
alien_y_positions_laser = []
draw_enemy_rate = 4
draw_meteor_rate = 2
draw_shooting_star_rate = 1
game_speed = 3
human_times_hit = 0
alien_times_hit = 0
elapsed_time = 0
time = False
if 19.00 < elapsed_time < 21.00 or 39.00 < elapsed_time < 41.00:
draw_enemy_rate += 1
draw_meteor_rate += 1
for _ in range(draw_enemy_rate):
# generate random x and y values
x_human = random.randrange(WIDTH/2 + 75, WIDTH - 75)
y_human = random.randrange(HEIGHT, HEIGHT * 2)
x_alien = random.randrange(75, WIDTH/2 - 75)
y_alien = random.randrange(HEIGHT, HEIGHT * 2)
# append the x and y values to the appropriate list
human_x_positions.append(x_human)
human_y_positions.append(y_human)
alien_x_positions.append(x_alien)
alien_y_positions.append(y_alien)
# this is the meteor's repeat, and i made it a little less than the humans/aliens so there's less of them
for _ in range(draw_meteor_rate):
# generate random x and y values
x_meteor = random.randrange(WIDTH/2 + 75, WIDTH - 75)
y_meteor = random.randrange(HEIGHT, HEIGHT + 50)
x_alien_meteor = random.randrange(75, WIDTH/2 - 75)
y_alien_meteor = random.randrange(HEIGHT, HEIGHT + 50)
# append the x and y values to the appropriate list
meteor_x_positions.append(x_meteor)
meteor_y_positions.append(y_meteor)
alien_meteor_x_positions.append(x_alien_meteor)
alien_meteor_y_positions.append(y_alien_meteor)
for _ in range(draw_shooting_star_rate):
x_human_shooting_star = random.randrange(WIDTH/2 + 75, WIDTH - 75)
y_human_shooting_star = random.randrange(HEIGHT, HEIGHT + 50)
x_alien_shooting_star = random.randrange(75, WIDTH/2 - 75)
y_alien_shooting_star = random.randrange(HEIGHT, HEIGHT + 50)
# append the x and y values to the appropriate list
human_x_positions_shooting_star.append(x_human_shooting_star)
human_y_positions_shooting_star.append(y_human_shooting_star)
alien_x_positions_shooting_star.append(x_alien_shooting_star)
alien_y_positions_shooting_star.append(y_alien_shooting_star)
spaceship_human_x = 750
spaceship_human_y = 100
spaceship_alien_x = 250
spaceship_alien_y = 100
alien_width = 60
alien_height = 74
human_width = 60
human_height = 80
meteor_height = 60
meteor_width = 60
alien_meteor_width = 60
alien_meteor_height = 60
spaceship_width = 130
spaceship_height = 50
alien_spaceship_width = 130
alien_spaceship_height = 50
human_shooting_star_width = 210
human_shooting_star_height = 156
alien_shooting_star_width = 210
alien_shooting_star_height = 156
x_human_laser = 0
y_human_laser = 0
x_alien_laser = 0
y_alien_laser = 0
up_pressed_human = False
left_pressed_human = False
right_pressed_human = False
fire_laser_human = False
up_pressed_alien = False
left_pressed_alien = False
right_pressed_alien = False
fire_laser_alien = False
run_game = False
main_screen_alien_x = 10
main_screen_alien_y = 10
main_screen_human_x = 10
main_screen_human_y = 740
main_screen_meteor1_x = 0
main_screen_meteor2_x = 1000
main_screen_meteor1_degree = 0
main_screen_meteor2_degree = 0
alien_points = 0
human_points = 0
human_meteor_hit_counter = 0
alien_meteor_hit_counter = 0
counter = 0
start_time = 0
def update(delta_time):
global elapsed_time, draw_enemy_rate, draw_meteor_rate, game_speed, counter, start_time
counter += delta_time
if time == True:
elapsed_time += delta_time
elapsed_time = round(elapsed_time, 2)
for index in range(len(human_y_positions)):
human_y_positions[index] -= game_speed
if human_y_positions[index] < 0:
human_y_positions[index] = random.randrange(HEIGHT, HEIGHT + 50)
human_x_positions[index] = random.randrange(WIDTH/2 + 75, WIDTH - 75)
for index in range(len(alien_y_positions)):
alien_y_positions[index] -= game_speed
if alien_y_positions[index] < 0:
alien_y_positions[index] = random.randrange(HEIGHT, HEIGHT + 50)
alien_x_positions[index] = random.randrange(75, WIDTH/2 - 75)
for index in range(len(meteor_y_positions)):
meteor_y_positions[index] -= game_speed
if meteor_y_positions[index] < 0:
meteor_y_positions[index] = random.randrange(HEIGHT, HEIGHT + 50)
meteor_x_positions[index] = random.randrange(WIDTH/2 + 75, WIDTH - 75)
for index in range(len(alien_meteor_y_positions)):
alien_meteor_y_positions[index] -= game_speed
if alien_meteor_y_positions[index] < 0:
alien_meteor_y_positions[index] = random.randrange(HEIGHT, HEIGHT + 50)
alien_meteor_x_positions[index] = random.randrange(75, WIDTH/2 - 75)
if elapsed_time > 60.00:
for index in range(len(human_y_positions_shooting_star)):
human_y_positions_shooting_star[index] -= game_speed
if human_y_positions_shooting_star[index] < 0:
if start_time == 0:
start_time = counter
elif counter - start_time > 10:
start_time = 0
human_y_positions_shooting_star[index] = random.randrange(HEIGHT, HEIGHT + 50)
human_x_positions_shooting_star[index] = random.randrange(WIDTH/2 + 75, WIDTH - 75)
for index in range(len(alien_y_positions_shooting_star)):
alien_y_positions_shooting_star[index] -= game_speed
if alien_y_positions_shooting_star[index] < 0:
if start_time == 0:
start_time = counter
elif counter - start_time > 10:
start_time = 0
alien_y_positions_shooting_star[index] = random.randrange(HEIGHT, HEIGHT + 50)
alien_x_positions_shooting_star[index] = random.randrange(75, WIDTH/2 - 75)
if elapsed_time == 20.00 or elapsed_time == 40.00:
game_speed += 0.8
elif elapsed_time > 60:
game_speed = 4.9
global human_hit, alien_hit
removed_human_lasers = 0
for index in range(len(human_y_positions_laser)):
if human_y_positions_laser[index - removed_human_lasers] < 765:
human_y_positions_laser[index - removed_human_lasers] += 30
else:
del human_x_positions_laser[index - removed_human_lasers]
del human_y_positions_laser[index - removed_human_lasers]
removed_human_lasers += 1
removed_alien_lasers = 0
for index in range(len(alien_y_positions_laser)):
if alien_y_positions_laser[index - removed_alien_lasers] < 765:
alien_y_positions_laser[index - removed_alien_lasers] += 30
else:
del alien_x_positions_laser[index - removed_alien_lasers]
del alien_y_positions_laser[index - removed_alien_lasers]
removed_alien_lasers += 1
global left_pressed_human, left_pressed_alien, right_pressed_human, right_pressed_alien, spaceship_human_x, spaceship_alien_x
if left_pressed_human:
spaceship_human_x -= 5
if spaceship_human_x < 570:
spaceship_human_x = 570
if left_pressed_alien:
spaceship_alien_x -= 5
if spaceship_alien_x < 60:
spaceship_alien_x = 60
if right_pressed_human:
spaceship_human_x += 5
if spaceship_human_x > 940:
spaceship_human_x = 940
if right_pressed_alien:
spaceship_alien_x += 5
if spaceship_alien_x > 430:
spaceship_alien_x = 430
def draw_main_screen(x, y):
global main_screen_alien_x, main_screen_alien_y, main_screen_human_x, main_screen_human_y, main_screen_meteor1_x, main_screen_meteor1_y, main_screen_meteor2_x, main_screen_meteor2_y, main_screen_meteor1_degree, main_screen_meteor2_degree
scale = 0.3
texture = arcade.load_texture("space.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
arcade.draw_text("Welcome to...", 385, 600, arcade.color.BLACK, 25)
arcade.draw_text("ASTRONAUTS VS ALIENS!", 30, 375, arcade.color.BLACK, 65)
arcade.draw_text("press space to start", 350, 130, arcade.color.BLACK, 25)
if main_screen_alien_x < 500:
main_screen_alien_x += 3
main_screen_alien_y += 4
elif main_screen_alien_x >= 500:
main_screen_alien_x += 3
main_screen_alien_y -= 4
scale = 0.08
texture = arcade.load_texture("alien.png")
arcade.draw_texture_rectangle(main_screen_alien_x, main_screen_alien_y, scale * texture.width,
scale * texture.height, texture, 0)
if main_screen_human_x < 500:
main_screen_human_x += 3
main_screen_human_y -= 4
elif main_screen_human_x >= 500:
main_screen_human_x += 3
main_screen_human_y += 4
scale = 0.08
texture = arcade.load_texture("astronaut.png")
arcade.draw_texture_rectangle(main_screen_human_x, main_screen_human_y, scale * texture.width,
scale * texture.height, texture, 0)
if main_screen_alien_x > 1000:
main_screen_meteor1_x += 5
main_screen_meteor2_x -= 5
main_screen_meteor1_degree += 5
main_screen_meteor2_degree -= 5
scale = 0.08
texture = arcade.load_texture("meteor.png")
arcade.draw_texture_rectangle(main_screen_meteor1_x, 250, scale * texture.width,
scale * texture.height, texture, main_screen_meteor1_degree)
scale = 0.08
texture = arcade.load_texture("meteor.png")
arcade.draw_texture_rectangle(main_screen_meteor2_x, 525, scale * texture.width,
scale * texture.height, texture, main_screen_meteor2_degree)
def draw_end_screen(x, y):
global alien_points, human_points, elapsed_time
scale = 1.67
texture = arcade.load_texture("space2.jpg")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
arcade.draw_text("GAME OVER!", 270, 500,
arcade.color.BLACK, 65, font_name='GARA')
arcade.draw_text("press space to restart", 350, 75, arcade.color.BLACK, 25)
if alien_points > human_points or alien_times_hit == 3:
arcade.draw_text("The Humans Have Won Control!", 175, 400, arcade.color.BLACK, 40)
elif human_points > alien_points or human_times_hit == 3:
arcade.draw_text("The Aliens Have Won Control!", 200, 400, arcade.color.BLACK, 40)
else:
arcade.draw_text("It's a tie! Peace has been achieved.", 150, 400, arcade.color.BLACK, 40)
arcade.draw_text("For now...", 800, 350, arcade.color.BLACK, 25)
def draw_background(x, y):
scale = 1
texture = arcade.load_texture("night_sky.jpg")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
def alien_points_counter():
arcade.draw_text("Points: " + str(alien_points),
50, 600, arcade.color.WHITE, 15)
def human_points_counter():
arcade.draw_text("Points: " + str(human_points),
880, 600, arcade.color.WHITE, 15)
def alien_lives(x, y):
scale = 0.06
texture = arcade.load_texture("heart.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
def human_lives(x, y):
scale = 0.06
texture = arcade.load_texture("heart.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
def draw_human(x, y):
scale = 0.05
texture = arcade.load_texture("astronaut.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
def draw_alien(x, y):
scale = 0.05
texture = arcade.load_texture("alien.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
def draw_human_laser(x, y):
scale = 0.1
texture = arcade.load_texture("laser.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
def draw_alien_laser(x, y):
scale = 0.1
texture = arcade.load_texture("laser.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
def draw_human_meteor(x, y):
scale = 0.05
texture = arcade.load_texture("meteor.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
def draw_alien_meteor(x, y):
scale = 0.05
texture = arcade.load_texture("meteor.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
def draw_human_shooting_star(x, y):
scale = 0.1
texture = arcade.load_texture("shooting star.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, - 20)
def draw_alien_shooting_star(x, y):
scale = 0.1
texture = arcade.load_texture("shooting star.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, - 20)
def draw_spaceship_human(x, y):
scale = 0.4
texture = arcade.load_texture("spaceship.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
def draw_spaceship_alien(x, y):
scale = 0.4
texture = arcade.load_texture("spaceship.png")
arcade.draw_texture_rectangle(x, y, scale * texture.width,
scale * texture.height, texture, 0)
def add_more_humans():
global human_x_positions, human_y_positions
# generate random x and y values
x_human = random.randrange(WIDTH/2 + 75, WIDTH - 75)
y_human = random.randrange(HEIGHT, HEIGHT + 50)
# append the x and y values to the appropriate list
human_x_positions.append(x_human)
human_y_positions.append(y_human)
def add_more_aliens():
global alien_x_positions, alien_y_positions
# generate random x and y values
x_alien = random.randrange(75, WIDTH/2 - 75)
y_alien = random.randrange(HEIGHT, HEIGHT + 50)
# append the x and y values to the appropriate list
alien_x_positions.append(x_alien)
alien_y_positions.append(y_alien)
def add_more_meteors():
global meteor_x_positions, meteor_y_positions
x_meteor = random.randrange(WIDTH/2 + 75, WIDTH - 75)
y_meteor = random.randrange(HEIGHT, HEIGHT + 50)
meteor_x_positions.append(x_meteor)
meteor_y_positions.append(y_meteor)
def add_more_alien_meteors():
global alien_meteor_x_positions, alien_meteor_y_positions
x_alien_meteor = random.randrange(75, WIDTH/2 - 75)
y_alien_meteor = random.randrange(HEIGHT, HEIGHT + 50)
alien_meteor_x_positions.append(x_alien_meteor)
alien_meteor_y_positions.append(y_alien_meteor)
def add_more_human_shooting_stars():
x_human_shooting_star = random.randrange(WIDTH/2 + 75, WIDTH - 75)
y_human_shooting_star = random.randrange(HEIGHT, HEIGHT + 50)
# append the x and y values to the appropriate list
human_x_positions_shooting_star.append(x_human_shooting_star)
human_y_positions_shooting_star.append(y_human_shooting_star)
def add_more_alien_shooting_stars():
x_alien_shooting_star = random.randrange(75, WIDTH/2 - 75)
y_alien_shooting_star = random.randrange(HEIGHT, HEIGHT + 50)
# append the x and y values to the appropriate list
alien_x_positions_shooting_star.append(x_alien_shooting_star)
alien_y_positions_shooting_star.append(y_alien_shooting_star)
def laser_human_collision():
global human_x_positions_laser, human_y_positions_laser
global x_human_laser, y_human_laser
global human_width, human_height, human_points
hit_sound = arcade.load_sound("hit.wav")
human_index = 0
for x_human, y_human in zip(human_x_positions, human_y_positions):
human_laser_index = 0
for x_human_laser, y_human_laser in zip(human_x_positions_laser, human_y_positions_laser):
if (x_human - human_width/2 <= x_human_laser <= x_human + human_width/2) and (y_human - human_height/2 <= y_human_laser <= y_human + human_height/2):
del human_x_positions[human_index]
del human_y_positions[human_index]
del human_x_positions_laser[human_laser_index]
del human_y_positions_laser[human_laser_index]
add_more_humans()
arcade.sound.play_sound(hit_sound)
human_points += 10
continue
human_index += 1
def laser_alien_collision():
global alien_x_positions_laser, alien_y_positions_laser
global x_alien_laser, y_alien_laser
global alien_width, alien_height, alien_points
hit_sound = arcade.load_sound("hit.wav")
alien_index = 0
for x_alien, y_alien in zip(alien_x_positions, alien_y_positions):
alien_laser_index = 0
for x_alien_laser, y_alien_laser in zip(alien_x_positions_laser, alien_y_positions_laser):
if (x_alien - alien_width/2 <= x_alien_laser <= x_alien + alien_width/2) and (y_alien - alien_height/2 <= y_alien_laser <= y_alien + alien_height/2):
del alien_x_positions[alien_index]
del alien_y_positions[alien_index]
del alien_x_positions_laser[alien_laser_index]
del alien_y_positions_laser[alien_laser_index]
add_more_aliens()
arcade.sound.play_sound(hit_sound)
alien_points += 10
continue
alien_index += 1
def meteor_spaceship_collision():
global spaceship_human_x, spaceship_human_y
global meteor_x_positions, meteor_y_positions
global spaceship_width, spaceship_height
global human_times_hit
spaceship_hit = False
meteor_index = 0
for x_meteor, y_meteor in zip(meteor_x_positions, meteor_y_positions):
if (x_meteor - spaceship_width/2 <= spaceship_human_x <= x_meteor + spaceship_width/2) and (y_meteor - spaceship_height/2 <= spaceship_human_y <= y_meteor + spaceship_height/2):
del meteor_x_positions[meteor_index]
del meteor_y_positions[meteor_index]
spaceship_hit = True
human_times_hit += 1
add_more_meteors()
break
else:
meteor_index += 1
def alien_meteor_spaceship_collision():
global spaceship_alien_x, spaceship_alien_y
global alien_meteor_x_positions, alien_meteor_y_positions
global spaceship_width, spaceship_height
global alien_times_hit
alien_spaceship_hit = False
alien_meteor_index = 0
for x_alien_meteor, y_alien_meteor in zip(alien_meteor_x_positions, alien_meteor_y_positions):
if (x_alien_meteor - alien_spaceship_width/2 <= spaceship_alien_x <= x_alien_meteor + alien_spaceship_width/2 ) and (y_alien_meteor - alien_spaceship_height/2 <= spaceship_alien_y <= y_alien_meteor + alien_spaceship_height/2 ):
del alien_meteor_x_positions[alien_meteor_index]
del alien_meteor_y_positions[alien_meteor_index]
alien_spaceship_hit = True
alien_times_hit += 1
add_more_alien_meteors()
break
else:
alien_meteor_index += 1
def laser_human_shooting_star_collision():
global human_x_positions_laser, human_y_positions_laser
global x_human_laser, y_human_laser
global human_shooting_star_width, human_shooting_star_height
human_shooting_star_index = 0
for x_human_shooting_star, y_human_shooting_star in zip(human_x_positions_shooting_star, human_y_positions_shooting_star):
human_laser_index = 0
for x_human_laser, y_human_laser in zip(human_x_positions_laser, human_y_positions_laser):
if (x_human_shooting_star - human_shooting_star_width/2 <= x_human_laser <= x_human_shooting_star + human_shooting_star_width/2) and (y_human_shooting_star - human_shooting_star_height/2 <= y_human_laser <= y_human_shooting_star + human_shooting_star_height/2):
del human_x_positions_shooting_star[human_shooting_star_index]
del human_y_positions_shooting_star[human_shooting_star_index]
del human_x_positions_laser[human_laser_index]
del human_y_positions_laser[human_laser_index]
add_more_human_shooting_stars()
break
else:
human_laser_index += 1
human_shooting_star_index += 1
def laser_alien_shooting_star_collision():
global alien_x_positions_laser, alien_y_positions_laser
global x_alien_laser, y_alien_laser
global alien_shooting_star_width, alien_shooting_star_height
alien_shooting_star_index = 0
for x_alien_shooting_star, y_alien_shooting_star in zip(alien_x_positions_shooting_star, alien_y_positions_shooting_star):
alien_laser_index = 0
for x_alien_laser, y_alien_laser in zip(alien_x_positions_laser, alien_y_positions_laser):
if (x_alien_shooting_star - alien_shooting_star_width/2 <= x_alien_laser <= x_alien_shooting_star + alien_shooting_star_width/2) and (y_alien_shooting_star - alien_shooting_star_height/2 <= y_alien_laser <= y_alien_shooting_star + alien_shooting_star_height/2):
del alien_x_positions_shooting_star[alien_shooting_star_index]
del alien_y_positions_shooting_star[alien_shooting_star_index]
del alien_x_positions_laser[alien_laser_index]
del alien_y_positions_laser[alien_laser_index]
add_more_alien_shooting_stars()
break
else:
alien_laser_index += 1
alien_shooting_star_index += 1
def on_draw():
global spaceship_human_x, spaceship_human_y, spaceship_alien_x, spaceship_alien_y, run_game, time, elapsed_time, draw_enemy_rate, draw_meteor_rate
arcade.start_render()
draw_main_screen(500, 375)
if run_game == True:
draw_background(500, 375)
laser_human_collision()
laser_alien_collision()
meteor_spaceship_collision()
alien_meteor_spaceship_collision()
laser_human_shooting_star_collision()
laser_alien_shooting_star_collision()
time = True
for x_human, y_human in zip(human_x_positions, human_y_positions):
draw_human(x_human, y_human)
for x_alien, y_alien in zip(alien_x_positions, alien_y_positions):
draw_alien(x_alien, y_alien)
for x_meteor, y_meteor in zip(meteor_x_positions, meteor_y_positions):
draw_human_meteor(x_meteor, y_meteor)
for x_alien_meteor, y_alien_meteor in zip(alien_meteor_x_positions, alien_meteor_y_positions):
draw_alien_meteor(x_alien_meteor, y_alien_meteor)
draw_spaceship_human(spaceship_human_x, spaceship_human_y)
draw_spaceship_alien(spaceship_alien_x, spaceship_alien_y)
for x_human_laser, y_human_laser in zip(human_x_positions_laser, human_y_positions_laser):
draw_human_laser(x_human_laser, y_human_laser)
for x_alien_laser, y_alien_laser in zip(alien_x_positions_laser, alien_y_positions_laser):
draw_alien_laser(x_alien_laser, y_alien_laser)
arcade.draw_lrtb_rectangle_filled(
WIDTH/2 - 5, WIDTH/2 + 5, HEIGHT, 0, arcade.color.WHITE)
level_up_sound = arcade.load_sound("level_up.wav")
lost_life_sound = arcade.load_sound("lost_life.wav")
if elapsed_time > 60.00:
for x_human_shooting_star, y_human_shooting_star in zip(human_x_positions_shooting_star, human_y_positions_shooting_star):
draw_human_shooting_star(x_human_shooting_star, y_human_shooting_star)
for x_alien_shooting_star, y_alien_shooting_star in zip(alien_x_positions_shooting_star, alien_y_positions_shooting_star):
draw_alien_shooting_star(x_alien_shooting_star, y_alien_shooting_star)
elif 19 < elapsed_time < 21 or 39 < elapsed_time < 41 or 59 < elapsed_time < 61:
arcade.draw_rectangle_filled(500, 375, 370, 100, arcade.color.BLACK)
arcade.draw_text("LEVEL UP!", 320, 342, arcade.color.WHITE, 65, font_name=('calibri'))
if 18.95 < elapsed_time < 19 or 38.95 < elapsed_time < 39 or 58.95 < elapsed_time < 59:
arcade.sound.play_sound(level_up_sound)
if 116 <= elapsed_time <= 119:
arcade.draw_rectangle_filled(500, 375, 50, 100, arcade.color.BLACK)
arcade.draw_text(str(int(120 - elapsed_time)), 475, 342, arcade.color.WHITE, 65)
elif elapsed_time >= 120:
arcade.draw_rectangle_filled(500, 375, 390, 100, arcade.color.BLACK)
arcade.draw_text("TIME'S UP!", 320, 342, arcade.color.WHITE, 65)
alien_points_counter()
human_points_counter()
alien_points = 0
human_points = 0
if human_times_hit == 0:
alien_lives(890, 580)
alien_lives(915, 580)
alien_lives(940, 580)
elif human_times_hit == 1:
alien_lives(915, 580)
alien_lives(940, 580)
# arcade.sound.play_sound(lost_life_sound)
elif human_times_hit == 2:
alien_lives(940, 580)
# arcade.sound.play_sound(lost_life_sound)
if alien_times_hit == 0:
alien_lives(62, 580)
alien_lives(87, 580)
alien_lives(112, 580)
elif alien_times_hit == 1:
alien_lives(87, 580)
alien_lives(112, 580)
# arcade.sound.play_sound(lost_life_sound)
elif alien_times_hit == 2:
alien_lives(112, 580)
# arcade.sound.play_sound(lost_life_sound)
if human_times_hit >= 4:
run_game = False
draw_end_screen(500, 375)
if alien_times_hit >= 4:
run_game = False
draw_end_screen(500, 375)
elif elapsed_time > 121:
run_game = False
draw_end_screen(500, 375)
def on_key_press(key, modifiers):
global left_pressed_human, left_pressed_alien, right_pressed_human, right_pressed_alien, fire_laser_human, fire_laser_alien, spaceship_human_x, spaceship_human_y, spaceship_alien_x, spaceship_alien_y, run_game, time, delta_time
laser_sound = arcade.load_sound("laser.wav")
if key == arcade.key.LEFT:
left_pressed_human = True
if key == arcade.key.A:
left_pressed_alien = True
if key == arcade.key.RIGHT:
right_pressed_human = True
if key == arcade.key.D:
right_pressed_alien = True
if key == arcade.key.W:
fire_laser_alien = True
alien_x_positions_laser.append(spaceship_alien_x)
alien_y_positions_laser.append(spaceship_alien_y)
arcade.sound.play_sound(laser_sound)
if key == arcade.key.UP:
fire_laser_human = True
human_x_positions_laser.append(spaceship_human_x)
human_y_positions_laser.append(spaceship_human_y)
arcade.sound.play_sound(laser_sound)
if key == arcade.key.SPACE:
run_game = True
time = True
def on_key_release(key, modifiers):
global left_pressed_human, left_pressed_alien, right_pressed_human, right_pressed_alien, laser_fire_key
if key == arcade.key.LEFT:
left_pressed_human = False
if key == arcade.key.A:
left_pressed_alien = False
if key == arcade.key.RIGHT:
right_pressed_human = False
if key == arcade.key.D:
right_pressed_alien = False
if key == arcade.key.W:
laser_fire_key = False
if key == arcade.key.UP:
laser_fire_key = False
def setup():
arcade.open_window(1000, 750, "Astronauts VS Aliens!")
window = arcade.get_window()
window.on_draw = on_draw
window.on_key_press = on_key_press
window.on_key_release = on_key_release
arcade.schedule(update, 1/100)
arcade.run()
hello
# Call the main function to get the program started.
if __name__ == '__main__':
setup()