-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
1818 lines (1688 loc) · 71.7 KB
/
main.py
File metadata and controls
1818 lines (1688 loc) · 71.7 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
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 pygame, random, math, pickle
from time import sleep
import structures, entities, levels
#Copyright Orion Williams 2018
pygame.init()
pygame.font.init()
pygame.mixer.init()
window = pygame.display.set_mode([800, 600])
pygame.display.set_caption("Road Rage")
window.fill([88, 198, 73])
running = True
show_me = False
setHighscore = False
sfx = True
enteringName = False
score = ""
screen = "menu"
previous = "menu"
placeSet = None
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
bkg = pygame.image.load("./images/bkg.png")
arrow = pygame.image.load("./images/arrow.png")
night_ = pygame.surface.Surface([800, 600])
night_setting = [200, 166, 133, 100, 66, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 33, 66, 100, 133, 166, 200, 217]
accidentpos = [0, 0]
tutorialindex = 0
dotutorial = False
lightswitch = pygame.mixer.Sound("./sfx/light-switch.wav")
motorcycle = pygame.mixer.Sound("./sfx/Motorcycle.wav")
car = pygame.mixer.Sound("./sfx/Car.wav")
scoreFile = open("./data/scores.dat", "rb")
try:
highScores = pickle.load(scoreFile)
except:
highScores = [[0, "player"], [0, "player"], [0, "player"], [0, "player"], [0, "player"]]
scoreFile.close()
volume = 5
oldvolume = 5
level = 0
page = 1
stopped = False
cargroup = pygame.sprite.Group()
roadgroup = pygame.sprite.Group()
lightgroup = pygame.sprite.Group()
intersectiongroup = pygame.sprite.Group()
buttongroup = pygame.sprite.Group()
buildinggroup = pygame.sprite.Group()
pygame.time.set_timer(pygame.USEREVENT, 100) #Acceleration
pygame.time.set_timer(pygame.USEREVENT + 1, 2250) #Car Spawn
pygame.time.set_timer(pygame.USEREVENT + 2, 1000) #Countdown
pygame.time.set_timer(pygame.USEREVENT + 3, 60000) #Time of Day change
class slider(pygame.sprite.Sprite):
def __init__(self, pos, len, start):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.surface.Surface([10, 10])
self.image.fill([255, 255, 255])
self.rect = self.image.get_rect()
self.rect.left, self.rect.top = list(pos)
self.pos = list(pos)
self.length = len
self.clicked = False
self.boundaryrect = pygame.surface.Surface([self.length * 10, 15])
self.boundaryrect = self.boundaryrect.get_rect()
self.boundaryrect.left, self.boundaryrect.top = list(pos)
self.where = start
if start < len:
self.rect.left += start * 10
def draw(self):
global window
window.blit(self.image, [self.rect.left, self.rect.top + 3])
pygame.draw.rect(window, [255, 255, 255], [self.pos[0], self.pos[1], (self.length * 10) + 6, 15], 2)
def grab(self):
global mouse
if self.rect.collidepoint([mouse.rect.centerx, mouse.rect.centery]):
self.clicked = True
def drag(self):
global mouse
if self.clicked:
if mouse.rect.left < self.boundaryrect.right - 6 and self.rect.left < self.boundaryrect.left + 3:
self.rect.left = mouse.rect.centerx
elif mouse.rect.left > self.boundaryrect.right - 6:
self.rect.left = self.boundaryrect.right - 6
elif mouse.rect.left > self.pos[0] + 3:
self.rect.left = mouse.rect.centerx
self.where = int(self.rect.left - self.pos[0]) / 10
class textbox(pygame.sprite.Sprite):
def __init__(self, pos, text, len, max):
global font
pygame.sprite.Sprite.__init__(self)
self.text = str(text)
self.max = max
self.image = font.render(str(self.text), 1, [255, 255, 255])
self.underline = pygame.surface.Surface([len, 1])
self.underline.fill([255, 255, 255])
self.rect = self.image.get_rect()
self.rect.left, self.rect.top = list(pos)
def draw(self):
global window
window.blit(self.image, [self.rect.left, self.rect.top])
window.blit(self.underline, [self.rect.left, self.rect.top + 20])
def write(self, char):
allowed = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "[", "]", ";", "'", ",", ".", "/"]
if len(self.text) < self.max:
if str(char) in allowed:
self.text = self.text + str(char)
elif char == "space":
self.text = self.text + " "
elif char == "backspace":
self.text = self.text[0 : len(self.text) - 1]
self.image = font.render(str(self.text), 1, [255, 255, 255])
class trafficbutton(pygame.sprite.Sprite):
def __init__(self, pos, id):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.surface.Surface([20, 20])
self.image.fill([0, 0, 0])
self.image.set_alpha(200)
self.rect = self.image.get_rect()
self.rect.left, self.rect.top = list(pos)
self.clicked = False
def click(self):
global mouse, lightgroup
if self.rect.colliderect(mouse.rect):
self.clicked = True
mouse.id = self.id
update(lightgroup, "toggle-id")
class mouseclass(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.rect = pygame.surface.Surface([1, 1])
self.rect = self.rect.get_rect()
self.rect.centerx, self.rect.centery = 0, 0
self.objective = {}
self.accident = False
self.collidepoint = [0, 0]
self.collide = False
self.accidents = 0.0
self.score = 0
self.id = None
self.light = False
self.angry = pygame.sprite.Group()
def move(self, x, y):
self.rect.centerx, self.rect.centery = x, y
def reset_stats(self):
self.score = 0
self.angry = pygame.sprite.Group()
self.objective = {}
self.accident = False
self.collidepoint = [0, 0]
self.collide = False
self.accidents = 0.0
self.score = 0
self.id = None
class imagebutton(pygame.sprite.Sprite):
def __init__(self, image, pos, centered):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(str(image))
self.rect = self.image.get_rect()
if centered:
self.rect.left, self.rect.top = 400 - self.rect.width/2, pos[1]
else:
self.rect.left, self.rect.top = pos
self.clicked = False
def click(self):
global mouse
if self.rect.colliderect(mouse.rect):
self.clicked = True
def draw(self):
global window
window.blit(self.image, [self.rect.left, self.rect.top])
class button(pygame.sprite.Sprite):
def __init__(self, text, pos, centered):
global font
pygame.sprite.Sprite.__init__(self)
self.text = text
self.image = font.render(self.text, 1, [255, 255, 255])
self.rect = self.image.get_rect()
if centered:
self.rect.left, self.rect.top = 400 - self.rect.width/2, pos[1]
else:
self.rect.left, self.rect.top = pos
self.clicked = False
def click(self):
global mouse
if self.rect.colliderect(mouse.rect):
self.clicked = True
def draw(self):
global window
window.blit(self.image, [self.rect.left, self.rect.top])
class switch(pygame.sprite.Sprite):
def __init__(self, pos, toggle):
pygame.sprite.Sprite.__init__(self)
self.images = [pygame.image.load("./images/ui/switch/switch-on.png"), pygame.image.load("./images/ui/switch/switch-off.png")]
self.state = bool(toggle)
self.clicked = False
if self.state:
self.image = self.images[0]
else:
self.image = self.images[1]
self.rect = self.image.get_rect()
self.rect.left, self.rect.top = list(pos)
def toggle(self):
global mouse
if self.rect.colliderect(mouse.rect):
self.clicked = True
self.state = not self.state
if self.state:
self.image = self.images[0]
else:
self.image = self.images[1]
def draw(self):
global window
window.blit(self.image, [self.rect.left, self.rect.top])
mouse = mouseclass()
menuButton = button("[m] menu", [400, 280], True)
replayButton = button("[r] replay", [400, 300], True)
scoreButton = button("[v] view highscores", [400, 320], True)
enterButton = button("[e] enter name", [10, 290], False)
nextLevelButton = button("[n] next level", [400, 320], True)
closeButton = button("[c] close", [20, 45], False)
showButton = button("[s] show me", [180, 45], False)
playButton = button("[p] play game", [20, 70], False)
howButton = button("[h] how to play", [20, 100], False)
settingsButton = button("[s] settings", [20, 130], False)
quitButton = button("[q] quit game", [20, 160], False)
backButton = button("[b] back", [10, 10], False)
resumeButton = button("[r] resume game", [20, 70], False)
goalButton = button("[1] goal of the game", [10, 110], False)
exampleButton = button("[2] examples of level tasks", [10, 130], False)
controlButton = button("[3] controls", [10, 150], False)
mechanicsButton = button("[4] game mechanics", [10, 170], False)
carButton = button("[5] cars", [10, 190], False)
gamemodesButton = button("[6] gamemodes", [10, 210], False)
nextButton = button("[n] next", [20, 560], False)
skipButton = button("[x] skip tutorial", [140, 560], False)
name = textbox([10, 290], "player", 250, 20)
volumeSlider = slider([243, 188], 11, 5)
fullSwitch = switch([313, 98], False)
sfxSwitch = switch([313, 128], True)
keySwitch = switch([313, 158], True)
classic = imagebutton("./images/ui/buttons/classic.png", [80, 240], False)
survival = imagebutton("./images/ui/buttons/freeplay.png", [320, 240], False)
freeplay = imagebutton("./images/ui/buttons/freeplay.png", [560, 240], False)
level1 = imagebutton("./images/ui/buttons/level1.png", [32, 60], False)
level2 = imagebutton("./images/ui/buttons/level2.png", [224, 60], False)
level3 = imagebutton("./images/ui/buttons/level3.png", [416, 60], False)
level4 = imagebutton("./images/ui/buttons/level4.png", [608, 60], False)
level5 = imagebutton("./images/ui/buttons/level5.png", [32, 240], False)
level6 = imagebutton("./images/ui/buttons/level6.png", [224, 240], False)
level7 = imagebutton("./images/ui/buttons/level7.png", [416, 240], False)
level8 = imagebutton("./images/ui/buttons/level8.png", [608, 240], False)
level9 = imagebutton("./images/ui/buttons/level9.png", [32, 420], False)
level10 = imagebutton("./images/ui/buttons/level10.png", [224, 420], False)
level11 = imagebutton("./images/ui/buttons/level11.png", [416, 420], False)
level12 = imagebutton("./images/ui/buttons/level12.png", [608, 420], False)
def readableTime(time):
if len(str(int(math.floor(time % 60)))) == 1:
newtime = str(int(math.floor(time / 60))) + ":0" + str(int(math.floor(time % 60)))
else:
newtime = str(int(math.floor(time / 60))) + ":" + str(int(math.floor(time % 60)))
return newtime
def selectLevel():
global window
image = pygame.image.load("./images/ui/buttons/freeplay.png")
rect = pygame.surface.Surface([800, 600])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [0, 0])
backButton.draw()
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
text = font.render(
"level 1", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [112 - rect, 185])
text = font.render(
"level 2", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [304 - rect, 185])
text = font.render(
"level 3", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [496 - rect, 185])
text = font.render(
"level 4", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [688 - rect, 185])
text = font.render(
"level 5", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [112 - rect, 365])
text = font.render(
"level 6", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [304 - rect, 365])
text = font.render(
"level 7", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [496 - rect, 365])
text = font.render(
"level 8", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [688 - rect, 365])
text = font.render(
"level 9", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [112 - rect, 545])
text = font.render(
"level 10", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [304 - rect, 545])
text = font.render(
"level 11", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [496 - rect, 545])
text = font.render(
"level 12", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [688 - rect, 545])
level1.draw()
level2.draw()
level3.draw()
level4.draw()
level5.draw()
level6.draw()
level7.draw()
level8.draw()
level9.draw()
level10.draw()
level11.draw()
level12.draw()
def intro():
global mouse, level, sleep, volume
window.fill([0, 0, 0])
pygame.time.set_timer(pygame.USEREVENT + 1, 8000)
pygame.time.set_timer(pygame.USEREVENT + 2, 8000)
pygame.display.flip()
sleep(2)
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 32)
if mouse.objective["objective"] != "freeplay" and mouse.objective["objective"] != "survival":
text = font.render(
"level " + str(level), 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [400 - rect, 185])
elif mouse.objective["objective"] == "freeplay":
text = font.render(
"freeplay mode", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [400 - rect, 185])
elif mouse.objective["objective"] == "survival":
text = font.render(
"survival mode", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [400 - rect, 185])
pygame.display.flip()
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
sleep(2)
if mouse.objective["objective"] == "cars":
text = font.render(
"level objective: get " + str(mouse.objective["amount"]) + " cars through the level", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [400 - rect, 230])
elif mouse.objective["objective"] == "crashes":
text = font.render(
"level objective: avoid " + str(mouse.objective["amount"]) + " crashes until the time runs out", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [400 - rect, 230])
elif mouse.objective["objective"] == "anger":
text = font.render(
"level objective: have less than " + str(mouse.objective["amount"]) + " angry drivers", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [400 - rect, 230])
text = font.render(
"until the time runs out", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [400 - rect, 250])
elif mouse.objective["objective"] == "survival":
text = font.render(
"objective: survive for as long as you can without", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [400 - rect, 230])
text = font.render(
"any accidents", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [400 - rect, 250])
elif mouse.objective["objective"] == "freeplay":
text = font.render(
"objective: have fun! it's freeplay mode!", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [400 - rect, 230])
pygame.display.flip()
sleep(3)
for i in range(20):
background()
roadgroup.draw(window)
intersectiongroup.draw(window)
buildinggroup.draw(window)
update(cargroup, "traffic")
update(cargroup, "crash")
update(cargroup, "drive")
update(cargroup, "draw")
update(lightgroup, "draw")
night(night_setting[mouse.objective["tod"]])
rect = pygame.surface.Surface([800 - (40 * i), 600 - (30 * i)])
window.blit(rect, [0 + (i * 20), 0 + (i * 15)])
pygame.display.flip()
def selectScreen():
global window
rect = pygame.surface.Surface([800, 200])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [0, 200])
rect = pygame.surface.Surface([107, 27])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [5, 5])
backButton.draw()
classic.draw()
survival.draw()
freeplay.draw()
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
text = font.render(
"[c] classic", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [160 - rect, 210])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
text = font.render(
"[s] survival", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [400 - rect, 210])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
text = font.render(
"[f] freeplay", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [640 - rect, 210])
def pauseScreen():
global window
rect = pygame.surface.Surface([195, 180])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [10, 10])
resumeButton.draw()
howButton.draw()
settingsButton.draw()
quitButton.draw()
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 32)
text = font.render(
"paused", 1,
[255, 255, 255])
window.blit(text, [20, 22])
def howScreen():
global window
rect = pygame.surface.Surface([800, 600])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [0, 0])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 32)
text = font.render(
"how to play", 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 10])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
text = font.render(
"click on a topic below to read about it:", 1,
[255, 255, 255])
window.blit(text, [10, 70])
backButton.draw()
goalButton.draw()
exampleButton.draw()
mechanicsButton.draw()
controlButton.draw()
carButton.draw()
gamemodesButton.draw()
def howPageScreen(screen):
rect = pygame.surface.Surface([800, 600])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [0, 0])
backButton.draw()
fontbig = pygame.font.Font("./resources/Danger on the Motorway.otf", 32)
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
if screen == 1:
text = fontbig.render(
"goal of the game", 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 10])
text = font.render("the goal of the game is to clear all the levels by completing", 1, [255, 255, 255])
window.blit(text, [10, 70])
text = font.render("the different tasks defined for each level.", 1, [255, 255, 255])
window.blit(text, [10, 90])
text = font.render("all of these tasks will be mentioned in the next section.", 1, [255, 255, 255])
window.blit(text, [10, 130])
elif screen == 2:
text = fontbig.render(
"examples of level tasks", 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 10])
text = font.render("to complete each level, you have to complete a certain task.", 1, [255, 255, 255])
window.blit(text, [10, 70])
text = font.render("each task is defined below:", 1, [255, 255, 255])
window.blit(text, [10, 90])
text = font.render("1. Get a certain amount of cars to the exit before time runs out.", 1, [255, 255, 255])
window.blit(text, [10, 130])
text = font.render("2. survive a certain amount of accidents until the timer", 1, [255, 255, 255])
window.blit(text, [10, 170])
text = font.render("runs out.", 1, [255, 255, 255])
window.blit(text, [10, 190])
text = font.render("3. have less than a certain amount of angry drivers before the", 1, [255, 255, 255])
window.blit(text, [10, 230])
text = font.render("time runs out.", 1, [255, 255, 255])
window.blit(text, [10, 250])
elif screen == 3:
text = fontbig.render(
"controls", 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 10])
text = font.render("left click: toggle traffic lights [1]", 1, [255, 255, 255])
window.blit(text, [10, 70])
text = font.render("right click: clear crashed cars [2]", 1, [255, 255, 255])
window.blit(text, [10, 110])
text = font.render("escape key: pause game [3]", 1, [255, 255, 255])
window.blit(text, [10, 150])
image = pygame.image.load("./images/ui/how-to/controls.png")
window.blit(image, [500, 70])
elif screen == 4:
text = fontbig.render(
"game mechanics", 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 10])
text = font.render("traffic lights: they control the flow of traffic. toggle them", 1, [255, 255, 255])
window.blit(text, [10, 70])
text = font.render("from red to green to red and vice versa, by left clicking them.", 1, [255, 255, 255])
window.blit(text, [10, 90])
text = font.render("one important note, clicking the intersection will switch both", 1, [255, 255, 255])
window.blit(text, [10, 110])
text = font.render("lights at that intersection, while just clicking one light", 1, [255, 255, 255])
window.blit(text, [10, 130])
text = font.render("individually will switch just that light.", 1,
[255, 255, 255])
window.blit(text, [10, 150])
text = font.render("car accidents: car accidents happen when two cars collide,", 1, [255, 255, 255])
window.blit(text, [10, 190])
text = font.render("stopping all traffic behind them. cars that have been in", 1, [255, 255, 255])
window.blit(text, [10, 210])
text = font.render("accidents will be identified by a yellow warning sign above", 1, [255, 255, 255])
window.blit(text, [10, 230])
text = font.render("them. right click on those cars to clear an accident.", 1, [255, 255, 255])
window.blit(text, [10, 250])
text = font.render("angry drivers: angry drivers happen when a driver is stopped", 1, [255, 255, 255])
window.blit(text, [10, 290])
text = font.render("for too long. cars with angry drivers will be identified by", 1, [255, 255, 255])
window.blit(text, [10, 310])
text = font.render("a red, frowny face above them. angry drivers penalize how", 1, [255, 255, 255])
window.blit(text, [10, 330])
text = font.render('much time is left on a level, or even stop the timer completely.', 1, [255, 255, 255])
window.blit(text, [10, 350])
text = font.render('but, they can be "calmed down" by restoring the flow of traffic', 1, [255, 255, 255])
window.blit(text, [10, 370])
text = font.render('in front of them.', 1, [255, 255, 255])
window.blit(text, [10, 390])
image = pygame.image.load("./images/ui/how-to/traffic lights.png")
window.blit(image, [80, 430])
image = pygame.image.load("./images/ui/how-to/accident.png")
window.blit(image, [320, 430])
image = pygame.image.load("./images/ui/how-to/angry drivers.png")
window.blit(image, [540, 430])
elif screen == 5:
text = fontbig.render(
"cars", 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 10])
text = font.render("there are two main different types of cars in the game.", 1, [255, 255, 255])
window.blit(text, [10, 70])
text = font.render("normal cars: normal cars drive at average speeds and take", 1, [255, 255, 255])
window.blit(text, [10, 110])
text = font.render("up some space.", 1, [255, 255, 255])
window.blit(text, [10, 130])
image = pygame.image.load("./images/cars/red/car-right.png")
window.blit(image, [10, 150])
text = font.render("buses: buses drive at slow speeds and take up twice as much", 1, [255, 255, 255])
window.blit(text, [10, 190])
text = font.render("space as normal cars.", 1, [255, 255, 255])
window.blit(text, [10, 210])
image = pygame.image.load("./images/cars/transit/car-right.png")
window.blit(image, [10, 230])
elif screen == 6:
text = fontbig.render(
"gamemodes", 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 10])
text = font.render("there are three different playable gamemodes in the game.", 1, [255, 255, 255])
window.blit(text, [10, 70])
text = font.render("classic mode: classic mode is the original 12 game levels", 1, [255, 255, 255])
window.blit(text, [10, 110])
text = font.render("with different challenges.", 1, [255, 255, 255])
window.blit(text, [10, 130])
text = font.render("survival mode: survival mode is one level where players try", 1, [255, 255, 255])
window.blit(text, [10, 170])
text = font.render('to see how long they can "survive" before causing a', 1, [255, 255, 255])
window.blit(text, [10, 190])
text = font.render("car accident.", 1, [255, 255, 255])
window.blit(text, [10, 210])
text = font.render("freeplay mode: freeplay mode is a mode where you can practice", 1, [255, 255, 255])
window.blit(text, [10, 250])
text = font.render('playing the game or just mess around. you cannot lose in', 1, [255, 255, 255])
window.blit(text, [10, 270])
text = font.render("freeplay mode.", 1, [255, 255, 255])
window.blit(text, [10, 290])
def highScore():
global window
rect = pygame.surface.Surface([800, 600])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [0, 0])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 32)
text = font.render(
"high score", 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 10])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
text = font.render(
"1. " + readableTime(highScores[0][0]) + " set by " + highScores[0][1], 1,
[255, 255, 255])
window.blit(text, [10, 70])
text = font.render(
"2. " + readableTime(highScores[1][0]) + " set by " + highScores[1][1], 1,
[255, 255, 255])
window.blit(text, [10, 100])
text = font.render(
"3. " + readableTime(highScores[2][0]) + " set by " + highScores[2][1], 1,
[255, 255, 255])
window.blit(text, [10, 130])
text = font.render(
"4. " + readableTime(highScores[3][0]) + " set by " + highScores[3][1], 1,
[255, 255, 255])
window.blit(text, [10, 160])
text = font.render(
"5. " + readableTime(highScores[4][0]) + " set by " + highScores[4][1], 1,
[255, 255, 255])
window.blit(text, [10, 190])
backButton.draw()
placeFollower = [None, "st", "nd", "rd", "th", "th"]
if setHighscore and not enteringName:
text = font.render(
"congrats! you just set a new highscore for " + str(placeSet) + placeFollower[placeSet] + " place!", 1,
[255, 255, 255])
window.blit(text, [10, 230])
text = font.render(
"want to sign your name into the highscore board?", 1,
[255, 255, 255])
window.blit(text, [10, 250])
enterButton.draw()
if enteringName and setHighscore:
text = font.render(
"enter your name below, when you are finished press return.", 1,
[255, 255, 255])
window.blit(text, [10, 250])
name.draw()
def settingsScreen():
global window
rect = pygame.surface.Surface([800, 600])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [0, 0])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 32)
text = font.render(
"settings", 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 10])
backButton.draw()
pygame.draw.rect(window, [255, 255, 255], [33, 50, 333, 500], 2)
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
text = font.render(
"general", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [200 - rect, 60])
text = font.render(
"fullscreen", 1,
[255, 255, 255])
window.blit(text, [43, 100])
fullSwitch.draw()
text = font.render(
"sfx", 1,
[255, 255, 255])
window.blit(text, [43, 130])
sfxSwitch.draw()
text = font.render(
"keyboard shortcuts", 1,
[255, 255, 255])
window.blit(text, [43, 160])
keySwitch.draw()
text = font.render(
"volume: " + str(volume), 1,
[255, 255, 255])
window.blit(text, [43, 190])
volumeSlider.draw()
pygame.draw.rect(window, [255, 255, 255], [433, 50, 333, 500], 2)
text = font.render(
"about", 1,
[255, 255, 255])
rect = text.get_rect().width / 2
window.blit(text, [600 - rect, 60])
text = font.render(
"version 1.0, revised 10/27", 1,
[255, 255, 255])
window.blit(text, [443, 100])
text = font.render(
"copyright orion williams", 1,
[255, 255, 255])
window.blit(text, [443, 130])
text = font.render(
"created for pyweek 26", 1,
[255, 255, 255])
window.blit(text, [443, 160])
text = font.render(
"built in python and pygame", 1,
[255, 255, 255])
window.blit(text, [443, 220])
text = font.render(
"art made in photoshop", 1,
[255, 255, 255])
window.blit(text, [443, 250])
text = font.render(
"sound effects from:", 1,
[255, 255, 255])
window.blit(text, [443, 310])
text = font.render(
"- created in bfxr", 1,
[255, 255, 255])
window.blit(text, [443, 340])
text = font.render(
"- earthcam outside wrigley", 1,
[255, 255, 255])
window.blit(text, [443, 370])
text = font.render(
" field in chicago, il", 1,
[255, 255, 255])
window.blit(text, [443, 400])
text = font.render(
"http://pyweek.org/e/deep26", 1,
[255, 255, 255])
window.blit(text, [443, 490])
text = font.render(
"http://oriondark7.com/", 1,
[255, 255, 255])
window.blit(text, [443, 520])
def menuScreen():
global window
rect = pygame.surface.Surface([235, 180])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [10, 10])
playButton.draw()
howButton.draw()
settingsButton.draw()
quitButton.draw()
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 32)
text = font.render(
"road rage", 1,
[255, 255, 255])
window.blit(text, [20, 22])
def gameOverScreen():
global window
rect = pygame.surface.Surface([800, 600])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [0, 0])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 32)
text = font.render(
"game over!", 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 180])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
text = font.render(
"cars passed: " + str(mouse.score), 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 220])
if mouse.objective["objective"] == "survival":
if len(str(int(math.floor(mouse.objective["time"] % 60)))) == 1:
text = font.render("time survived: " + str(int(math.floor(mouse.objective["time"] / 60))) + ":0" + str(int(math.floor(
mouse.objective["time"] % 60))), 1, [255, 255, 255])
else:
text = font.render("time survived: " + str(int(math.floor(mouse.objective["time"] / 60))) + ":" + str(int(math.floor(mouse.objective["time"] % 60))), 1, [255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 240])
menuButton.draw()
replayButton.draw()
else:
text = font.render(
"accidents: " + str(int(math.floor(mouse.accidents))), 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 240])
menuButton.draw()
replayButton.draw()
if mouse.objective["objective"] == "survival":
scoreButton.draw()
def winScreen():
global window
rect = pygame.surface.Surface([800, 600])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [0, 0])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 32)
text = font.render(
"you win!", 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 180])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
text = font.render(
"cars passed: " + str(mouse.score), 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 220])
text = font.render(
"accidents: " + str(int(math.floor(mouse.accidents))), 1,
[255, 255, 255])
rect = 400 - text.get_rect().width / 2
window.blit(text, [rect, 240])
menuButton.draw()
replayButton.draw()
if level < 12:
nextLevelButton.draw()
def accidentNotification():
global mouse, window, show_me, arrow, accidentpos
rect = pygame.surface.Surface([320, 60])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [10, 10])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
text = font.render(
"there's been an accident!", 1,
[255, 255, 255])
window.blit(text, [20, 20])
closeButton.draw()
showButton.draw()
if show_me:
window.blit(pygame.transform.scale2x(arrow), [accidentpos[0], accidentpos[1]])
def timerStoppedNotification():
global mouse, window, show_me, arrow, accidentpos
rect = pygame.surface.Surface([340, 60])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [10, 10])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
text = font.render(
"the timer has been stopped!", 1,
[255, 255, 255])
window.blit(text, [20, 20])
closeButton.draw()
def displayinfo():
global mouse, window
rect = pygame.surface.Surface([350, 80])
rect.fill([0, 0, 0])
rect.set_alpha(200)
window.blit(rect, [10, 502])
font = pygame.font.Font("./resources/Danger on the Motorway.otf", 16)
if mouse.objective["objective"] != "freeplay" and mouse.objective["objective"] != "survival":
if len(str(int(math.floor(mouse.objective["time"] % 60)))) == 1:
text = font.render("time left: " + str(int(math.floor(mouse.objective["time"] / 60))) + ":0" + str(int(math.floor(
mouse.objective["time"] % 60))), 1, [255, 255, 255])
else:
text = font.render("time left: " + str(int(math.floor(mouse.objective["time"] / 60))) + ":" + str(int(math.floor(mouse.objective["time"] % 60))), 1, [255, 255, 255])