-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailgateGameAnimated.js
2278 lines (1833 loc) · 93.8 KB
/
tailgateGameAnimated.js
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
jsPsych.plugins['tailgate'] = (function(){
var plugin = {};
plugin.info = {
name: 'tailgate',
parameters: { //put variables in here that want to change like numberOfLanes, pattern, speed, numOfCops... BRAKEV and ACCELV
numberOfLanes: {
type: jsPsych.plugins.parameterType.INT,
default: 4,
description: "The number of lanes in the game -> can be 3, 4, or 5"
},
truckSequence1: {
type: jsPsych.plugins.parameterType.ARRAY,
default: null,
description: "An array of four different trucks"
},
truckSequence2: {
type: jsPsych.plugins.parameterType.ARRAY,
default: null,
description: "An array of four different trucks"
},
truckSequence3: {
type: jsPsych.plugins.parameterType.ARRAY,
default: null,
description: "An array of four different trucks"
},
truckSequence4: {
type: jsPsych.plugins.parameterType.ARRAY,
default: null,
description: "An array of four different trucks"
},
overallGameTime: {
type: jsPsych.plugins.parameterType.INT,
default: null,
description: "How long a trial is in milliseconds"
}
}
};
plugin.trial = function(display_element, trial) {
display_element.innerHTML = "<div id='frame'> <div id = 'container'> <img id = 'Fbox' class = 'laneBox' src = 'assets/F.svg' alt = 'F'> <img id = 'Gbox' class = 'laneBox' src = 'assets/G.svg' alt = 'G'> <img id = 'Hbox' class = 'laneBox' src = 'assets/H.svg' alt = 'H'> <img id = 'Jbox' class = 'laneBox' src = 'assets/J.svg' alt = 'J'> <img id = 'Kbox' class = 'laneBox' src = 'assets/K.svg' alt = 'K'> <img id = 'Lbox' class = 'laneBox' src = 'assets/L.svg' alt = 'L'> " +
"<img id = 'redSquare1' class = 'redSquare' src = 'assets/thin-blue-line-png-15.png' alt = 'Red Square 1'> <img id = 'redSquare2' class = 'redSquare' src = 'assets/thin-blue-line-png-15.png' alt = 'Red Square 2'> <img id = 'redSquare3' class = 'redSquare' src = 'assets/thin-blue-line-png-15.png' alt = 'Red Square 3'> <img id = 'redSquare4' class = 'redSquare' src = 'assets/thin-blue-line-png-15.png' alt = 'Red Square 4'> <img id = 'redSquare5' class = 'redSquare' src = 'assets/thin-blue-line-png-15.png' alt = 'Red Square 5'> <img id = 'redSquare6' class = 'redSquare' src = 'assets/thin-blue-line-png-15.png' alt = 'Red Square 6'> " +
"<img id = 'laneBound1' src = 'assets/yellowline.png' alt = 'Yellow Line'> <img id = 'laneBound2' src = 'assets/yellowline.png' alt = 'Yellow Line'> " +
"<div id = 'countdownFrame'> <img id = 'countDown1' src = 'assets/countdown-1.svg' alt = '1'> </div> <div id = 'countdownFrame2'> <img id = 'countDown2' src = 'assets/countdown-2.svg' alt = '2'> </div> <div id = 'countdownFrame3'> <img id = 'countDown3' src = 'assets/countdown-3.svg' alt = '3'> </div>" +
"<div id = 'tutorialSignFrame'> <img id = 'tutorialSign' src = 'assets/tutorialSign.svg' alt = 'Tutorial Sign'> " +
"<div id = 'tutorialText'> <p id = 'introText'></p> <div id = 'tutButton'> CONTINUE </div> </div> </div>" +
"<div id = 'tutorialSignFrame2'> <img id = 'tutorialSign2' src = 'assets/tutorialSignSide.svg' alt = 'Tutorial Sign Side'> " +
"<div id = 'tutorialText2'> <p id = 'introText2'></p></div></div>" +
"<img id = 'policeCar1' class = 'policeCar' src = 'assets/truck.svg' alt = 'Truck Lane 1'> <img id = 'policeCar2' class = 'policeCar' src = 'assets/truck.svg' alt = 'Truck Lane 2'> <img id = 'policeCar3' class = 'policeCar' src = 'assets/truck.svg' alt = 'Truck Lane 3'> <img id = 'policeCar4' class = 'policeCar' src = 'assets/truck.svg' alt = 'Truck Lane 4'> <img id = 'policeCar5' class = 'policeCar' src = 'assets/truck.svg' alt = 'Truck Lane 5'> <img id = 'policeCar6' class = 'policeCar' src = 'assets/truck.svg' alt = 'Truck Lane 6'> " +
"<img id = 'redPoliceCar1' class = 'policeCar' src = 'assets/truck2.svg' alt = 'Truck Lane 1'> <img id = 'redPoliceCar2' class = 'policeCar' src = 'assets/truck2.svg' alt = 'Truck Lane 2'> <img id = 'redPoliceCar3' class = 'policeCar' src = 'assets/truck2.svg' alt = 'Truck Lane 3'> <img id = 'redPoliceCar4' class = 'policeCar' src = 'assets/truck2.svg' alt = 'Truck Lane 4'> <img id = 'redPoliceCar5' class = 'policeCar' src = 'assets/truck2.svg' alt = 'Truck Lane 5'> <img id = 'redPoliceCar6' class = 'policeCar' src = 'assets/truck2.svg' alt = 'Truck Lane 6'> " +
"<img id = 'greenPoliceCar1' class = 'policeCar' src = 'assets/truck3.svg' alt = 'Truck Lane 1'> <img id = 'greenPoliceCar2' class = 'policeCar' src = 'assets/truck3.svg' alt = 'Truck Lane 2'> <img id = 'greenPoliceCar3' class = 'policeCar' src = 'assets/truck3.svg' alt = 'Truck Lane 3'> <img id = 'greenPoliceCar4' class = 'policeCar' src = 'assets/truck3.svg' alt = 'Truck Lane 4'> <img id = 'greenPoliceCar5' class = 'policeCar' src = 'assets/truck3.svg' alt = 'Truck Lane 5'> <img id = 'greenPoliceCar6' class = 'policeCar' src = 'assets/truck3.svg' alt = 'Truck Lane 6'> " +
"<img id = 'yellowPoliceCar1' class = 'policeCar' src = 'assets/truck4.svg' alt = 'Truck Lane 1'> <img id = 'yellowPoliceCar2' class = 'policeCar' src = 'assets/truck4.svg' alt = 'Truck Lane 2'> <img id = 'yellowPoliceCar3' class = 'policeCar' src = 'assets/truck4.svg' alt = 'Truck Lane 3'> <img id = 'yellowPoliceCar4' class = 'policeCar' src = 'assets/truck4.svg' alt = 'Truck Lane 4'> <img id = 'yellowPoliceCar5' class = 'policeCar' src = 'assets/truck4.svg' alt = 'Truck Lane 5'> <img id = 'yellowPoliceCar6' class = 'policeCar' src = 'assets/truck4.svg' alt = 'Truck Lane 6'> " +
"<img id = 'sportsCar' src = 'assets/car.svg' alt = 'Player'> " +
"<div id = 'roadLine1' class = 'roadLine'></div> <div id = 'roadLine2' class = 'roadLine'></div> <div id = 'roadLine3' class = 'roadLine'></div> <div id = 'roadLine4' class = 'roadLine'></div> <div id = 'roadLine5' class = 'roadLine'></div> </div> " +
"<div id = 'overlay'> <span id = 'timer-label'>RANK</span> <span id = 'Time'>1</span> <span id = 'lineSeparator'> </span> <span id = 'score-label'>SCORE</span> <span id = 'Trucks'>0</span> </div>"+
"<div id = 'trackOverlay'> <span id = 'player1-icon'></span> <span id = 'finishLine'></span> </div> </div> </div>";
const canvas = document.getElementById('container'); //div element
// const context = canvas.getContext('2d');
const laneBound1 = document.getElementById('laneBound1');
const laneBound2 = document.getElementById('laneBound2');
const policeCar1 = document.getElementById('policeCar1');
const policeCar2 = document.getElementById('policeCar2');
const policeCar3 = document.getElementById('policeCar3');
const policeCar4 = document.getElementById('policeCar4');
const policeCar5 = document.getElementById('policeCar5');
const policeCar6 = document.getElementById('policeCar6');
const redPoliceCar1 = document.getElementById('redPoliceCar1');
const redPoliceCar2 = document.getElementById('redPoliceCar2');
const redPoliceCar3 = document.getElementById('redPoliceCar3');
const redPoliceCar4 = document.getElementById('redPoliceCar4');
const redPoliceCar5 = document.getElementById('redPoliceCar5');
const redPoliceCar6 = document.getElementById('redPoliceCar6');
const greenPoliceCar1 = document.getElementById('greenPoliceCar1');
const greenPoliceCar2 = document.getElementById('greenPoliceCar2');
const greenPoliceCar3 = document.getElementById('greenPoliceCar3');
const greenPoliceCar4 = document.getElementById('greenPoliceCar4');
const greenPoliceCar5 = document.getElementById('greenPoliceCar5');
const greenPoliceCar6 = document.getElementById('greenPoliceCar6');
const yellowPoliceCar1 = document.getElementById('yellowPoliceCar1');
const yellowPoliceCar2 = document.getElementById('yellowPoliceCar2');
const yellowPoliceCar3 = document.getElementById('yellowPoliceCar3');
const yellowPoliceCar4 = document.getElementById('yellowPoliceCar4');
const yellowPoliceCar5 = document.getElementById('yellowPoliceCar5');
const yellowPoliceCar6 = document.getElementById('yellowPoliceCar6');
const Fbox = document.getElementById('Fbox');
const Gbox = document.getElementById('Gbox');
const Hbox = document.getElementById('Hbox');
const Jbox = document.getElementById('Jbox');
const Kbox = document.getElementById('Kbox');
const Lbox = document.getElementById('Lbox');
const redBox1 = document.getElementById('redSquare1');
const redBox2 = document.getElementById('redSquare2');
const redBox3 = document.getElementById('redSquare3');
const redBox4 = document.getElementById('redSquare4');
const redBox5 = document.getElementById('redSquare5');
const redBox6 = document.getElementById('redSquare6');
const fullScreenIcon = document.getElementById('fullscreenh');
const soundIcon = document.getElementById('sound');
const roadLine1 = document.getElementById('roadLine1');
const roadLine2 = document.getElementById('roadLine2');
const roadLine3 = document.getElementById('roadLine3');
const roadLine4 = document.getElementById('roadLine4');
const roadLine5 = document.getElementById('roadLine5');
const infoBarImageContainer = document.getElementById('overlay'); //holds the time and score
const trackBarImageContainer = document.getElementById('trackOverlay'); //holds the ranking display
const tutorialSign = document.getElementById('tutorialSign');
const introText = document.getElementById('introText');
const tutorialSign2 = document.getElementById('tutorialSign2');
const introText2 = document.getElementById('introText2');
const tutButton = document.getElementById('tutButton');
const countDown1 = document.getElementById('countDown1');
const countDown2 = document.getElementById('countDown2');
const countDown3 = document.getElementById('countDown3');
const tutorialText2 = document.getElementById('tutorialText2');
const timerLabel = document.getElementById('Time');
const sportsCar = document.getElementById('sportsCar');
var doubleError = false;
//--------Global Variables----------
//canvas.style.height = (window.innerHeight) + 'px';
var numberOfLanes = 4;
var laneOffset;
var truckOffset;
var firstLaneXPos;
var secondLaneXPos;
var thirdLaneXPos;
var fourthLaneXPos;
var fifthLaneXPos;
var sixthLaneXPos;
var currentPlayerXPos; //the x coord the player is currently at
//-------------------------------------------------
var height = canvas.clientHeight;
var width = canvas.clientWidth;
//if width is greater than height: landscape
//if height is greater than width: height
//if orientation is true, then it is landscape mode
//if orientation is false, then it is portrait mode
var orientation = findOrientation();
var carOffset = .225 * height; //22.5 percent of context height
//Sounds
var truckSound = new Audio('assets/ding.wav');
truckSound.volume = .2;
var crashSound = new Audio('assets/brakingCar.wav');
crashSound.volume = .5;
var backgroundSound = new Audio('assets/backgroundSound.wav');
backgroundSound.volume = .35;
backgroundSound.loop = true;
var continueSound = new Audio('assets/continueSound.wav');
continueSound.volume = .5;
var countdownSound = new Audio('assets/countdownSound.wav');
countdownSound.volume = .5;
var startGameSound = new Audio('assets/startGameSound.wav');
startGameSound.volume = .5;
var emptyLane = 1; //the correct lane user has to input, game starts with first lane empty
var currentLanePos = 3; //current lane the car player is at, game starts with car at lane 3
var copPattern = [emptyLane]; //the pattern of empty cop lanes
var iterator = 0;
var numCops = 12; //how many waves of cops will come
//variables for game timer
var time = 0;
var timerRunning = true; //when game starts, set to true
//const overallGameTime = 6000; //complete the game within this many milliseconds
//var remainingTime = overallGameTime - time;
//var tempTime = 1000;
var listOfDataPoints = []; //an array of datapoints
var dataPoint = []; //this array holds ms for input, which truckSequence, and which truck in truckSequence
//variables for cop timing animation
var inputTime = []; //array for holding all the times it took for a user to input an answer
var truckYPos = 5; //y coordinate of where the cop cars are aligned 5% of the height of canvas
var startTime = 0;
var endTime = 0;
/*if(orientation === false){ //portrait mode
truckYPos = 8;
}*/
var initialtruckYPos = truckYPos; //is not changed
//if user is allowed to hit enter to start game
var startGameBool = true;
//when the game accepts user input, set to true
var acceptUserInput = false;
//when the user gives correct answer, set to true
var correctInputGiven = false;
//when the user gives incorrect answer, set to true
var wrongInputGiven = false;
//carV - truckV is the speed the trucks are moving
//truckV stays at 1 percent movement
//carV is changed throughout animation to simulate braking
var carV = 1; // 1 percent
var truckV = 1; // 1 percent
var maxCarV = 2.25;
var incrementSpeed = 10;
var changeValCounter = 0;
var newPos;
//animation variables
var right = false;
var left = false;
var startTruckAnimation = false;
var startNewWave = false;
var redrawTrucks = false;
var continueDrawingTrucks = false;
//handles different truck accelerations
var inertia = false;
var initialCarYPos;
var animationState = '';
var portraitOffset = 0;
//braking
var brakeV = .025; //.012
var accelV = .015; //.008
var stopVal = 1.75;
//var carVtemp = carV;
var bool = false;
var tutorial = true;
var slide = 1;
var endSlide = false;
//---Endless Mode/ Truck Sequences---//
var truckSequence1 = [1,2,3,1];
var truckSequence2 = [2,1,4,2];
var truckSequence3 = [3,4,2,3];
var truckSequence4 = [4,1,3,4];
var truckSeqLength = 4;
var numOfTruckSeq = 4;
var prevTruckSeq = 0;
var currentTruckSequence = 1;
var lives = 1; //user starts out with five lives
var rank = 1;
var score = 0;
var mute = false;
var doubleClickChecker = false;
var countdownIsPlaying = false; //the 321 countdown is originally not playing
var lifeBoolean = false;
var currentY = 85; // initial position of the icon
//----------------------------------------
function findOrientation(){
if(width <= height){ //portrait mode
orientation = false;
}
else{ //height < width landscape mode
orientation = true;
}
}
//-------Set up initial assets------------
tutorialPrint();
function tutorialPrint(){
if(slide === 1){
introText.innerHTML = "Tailgate is a game that will test your reaction time.";
}
else if(slide === 2){
introText.innerHTML = "Press the letter of the empty lane on your keyboard or tap the lane if you are on a mobile device.";
}
else if(slide === 3){
tutorialText2.style.visibility = 'visible';
tutorialSign.style.visibility = 'hidden';
introText.style.visibility = 'hidden';
tutButton.style.visibility = 'hidden';
tutorialSign2.style.visibility = 'visible';
introText2.innerHTML = "Press the F key or tap the empty lane.";
introText2.style.visibility = 'visible';
}
else if(slide === 4){
introText2.innerHTML = "Now press the H key or tap the empty lane.";
}
else if(slide === 5){
tutorialText2.style.visibility = 'hidden';
tutorialSign.style.visibility = 'visible';
introText.style.visibility = 'visible';
tutButton.style.visibility = 'visible';
tutorialSign2.style.visibility = 'hidden';
introText2.style.visibility = 'hidden';
introText.innerHTML = "Try to score as many points before you crash 3 times!";
tutButton.innerHTML = "START GAME";
//add the 3 2 1 go animation
}
}
initializeGame();
function initializeGame() {
switch (numberOfLanes) {
case 3:
laneOffset = .1 * width; //6.5 percent of context width
truckOffset = .03 * width; //3 percent of context width
firstLaneXPos = laneOffset;
secondLaneXPos = (width / 3) + laneOffset; //width / 4 - 10
thirdLaneXPos = width - (width / 3) + laneOffset; // width / 4 - 20
currentPlayerXPos = thirdLaneXPos;
window.addEventListener('resize', resize3, {passive: true});
initAssetPos3();
break;
case 4:
laneOffset = .065 * width; //6.5 percent of context width
truckOffset = .03 * width; //3 percent of context width
firstLaneXPos = laneOffset;
secondLaneXPos = (width / 4) + laneOffset; //width / 4 - 10
thirdLaneXPos = (width / 2) + laneOffset; // width / 4 - 20
fourthLaneXPos = (width - (width / 4)) + laneOffset; //width / 4 - 30
currentPlayerXPos = thirdLaneXPos;
window.addEventListener('resize', resize4, {passive: true});
initAssetPos4();
break;
case 5:
laneOffset = .03 * width; //6.5 percent of context width
truckOffset = .03 * width; //3 percent of context width
firstLaneXPos = laneOffset;
secondLaneXPos = (width / 5) + laneOffset; //width / 4 - 10
thirdLaneXPos = 2 * (width / 5) + laneOffset; // width / 4 - 20
fourthLaneXPos = 3 * (width / 5) + laneOffset; //width / 4 - 30
fifthLaneXPos = 4 * (width / 5) + laneOffset;
currentPlayerXPos = thirdLaneXPos;
window.addEventListener('resize', resize5, {passive: true});
initAssetPos5();
break;
case 6:
laneOffset = .02 * width; //6.5 percent of context width
truckOffset = .02 * width; //3 percent of context width
firstLaneXPos = laneOffset;
secondLaneXPos = (width / 6) + laneOffset; //width / 4 - 10
thirdLaneXPos = 2 * (width / 6) + laneOffset; // width / 4 - 20
fourthLaneXPos = 3 * (width / 6) + laneOffset; //width / 4 - 30
fifthLaneXPos = 4 * (width / 6) + laneOffset;
sixthLaneXPos = 5 * (width / 6) + laneOffset;
currentPlayerXPos = thirdLaneXPos;
window.addEventListener('resize', resize6, {passive: true});
initAssetPos6();
break;
}
}
function initializeHelper() {
/*let secs = Math.floor(remainingTime / 100);
let hundredths = remainingTime % 100;
if (secs < 10) {
secs = "0" + secs.toString();
} else {
secs = secs.toString();
}
hundredths = hundredths.toString();
document.getElementById("Time").innerText = secs + "." + hundredths;*/
console.log("Element in question is " + document.getElementById("Time"));
document.getElementById("Time").innerText = rank + "";
findOrientation();
if(orientation === false){ //portrait mode
portraitOffset = .015;
truckYPos = 10;
initialtruckYPos = truckYPos;
}
else if(orientation === true){//landscape
portraitOffset = 0;
truckYPos = 5;
initialtruckYPos = truckYPos;
}
laneBound1.style.left = (.015 * width) + 'px';
laneBound1.style.top = 0 + 'px';//(-.25 * height) + 'px';
laneBound2.style.left = width - (.025 * width) + 'px';
laneBound2.style.top = 0 + 'px';
drawFBox();
drawGBox();
drawHBox();
drawRedBox1();
drawRedBox2();
drawRedBox3();
//Game starts with lane one empty
//so dont show Police car lane 1
policeCar1.style.left = firstLaneXPos + truckOffset + 'px';
policeCar1.style.top = truckYPos + '%';
policeCar1.style.visibility = 'hidden';
//Police car lane 2
policeCar2.style.left = secondLaneXPos + truckOffset + 'px';
policeCar2.style.top = truckYPos + '%';
//Police car lane 3
policeCar3.style.left = thirdLaneXPos + truckOffset + 'px';
policeCar3.style.top = truckYPos + '%';
redPoliceCar1.style.left = firstLaneXPos + truckOffset + 'px';
redPoliceCar1.style.top = truckYPos + '%';
redPoliceCar1.style.visibility = 'hidden';
redPoliceCar2.style.left = secondLaneXPos + truckOffset + 'px';
redPoliceCar2.style.top = truckYPos + '%';
redPoliceCar2.style.visibility = 'hidden';
redPoliceCar3.style.left = thirdLaneXPos + truckOffset + 'px';
redPoliceCar3.style.top = truckYPos + '%';
redPoliceCar3.style.visibility = 'hidden';
greenPoliceCar1.style.left = firstLaneXPos + truckOffset + 'px';
greenPoliceCar1.style.top = truckYPos + '%';
greenPoliceCar1.style.visibility = 'hidden';
greenPoliceCar2.style.left = secondLaneXPos + truckOffset + 'px';
greenPoliceCar2.style.top = truckYPos + '%';
greenPoliceCar2.style.visibility = 'hidden';
greenPoliceCar3.style.left = thirdLaneXPos + truckOffset + 'px';
greenPoliceCar3.style.top = truckYPos + '%';
greenPoliceCar3.style.visibility = 'hidden';
yellowPoliceCar1.style.left = firstLaneXPos + truckOffset + 'px';
yellowPoliceCar1.style.top = truckYPos + '%';
yellowPoliceCar1.style.visibility = 'hidden';
yellowPoliceCar2.style.left = secondLaneXPos + truckOffset + 'px';
yellowPoliceCar2.style.top = truckYPos + '%';
yellowPoliceCar2.style.visibility = 'hidden';
yellowPoliceCar3.style.left = thirdLaneXPos + truckOffset + 'px';
yellowPoliceCar3.style.top = truckYPos + '%';
yellowPoliceCar3.style.visibility = 'hidden';
redPoliceCar4.style.visibility = 'hidden';
redPoliceCar5.style.visibility = 'hidden';
redPoliceCar6.style.visibility = 'hidden';
greenPoliceCar4.style.visibility = 'hidden';
greenPoliceCar5.style.visibility = 'hidden';
greenPoliceCar6.style.visibility = 'hidden';
yellowPoliceCar4.style.visibility = 'hidden';
yellowPoliceCar5.style.visibility = 'hidden';
yellowPoliceCar6.style.visibility = 'hidden';
//Road Lane 1
roadLine1.style.left = secondLaneXPos - laneOffset + 'px';
roadLine1.style.top = -25 + '%';
//Road Lane 2
roadLine2.style.left = thirdLaneXPos - laneOffset + 'px';
roadLine2.style.top = -25 + '%';
//Player car starts at lane 3
sportsCar.style.left = currentPlayerXPos + (.04 * width) + 'px';
sportsCar.style.top = (height - carOffset) + 'px';
initialCarYPos = (height - carOffset);
}
function initAssetPos3() {
initializeHelper();
//print these elements off screen
//j k l box
Jbox.style.left = -150 + '%';
Kbox.style.left = -150 + '%';
Lbox.style.left = -150 + '%';
//redsquare 4 5 6
redBox4.style.left = -150 + '%';
redBox5.style.left = -150 + '%';
redBox6.style.left = -150 + '%';
policeCar4.style.left = 150 + '%';
policeCar4.style.top = -150 + '%';
policeCar5.style.left = 150 + '%';
policeCar5.style.top = -150 + '%';
policeCar6.style.left = 150 + '%';
policeCar6.style.top = -150 + '%';
//Road Lane 3
roadLine3.style.left = 150 + '%';
roadLine3.style.top = -150 + '%';
//Road Lane 4
roadLine4.style.left = 150 + '%';
roadLine4.style.top = -150 + '%';
//Road Lane 5
roadLine5.style.left = 150 + '%';
roadLine5.style.left = -150 + '%';
redPoliceCar4.style.left = 150 + '%';
redPoliceCar4.style.top = -150 + '%';
redPoliceCar5.style.left = 150 + '%';
redPoliceCar5.style.top = -150 + '%';
redPoliceCar6.style.left = 150 + '%';
redPoliceCar6.style.top = -150 + '%';
greenPoliceCar4.style.left = 150 + '%';
greenPoliceCar4.style.top = -150 + '%';
greenPoliceCar5.style.left = 150 + '%';
greenPoliceCar5.style.top = -150 + '%';
greenPoliceCar6.style.left = 150 + '%';
greenPoliceCar6.style.top = -150 + '%';
yellowPoliceCar4.style.left = 150 + '%';
yellowPoliceCar4.style.top = -150 + '%';
yellowPoliceCar5.style.left = 150 + '%';
yellowPoliceCar5.style.top = -150 + '%';
yellowPoliceCar6.style.left = 150 + '%';
yellowPoliceCar6.style.top = -150 + '%';
animate();
}
function initAssetPos4() {
initializeHelper();
drawJBox();
drawRedBox4();
//Police car lane 4
policeCar4.style.left = fourthLaneXPos + truckOffset + 'px';
policeCar4.style.top = truckYPos + '%';
redPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
redPoliceCar4.style.top = truckYPos + '%';
greenPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
greenPoliceCar4.style.top = truckYPos + '%';
yellowPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
yellowPoliceCar4.style.top = truckYPos + '%';
//Road Lane 3
roadLine3.style.left = fourthLaneXPos - laneOffset + 'px';
roadLine3.style.top = -25 + '%';
//print these elements offscreen
//k l box
Kbox.style.left = -150 + '%';
Lbox.style.left = -150 + '%';
//redsquare 5 6
redBox5.style.left = -150 + '%';
redBox6.style.left = -150 + '%';
policeCar5.style.left = 150 + '%';
policeCar5.style.top = -150 + '%';
policeCar6.style.left = 150 + '%';
policeCar6.style.top = -150 + '%';
//Road Lane 4 5
roadLine4.style.left = 150 + '%';
roadLine4.style.top = -150 + '%';
roadLine5.style.left = 150 + '%';
roadLine5.style.top = -150 + '%';
redPoliceCar5.style.left = 150 + '%';
redPoliceCar5.style.top = -150 + '%';
redPoliceCar6.style.left = 150 + '%';
redPoliceCar6.style.top = -150 + '%';
greenPoliceCar5.style.left = 150 + '%';
greenPoliceCar5.style.top = -150 + '%';
greenPoliceCar6.style.left = 150 + '%';
greenPoliceCar6.style.top = -150 + '%';
yellowPoliceCar5.style.left = 150 + '%';
yellowPoliceCar5.style.top = -150 + '%';
yellowPoliceCar6.style.left = 150 + '%';
yellowPoliceCar6.style.top = -150 + '%';
animate();
}
function initAssetPos5() {
initializeHelper();
drawJBox();
drawKBox();
drawRedBox4();
drawRedBox5();
//Police car lane 4
policeCar4.style.left = fourthLaneXPos + truckOffset + 'px';
policeCar4.style.top = truckYPos + '%';
policeCar5.style.left = fifthLaneXPos + truckOffset + 'px';
policeCar5.style.top = truckYPos + '%';
redPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
redPoliceCar4.style.top = truckYPos + '%';
redPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
redPoliceCar5.style.top = truckYPos + '%';
greenPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
greenPoliceCar4.style.top = truckYPos + '%';
greenPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
greenPoliceCar5.style.top = truckYPos + '%';
yellowPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
yellowPoliceCar4.style.top = truckYPos + '%';
yellowPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
yellowPoliceCar5.style.top = truckYPos + '%';
//Road Lane 3
roadLine3.style.left = fourthLaneXPos - laneOffset + 'px';
roadLine3.style.top = -25 + '%';
//Road Lane 4
roadLine4.style.left = fifthLaneXPos - laneOffset + 'px';
roadLine4.style.top = -25 + '%';
//draw off screen
Lbox.style.left = -150 + '%';
policeCar6.style.left = 150 + '%';
policeCar6.style.top = -150 + '%';
redBox6.style.left = -150 + '%';
roadLine5.style.left = 150 + '%';
roadLine5.style.top = -150 + '%';
redPoliceCar6.style.left = 150 + '%';
redPoliceCar6.style.top = -150 + '%';
greenPoliceCar6.style.left = 150 + '%';
greenPoliceCar6.style.top = -150 + '%';
yellowPoliceCar6.style.left = 150 + '%';
yellowPoliceCar6.style.top = -150 + '%';
animate();
}
function initAssetPos6() {
initializeHelper();
drawJBox();
drawKBox();
drawLBox();
drawRedBox4();
drawRedBox5();
drawRedBox6();
//Police car lane 4
policeCar4.style.left = fourthLaneXPos + truckOffset + 'px';
policeCar4.style.top = truckYPos + '%';
policeCar5.style.left = fifthLaneXPos + truckOffset + 'px';
policeCar5.style.top = truckYPos + '%';
policeCar6.style.left = sixthLaneXPos + truckOffset + 'px';
policeCar6.style.top = truckYPos + '%';
redPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
redPoliceCar4.style.top = truckYPos + '%';
redPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
redPoliceCar5.style.top = truckYPos + '%';
redPoliceCar6.style.left = sixthLaneXPos + truckOffset + 'px';
redPoliceCar6.style.top = truckYPos + '%';
greenPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
greenPoliceCar4.style.top = truckYPos + '%';
greenPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
greenPoliceCar5.style.top = truckYPos + '%';
greenPoliceCar6.style.left = sixthLaneXPos + truckOffset + 'px';
greenPoliceCar6.style.top = truckYPos + '%';
yellowPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
yellowPoliceCar4.style.top = truckYPos + '%';
yellowPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
yellowPoliceCar5.style.top = truckYPos + '%';
yellowPoliceCar6.style.left = sixthLaneXPos + truckOffset + 'px';
yellowPoliceCar6.style.top = truckYPos + '%';
//Road Lane 3
roadLine3.style.left = fourthLaneXPos - laneOffset + 'px';
roadLine3.style.top = -25 + '%';
//Road Lane 4
roadLine4.style.left = fifthLaneXPos - laneOffset + 'px';
roadLine4.style.top = -25 + '%';
//Road Lane 5
roadLine5.style.left = sixthLaneXPos - laneOffset + 'px';
roadLine5.style.top = -25 + '%';
animate();
}
function resize3() {
height = canvas.clientHeight;
width = canvas.clientWidth;
laneOffset = .1 * width; //6.5 percent of context width
truckOffset = .03 * width; //3 percent of context width
carOffset = .225 * height; //22.5 percent of context height
firstLaneXPos = laneOffset;
secondLaneXPos = (width / 3) + laneOffset;
thirdLaneXPos = width - (width / 3) + laneOffset;
setCurrentPlayerXPos();
initializeHelper();
infoBarImageContainer.style.left = 0 + 'px';
infoBarImageContainer.style.top = (.016 * height) + 'px';
trackBarImageContainer.style.left = 0 + 'px';
trackBarImageContainer.style.top = (.026 * height) + 'px';
}
function resize4() { //redraw if the window size is changed
height = canvas.clientHeight;
width = canvas.clientWidth;
laneOffset = .065 * width; //6.5 percent of context width
truckOffset = .03 * width; //3 percent of context width
carOffset = .225 * height; //22.5 percent of context height
firstLaneXPos = laneOffset;
secondLaneXPos = (width / 4) + laneOffset;
thirdLaneXPos = (width / 2) + laneOffset;
fourthLaneXPos = (width - (width / 4)) + laneOffset;
setCurrentPlayerXPos();
initializeHelper();
drawJBox();
drawRedBox4();
//Police car lane 4
policeCar4.style.left = fourthLaneXPos + truckOffset + 'px';
policeCar4.style.top = truckYPos + '%';
redPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
redPoliceCar4.style.top = truckYPos + '%';
greenPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
greenPoliceCar4.style.top = truckYPos + '%';
yellowPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
yellowPoliceCar4.style.top = truckYPos + '%';
//Road Lane 3
roadLine3.style.left = fourthLaneXPos - laneOffset + 'px';
roadLine3.style.top = -25 + '%';
infoBarImageContainer.style.left = 0 + 'px';
infoBarImageContainer.style.top = (.016 * height) + 'px';
trackBarImageContainer.style.left = 0 + 'px';
trackBarImageContainer.style.top = (.026 * height) + 'px';
}
function resize5() {
height = canvas.clientHeight;
width = canvas.clientWidth;
laneOffset = .035 * width; //6.5 percent of context width
truckOffset = .03 * width; //3 percent of context width
carOffset = .225 * height; //22.5 percent of context height
firstLaneXPos = laneOffset;
secondLaneXPos = (width / 5) + laneOffset; //width / 4 - 10
thirdLaneXPos = 2 * (width / 5) + laneOffset; // width / 4 - 20
fourthLaneXPos = 3 * (width / 5) + laneOffset; //width / 4 - 30
fifthLaneXPos = 4 * (width / 5) + laneOffset;
setCurrentPlayerXPos();
initializeHelper();
drawJBox();
drawKBox();
drawRedBox4();
drawRedBox5();
//Police car lane 4
policeCar4.style.left = fourthLaneXPos + truckOffset + 'px';
policeCar4.style.top = truckYPos + '%';
policeCar5.style.left = fifthLaneXPos + truckOffset + 'px';
policeCar5.style.top = truckYPos + '%';
redPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
redPoliceCar4.style.top = truckYPos + '%';
redPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
redPoliceCar5.style.top = truckYPos + '%';
greenPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
greenPoliceCar4.style.top = truckYPos + '%';
greenPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
greenPoliceCar5.style.top = truckYPos + '%';
yellowPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
yellowPoliceCar4.style.top = truckYPos + '%';
yellowPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
yellowPoliceCar5.style.top = truckYPos + '%';
//Road Lane 3
roadLine3.style.left = fourthLaneXPos - laneOffset + 'px';
roadLine3.style.top = -25 + '%';
roadLine4.style.left = fifthLaneXPos - laneOffset + 'px';
roadLine4.style.top = -25 + '%';
infoBarImageContainer.style.left = 0 + 'px';
infoBarImageContainer.style.top = (.016 * height) + 'px';
trackBarImageContainer.style.left = 0 + 'px';
trackBarImageContainer.style.top = (.026 * height) + 'px';
}
function resize6() {
height = canvas.clientHeight;
width = canvas.clientWidth;
laneOffset = .02 * width; //6.5 percent of context width
truckOffset = .02 * width; //3 percent of context width
carOffset = .225 * height; //22.5 percent of context height
firstLaneXPos = laneOffset;
secondLaneXPos = (width / 6) + laneOffset; //width / 4 - 10
thirdLaneXPos = 2 * (width / 6) + laneOffset; // width / 4 - 20
fourthLaneXPos = 3 * (width / 6) + laneOffset; //width / 4 - 30
fifthLaneXPos = 4 * (width / 6) + laneOffset;
sixthLaneXPos = 5 * (width / 6) + laneOffset;
setCurrentPlayerXPos();
initializeHelper();
drawJBox();
drawKBox();
drawLBox();
drawRedBox4();
drawRedBox5();
drawRedBox6();
//Police car lane 4
policeCar4.style.left = fourthLaneXPos + truckOffset + 'px';
policeCar4.style.top = truckYPos + '%';
policeCar5.style.left = fifthLaneXPos + truckOffset + 'px';
policeCar5.style.top = truckYPos + '%';
policeCar6.style.left = sixthLaneXPos + truckOffset + 'px';
policeCar6.style.top = truckYPos + '%';
redPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
redPoliceCar4.style.top = truckYPos + '%';
redPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
redPoliceCar5.style.top = truckYPos + '%';
redPoliceCar6.style.left = sixthLaneXPos + truckOffset + 'px';
redPoliceCar6.style.top = truckYPos + '%';
greenPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
greenPoliceCar4.style.top = truckYPos + '%';
greenPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
greenPoliceCar5.style.top = truckYPos + '%';
greenPoliceCar6.style.left = sixthLaneXPos + truckOffset + 'px';
greenPoliceCar6.style.top = truckYPos + '%';
yellowPoliceCar4.style.left = fourthLaneXPos + truckOffset + 'px';
yellowPoliceCar4.style.top = truckYPos + '%';
yellowPoliceCar5.style.left = fifthLaneXPos + truckOffset + 'px';
yellowPoliceCar5.style.top = truckYPos + '%';
yellowPoliceCar6.style.left = sixthLaneXPos + truckOffset + 'px';
yellowPoliceCar6.style.top = truckYPos + '%';
//Road Lane 3
roadLine3.style.left = fourthLaneXPos - laneOffset + 'px';
roadLine3.style.top = -25 + '%';
roadLine4.style.left = fifthLaneXPos - laneOffset + 'px';
roadLine4.style.top = -25 + '%';