-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mission_Interstellar.py
2943 lines (2504 loc) · 103 KB
/
Mission_Interstellar.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
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import math
import os
import sys
import random
from os import listdir
from os.path import isfile, join
import pygame
from pygame.locals import *
# Basic Functions
def quit():
pygame.quit()
sys.exit()
def displaytext(
text,
fontsize,
x,
y,
color,
):
font = pygame.font.SysFont('sawasdee', fontsize, True)
text = font.render(text, 1, color)
textpos = text.get_rect(centerx=x, centery=y)
screen.blit(text, textpos)
return text
def displaymenutext(
text,
fontsize,
x,
y,
color,
):
menufont = pygame.font.Font("Sprites/ethnocentric.otf", fontsize)
text = menufont.render(text, 1, color)
textpos = text.get_rect(centerx=x, centery=y)
screen.blit(text, textpos)
return text
def displaycustomanimtext(string, tuple, font, size, color, bgcolor=None):
line_space = 16
x, y = tuple
y = y * line_space
char = ''
letter = 0
count = 0
for i in range(len(string)):
basicfont = pygame.font.Font(font, size)
pygame.event.clear()
pygame.time.wait(25)
char = char + string[letter]
text = basicfont.render(char, False, color,
bgcolor)
textrect = text.get_rect(
topleft=(x,
y))
screen.blit(text, textrect)
pygame.display.update(
textrect)
count += 1
letter += 1
def displayanimtext(string, tuple):
line_space = 16
x, y = tuple
y = y * line_space
char = ''
letter = 0
count = 0
for i in range(len(string)):
basicfont = pygame.font.Font("Sprites/s.ttf", 15)
pygame.event.clear()
pygame.time.wait(25)
char = char + string[letter]
text = basicfont.render(char, False, (2, 241,
16))
textrect = text.get_rect(
topleft=(x,
y))
screen.blit(text, textrect)
pygame.display.update(
textrect)
count += 1
letter += 1
def load_image(file, size_x=-1, size_y=-1, colorkey=None):
path = os.path.join('Sprites', file)
image = pygame.image.load(path)
image = image.convert()
if colorkey is not None:
if colorkey == -1:
colorkey = image.get_at((0, 0))
image.set_colorkey(colorkey, RLEACCEL)
if size_x != -1 or size_y != -1:
image = pygame.transform.scale(image, (size_x, size_y))
return image, image.get_rect()
def showfuelbar(player, pos):
unit = 900 / player.maxfuel
if player.fuel > 0:
fuelbar = pygame.Surface((player.fuel * unit, 10), pygame.SRCALPHA, 32)
fuelbar.convert_alpha()
barcolor = green
if player.fuel > player.maxfuel * 0.6:
barcolor = green
elif player.fuel > player.maxfuel * 0.3:
barcolor = yellow
elif player.fuel < player.maxfuel * 0.3 and player.fuel > 0:
warning("Low Fuel!!!")
barcolor = red
rect = pygame.draw.rect(screen, barcolor, pos)
displaymenutext('FUEL', 15, 60, height - 15, white)
def blackhole_collision(left, right):
if left != right:
return left.rect2.colliderect(right.rect)
else:
return False
def vicinity_collision(left, right):
if left != right:
return left.vicinity_rect.colliderect(right.rect)
else:
return False
def buttons_draw(buttons):
for b in buttons:
b.draw()
def game_over():
color1 = white
color2 = yellow
starfield1 = stars(1, (150, 150, 150), 75, 0.5)
starfield2 = stars(1, (75, 75, 75), 200, 1)
global mainmenu
global running
global speed_vec
global currentLvl
global gameovermenu
selected = 0
while gameovermenu:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
if setting_sound_effects:
menu_select.play()
selected -= 1
elif event.key == pygame.K_RIGHT:
if setting_sound_effects:
menu_select.play()
selected += 1
elif event.key == pygame.K_ESCAPE or event.key == pygame.K_BACKSPACE:
if setting_sound_effects:
menu_select.play()
mainmenu = True
gameovermenu = False
main_menu()
if event.key == pygame.K_RETURN:
if setting_sound_effects:
menu_select.play()
if selected == 0:
gameovermenu = False
running = True
# player.gameOver = False
play_lvl()
if selected == 1:
mainmenu = True
gameovermenu = False
main_menu()
screen.fill((0, 0, 0))
starfield1.drawstars()
starfield2.drawstars()
if selected > 1:
selected = 0
if selected < 0:
selected = 1
if (selected == 0):
color1 = white
color2 = yellow
elif (selected == 1):
color1 = yellow
color2 = white
displaymenutext('Game Over', 40, width / 2, 100, yellow)
displaymenutext('Play Again', 25, width / 3 - 20, height - 400, color1)
displaymenutext('Main Menu', 25, 2 * width / 3 + 20, height - 400,
color2)
displaytext('Mission Intersteller 1.0', 12, width - 80, height - 40,
white)
displaytext('Made by: Vatsal Patel', 12, width - 80, height - 20,
white)
speed_vec = vec(0, -1)
pygame.display.update()
clock.tick(60)
def lvl_finished():
color1 = white
color2 = yellow
starfield1 = stars(1, (150, 150, 150), 75, 0.5)
starfield2 = stars(1, (75, 75, 75), 200, 1)
global mainmenu
global running
global speed_vec
global currentLvl
global lvlfinishmenu
global gamefinishscreen
selected = 0
while lvlfinishmenu:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
if setting_sound_effects:
menu_select.play()
selected -= 1
elif event.key == pygame.K_RIGHT:
if setting_sound_effects:
menu_select.play()
selected += 1
elif event.key == pygame.K_ESCAPE or event.key == pygame.K_BACKSPACE:
if setting_sound_effects:
menu_select.play()
mainmenu = True
lvlfinishmenu = False
main_menu()
if event.key == pygame.K_RETURN:
if setting_sound_effects:
menu_select.play()
if selected == 0:
lvlfinishmenu = False
running = True
# player.gameOver = False
currentLvl += 1
play_lvl()
if selected == 1:
mainmenu = True
lvlfinishmenu = False
main_menu()
screen.fill((0, 0, 0))
starfield1.drawstars()
starfield2.drawstars()
if (currentLvl == 4):
lvlfinishmenu = False
gamefinishscreen = True
game_finished()
if selected > 1:
selected = 0
if selected < 0:
selected = 1
if (selected == 0):
color1 = white
color2 = yellow
elif (selected == 1):
color1 = yellow
color2 = white
displaymenutext('Level Complete', 40, width / 2, 100, yellow)
displaymenutext('Next Level', 25, width / 3 - 20, height - 400, color1)
displaymenutext('Main Menu', 25, 2 * width / 3 + 20, height - 400,
color2)
displaytext('Mission Intersteller 1.0', 12, width - 80, height - 40,
white)
displaytext('Made by: Vatsal Patel', 12, width - 80, height - 20,
white)
speed_vec = vec(0, -1)
pygame.display.update()
clock.tick(60)
def play_lvl():
global currentLvl
if currentLvl > 4:
currentLvl = 0
if currentLvl < 0:
currentLvl = 4
if currentLvl == 0:
level_1()
elif currentLvl == 1:
level_2()
elif currentLvl == 2:
level_3()
elif currentLvl == 3:
level_4()
elif currentLvl == 4:
level_5()
def warning(text):
displaymenutext(text, 35
, width / 2, height / 2, red)
def showMeteorWarning():
displaymenutext("Meteor Wave Arriving", 20, screen.get_rect().centerx, 75,
red)
def game_finished():
starfield1 = stars(1, (150, 150, 150), 75, 0.5)
starfield2 = stars(1, (75, 75, 75), 200, 1)
global mainmenu
global speed_vec
global gamefinishscreen
show_finish_desc = True
show_final_message = False
while gamefinishscreen:
for event in pygame.event.get():
if event.type == pygame.QUIT:
mainmenu = True
gamefinishscreen = False
main_menu()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE or event.key == pygame.K_BACKSPACE or event.key == pygame.K_RETURN:
if setting_sound_effects:
menu_select.play()
mainmenu = True
gamefinishscreen = False
main_menu()
screen.fill((0, 0, 0))
starfield1.drawstars()
starfield2.drawstars()
if show_finish_desc:
img, rect = load_image("planet_landed.jpg", screen.get_width(),
screen.get_height(), -1)
rect.center = screen.get_rect().center
rect.bottom = screen.get_rect().bottom
screen.blit(img, rect)
pygame.display.update()
if setting_sound_effects:
intro_printing.play(-1)
displaycustomanimtext("Congratulations", (width / 2 - 200, 5),
"Sprites/ethnocentric.otf", 30, yellow)
displaycustomanimtext(
"You have successfully completed this game and saved humanity by",
(100, 20), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext(
"rehabilitating humans on Proxima Centauri B. We will lead the ",
(130, 21.5), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext(
"mission to Pandora, Krypton, Cybertron and Solaris from the",
(130, 23), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext(
"Proxima Centauri base station. For now, rest as you have come",
(120, 24.5), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext("a long way.", (width / 2 - 50, 26),
"Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext("Press Enter", (width / 2 - 80, 33),
"Sprites/ethnocentric.otf", 20, white)
displaytext('Mission Intersteller 1.0', 12, width - 80,
height - 40,
white)
displaytext('Made by: Vatsal Patel', 12, width - 80, height - 30,
white)
pygame.display.update()
intro_printing.stop()
while show_finish_desc:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_RETURN:
if setting_sound_effects:
menu_select.play()
show_finish_desc = False
show_final_message = True
if show_final_message:
timercount = 0
screen.fill((0, 0, 0))
pygame.display.update()
img, rect = load_image("future.jpg", screen.get_width(),
screen.get_height(), -1)
rect.center = screen.get_rect().center
rect.bottom = screen.get_rect().bottom
print(screen.get_width())
print(screen.get_height())
screen.blit(img, rect)
pygame.display.update()
if setting_sound_effects:
intro_printing.play(-1)
displaycustomanimtext("Message from future gen", (200, 5),
"Sprites/ethnocentric.otf", 30, yellow)
displaycustomanimtext(
"This game is based on fiction and hoping that you enjoyed playing it.",
(100, 15), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext(
"But the reason for developing this game is to bring awareness to youth,",
(80, 16.5), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext(
"as youth is the future. This fiction is slowly turning into reality on",
(100, 18), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext(
"Earth. With every passing day, thousands of trees are being cut down,",
(90, 19.5), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext(
"numerous animal species are going extinct, water, land and air are",
(100, 21), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext(
"polluted, and there are numerous more human activities poisoning",
(100, 22.5), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext(
"the environment. Do you see your future as an intelligent civilized",
(100, 24), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext("interplanetary species on this path?",
(300, 25.5), "Sprites/ethnocentric.otf", 15,
white)
displaycustomanimtext(
"Definitely No. Please help restore Mother Nature, your own home. Your",
(100, 29), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext(
"small contribution can turn the fate of the whole planet collaboratively.",
(70, 30.5), "Sprites/ethnocentric.otf", 15, white)
displaycustomanimtext(
"Follow the Reduce, Reuse, Recycle and Restore principle",
(80, 35), "Sprites/ethnocentric.otf", 20, yellow)
displaytext('Mission Intersteller 1.0', 12, width - 80,
height - 40,
white)
displaytext('Made by: Vatsal Patel', 12, width - 80, height - 30,
white)
slide_time = pygame.time.get_ticks()
pygame.display.update()
intro_printing.stop()
while show_final_message:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_RETURN:
if setting_sound_effects:
menu_select.play()
show_final_message = False
mainmenu = True
gamefinishscreen = False
main_menu()
time_since_enter = pygame.time.get_ticks() - slide_time
if time_since_enter / 1000 > timercount:
timercount += 1
displaytext('Mission Intersteller 1.0', 12, width - 80,
height - 40,
white)
displaytext('Made by: Vatsal Patel', 12, width - 80, height - 20,
white)
pygame.display.update()
speed_vec = vec(0, -1)
pygame.display.update()
clock.tick(60)
def offset(offset, planetGroup, wormholeGroup, meteorGroup, blackholeGroup,
asteroidGroup, target_pt, shipGroup, player, withplayer=False):
for planet in planetGroup:
planet.pos.x -= offset
for wormhole in wormholeGroup:
wormhole.pos.x -= offset
for meteor in meteorGroup:
meteor.pos.x -= offset
for blackhole in blackholeGroup:
blackhole.pos.x -= offset
for asteroid in asteroidGroup:
asteroid.pos.x -= offset
for ship in shipGroup:
ship.pos.x -= offset
target_pt.pos.x -= offset
if withplayer:
player.position.x -= offset
player.rect.centerx -= offset
pygame.display.update()
def createmeteorWave(num, posx):
meteors = []
mtg = pygame.sprite.Group()
for i in range(num):
randx = random.randrange(posx - 300, posx + 200)
randy = random.randrange(0, 100) - 50
rand_rad = random.randrange(5, 30)
rand_speedx = random.randrange(10, 30) / 10
rand_speedy = random.randrange(10, 30) / 10
meteor = Meteor((randx, randy), rand_rad,
vec(rand_speedx, rand_speedy))
mtg.add(meteor)
meteors.append(meteor)
return meteors, mtg
# Menus
def level_menu():
color1 = white
color2 = yellow
color3 = yellow
color4 = yellow
color5 = yellow
starfield1 = stars(1, (150, 150, 150), 75, 0.5)
starfield2 = stars(1, (75, 75, 75), 200, 1)
global mainmenu
global submenu
global running
global speed_vec
global currentLvl
selected = 0
while submenu:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
if setting_sound_effects:
menu_select.play()
selected -= 1
elif event.key == pygame.K_DOWN:
if setting_sound_effects:
menu_select.play()
selected += 1
elif event.key == pygame.K_ESCAPE or event.key == pygame.K_BACKSPACE:
if setting_sound_effects:
menu_select.play()
mainmenu = True
submenu = False
main_menu()
if event.key == pygame.K_RETURN:
if setting_sound_effects:
menu_select.play()
submenu = False
running = True
currentLvl = selected
if selected == 0:
level_1()
if selected == 1:
level_2()
if selected == 2:
level_3()
if selected == 3:
level_4()
if selected == 4:
level_5()
screen.fill((0, 0, 0))
starfield1.drawstars()
starfield2.drawstars()
if selected > 4:
selected = 0
if selected < 0:
selected = 4
if (selected == 0):
color1 = white
color2 = yellow
color3 = yellow
color4 = yellow
color5 = yellow
elif (selected == 1):
color1 = yellow
color2 = white
color3 = yellow
color4 = yellow
color5 = yellow
elif (selected == 2):
color1 = yellow
color2 = yellow
color3 = white
color4 = yellow
color5 = yellow
elif (selected == 3):
color1 = yellow
color2 = yellow
color3 = yellow
color4 = white
color5 = yellow
elif (selected == 4):
color1 = yellow
color2 = yellow
color3 = yellow
color4 = yellow
color5 = white
main_img, main_rect = load_image("mission-interstellar.png", 800,
400, -1)
main_rect.center = (screen.get_width() / 2, 200)
screen.blit(main_img, main_rect)
displaymenutext('Level 1', 25, width / 2 - 20, height - 350, color1)
displaymenutext('Level 2', 25, width / 2 - 20, height - 275, color2)
displaymenutext('Level 3', 25, width / 2 - 20, height - 200, color3)
displaymenutext('Level 4', 25, width / 2 - 20, height - 125, color4)
displaymenutext('Level 5', 25, width / 2 - 20, height - 50, color5)
displaytext('Mission Intersteller 1.0', 18, width - 85, height - 30,
white)
displaytext('Made by: Vatsal Patel', 18, width - 85, height - 15,
white)
speed_vec = vec(0, -1)
pygame.display.update()
clock.tick(60)
def settings():
starfield1 = stars(1, (150, 150, 150), 75, 0.5)
starfield2 = stars(1, (75, 75, 75), 200, 1)
buttons = []
global mainmenu
global settingsmenu
global setting_music
global setting_sound_effects
global speed_vec
button1 = Button('On', 100, 40, (width / 2 + 50, height - 420), 5,
setting_music)
button2 = Button('On', 100, 40, (width / 2 + 50, height - 320), 5,
setting_sound_effects)
buttons.append(button1)
buttons.append(button2)
while settingsmenu:
for event in pygame.event.get():
if event.type == pygame.QUIT:
mainmenu = True
settingsmenu = False
main_menu()
if event.type == pygame.KEYDOWN:
if setting_sound_effects:
menu_select.play()
if event.key == pygame.K_ESCAPE or event.key == pygame.K_BACKSPACE:
mainmenu = True
settingsmenu = False
main_menu()
screen.fill((0, 0, 0))
starfield1.drawstars()
starfield2.drawstars()
displaymenutext('Music', 20, width / 2 - 90, height - 400, white)
displaymenutext('Sound Effects', 20, width / 2 - 90, height - 300,
white)
displaymenutext('Use Mouse for selection', 15, width / 2, height - 100,
white)
displaytext('Mission Intersteller 1.0', 18, width - 85, height - 30,
white)
displaytext('Made by: Vatsal Patel', 18, width - 85, height - 15,
white)
speed_vec = vec(0, -1)
setting_music = button1.check_click()
setting_sound_effects = button2.check_click()
buttons_draw(buttons)
pygame.display.update()
clock.tick(5)
def howtoplay():
starfield1 = stars(1, (150, 150, 150), 75, 0.5)
starfield2 = stars(1, (75, 75, 75), 200, 1)
global mainmenu
global howtoplaymenu
global speed_vec
speed_vec = vec(0, -1)
scroll_up = True
scroll_down = True
window_offset = 0
while howtoplaymenu:
for event in pygame.event.get():
if event.type == pygame.QUIT:
mainmenu = True
howtoplaymenu = False
main_menu()
keys = pygame.key.get_pressed()
if scroll_down:
if keys[K_UP]:
window_offset -= 10
speed_vec += vec(0, -0.04)
if scroll_up:
if keys[K_DOWN]:
window_offset += 10
speed_vec -= vec(0, -0.04)
if keys[K_ESCAPE] or keys[K_BACKSPACE]:
mainmenu = True
howtoplaymenu = False
main_menu()
screen.fill((0, 0, 0))
starfield1.drawstars()
starfield2.drawstars()
ship, ship_rect = load_image("ship.png", 100, 100, -1)
ship_rect.center = (100, 150)
ship_rect.centery += window_offset
screen.blit(ship, ship_rect)
planet, planet_rect = load_image("Planets/planet2.png", 100, 100, -1)
planet_rect.center = (100, 400)
planet_rect.centery += window_offset
screen.blit(planet, planet_rect)
asteroid, asteroid_rect = load_image("Asteroids/asteroid.png", 100,
100, -1)
asteroid_rect.center = (100, 650)
asteroid_rect.centery += window_offset
screen.blit(asteroid, asteroid_rect)
meteor, meteor_rect = load_image("Meteors/meteor.png", 50, 100, -1)
meteor_rect.center = (100, 900)
meteor_rect.centery += window_offset
screen.blit(meteor, meteor_rect)
blackhole, blackhole_rect = load_image("blackhole.png", 200,
(150 * 0.6), -1)
blackhole_rect.center = (100, 1150)
blackhole_rect.centery += window_offset
screen.blit(blackhole, blackhole_rect)
wormhole, wormhole_rect = load_image("wormhole.png", 150, (150 * 0.65),
-1)
wormhole_rect.center = (100, 1400)
wormhole_rect.centery += window_offset
screen.blit(wormhole, wormhole_rect)
displaymenutext('Player Spaceship', 25, screen.get_width() / 2,
ship_rect.top - 50, white)
displaytext(
'Use Arrows keys for the movement and SPACE key for the brakes',
24, screen.get_width() / 2,
ship_rect.top + 30, yellow)
displaytext(
'Turning requires minimum fuel while brakes require maximum fuel.',
24, screen.get_width() / 2,
ship_rect.top + 60, yellow)
displaytext('If the fuel of Spaceship gets empty, the player is out.', 24,
screen.get_width() / 2,
ship_rect.top + 90, yellow)
displaymenutext('Planets', 25, screen.get_width() / 2,
planet_rect.top - 50, white)
displaytext(
'Planets vary in different radius and surface types and all planets possess ',
24, screen.get_width() / 2,
planet_rect.top + 30, yellow)
displaytext(
'gravitational power that can pull and destroy the spaceship. But this gravity',
24, screen.get_width() / 2,
planet_rect.top + 60, yellow)
displaytext('can also be used to propel the spaceship.', 24,
screen.get_width() / 2,
planet_rect.top + 90, yellow)
displaymenutext('Asteroids', 25, screen.get_width() / 2,
asteroid_rect.top - 50, white)
displaytext(
'Asteroids revolve around planets and blackholes. Asteroids vary',
24, screen.get_width() / 2, asteroid_rect.top + 30, yellow)
displaytext(
'in different radius, surface types and speed of revolution but asteroids can',
24, screen.get_width() / 2, asteroid_rect.top + 60, yellow)
displaytext(
' destroy the spaceship on collision. So avoid going near them.',
24, screen.get_width() / 2, asteroid_rect.top + 90, yellow)
displaymenutext('Meteors', 25, screen.get_width() / 2,
meteor_rect.top - 50, white)
displaytext(
'Meteors travel in group in the space. Meteors vary in different shape, sizes,',
24, screen.get_width() / 2, meteor_rect.top + 30, yellow)
displaytext(
'speed and trails. An alert occurs 5 secs before the meteors shower. Meteors can',
24, screen.get_width() / 2, meteor_rect.top + 60, yellow)
displaytext(
'destroy the spaceship on collision. Asteroids can help against meteors.',
24, screen.get_width() / 2, meteor_rect.top + 90,
yellow)
displaymenutext('Black Hole', 25, screen.get_width() / 2,
blackhole_rect.top - 50, white)
displaytext(
'Black Hole is a region in the space with very strong gravity.',
24, screen.get_width() / 2, blackhole_rect.top + 20, yellow)
displaytext(
'Blackholes have big radius of gravity and can pull the spaceship ',
24, screen.get_width() / 2, blackhole_rect.top + 50, yellow)
displaytext(
'from large distance. Once pulled in, spaceship cannot',
24, screen.get_width() / 2, blackhole_rect.top + 80,
yellow)
displaytext(
'escape from blackhole.',
24, screen.get_width() / 2, blackhole_rect.top + 110,
yellow)
displaymenutext('Worm Hole', 25, screen.get_width() / 2,
wormhole_rect.top - 50, white)
displaytext(
'Worm hole resembles a tunnel between two points in space-time.',
24, screen.get_width() / 2, wormhole_rect.top + 30, yellow)
displaytext(
'It provides a shortcut by shorter path. It can be used to reach',
24, screen.get_width() / 2, wormhole_rect.top + 60, yellow)
displaytext(
'some other point in space without using fuel.',
24, screen.get_width() / 2, wormhole_rect.top + 90,
yellow)
displaytext('Mission Intersteller 1.0', 18, width - 85, height - 30,
white)
displaytext('Made by: Vatsal Patel', 18, width - 85, height - 15,
white)
if screen.get_height() - wormhole_rect.bottom > 50:
scroll_down = False
else:
scroll_down = True
if ship_rect.top > 100:
scroll_up = False
else:
scroll_up = True
pygame.display.update()
clock.tick(120)
def main_menu():
starfield1 = stars(1, (150, 150, 150), 75, 0.5)
starfield2 = stars(1, (75, 75, 75), 200, 1)
global gamefinishscreen
global mainmenu
global submenu
global settingsmenu
global howtoplaymenu
global running
global speed_vec
selected = 0
color1 = white
color2 = yellow
color3 = yellow
color4 = yellow
while mainmenu:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
if setting_sound_effects:
menu_select.play()
selected -= 1
elif event.key == pygame.K_DOWN:
if setting_sound_effects:
menu_select.play()
selected += 1
if event.key == pygame.K_RETURN:
if setting_sound_effects:
menu_select.play()
if selected == 0:
mainmenu = False
submenu = True
# gamefinishscreen = True
# game_finished()
level_menu()
if selected == 1:
mainmenu = False
settingsmenu = True
settings()
if selected == 2:
mainmenu = False
howtoplaymenu = True
howtoplay()
if selected == 3:
quit()
screen.fill((0, 0, 0))
starfield1.drawstars()
starfield2.drawstars()
if selected > 3:
selected = 0
if selected < 0:
selected = 3
if (selected == 0):
color1 = white
color2 = yellow
color3 = yellow
color4 = yellow
elif (selected == 1):
color1 = yellow
color2 = white
color3 = yellow
color4 = yellow
elif (selected == 2):
color1 = yellow
color2 = yellow
color3 = white
color4 = yellow
elif (selected == 3):
color1 = yellow
color2 = yellow
color3 = yellow
color4 = white
main_img, main_rect = load_image("mission-interstellar.png", 800,
400, -1)
main_rect.center = (screen.get_width() / 2, 200)
screen.blit(main_img, main_rect)
displaymenutext('Play', 25, width / 2 - 20, height - 300, color1)
displaymenutext('Options', 25, width / 2 - 20, height - 225, color2)
displaymenutext('How To Play', 25, width / 2 - 20, height - 150,
color3)
displaymenutext('Exit', 25, width / 2 - 20, height - 75, color4)
displaytext('Mission Intersteller 1.0', 18, width - 85, height - 30,
white)
displaytext('Made by: Vatsal Patel', 18, width - 85, height - 15,
white)
speed_vec = vec(0, -1)
pygame.display.update()
clock.tick(60)
# Classes
class Button:
def __init__(self, text, width, height, pos, elevation, pressed):
self.font = pygame.font.Font("Sprites/ethnocentric.otf", 20)
self.pressed = pressed
self.top_rect = pygame.Rect(pos, (width, height))