-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqbert.html
4150 lines (3797 loc) · 182 KB
/
qbert.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Q*bert arcade game</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<style>
@font-face {
font-family: 'NK57 Monospace Sc Sb';
src: url('fonts/NK57MonospaceScSb-Regular.woff2') format('woff2'),
url('fonts/NK57MonospaceScSb-Regular.woff') format('woff');
font-weight: normal;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'Source Code Pro';
src: url('fonts/SourceCodePro-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
font-display: swap;
}
#options {
width: 300px;
display: inline-block;
vertical-align: top;
}
.arrow-button {
display: inline-block;
background-color: white;
background-image: url(images/arrow.png);
height: 100px;
width: 100px;
border: none;
color: transparent;
}
.buttons-div {
width: 210px;
display: inline-block;
vertical-align: top;
}
.arrow-button:nth-of-type(1) {
transform: rotate(-90deg);
}
.arrow-button:nth-of-type(3) {
transform: rotate(180deg);
}
.arrow-button:nth-of-type(4) {
transform: rotate(90deg);
}
</style>
</head>
<body onload="startGame()">
<div style="display: none; font-family: 'NK57 Monospace Sc Sb';">
<img id="qbertLogo" src="images/QBert-Logo.png">
<img id="levelNumbers" src="images/level_numbers.png">
<img id="qbertFont" src="images/qbert_font.png">
<img id="qbertSprite" src="images/qbert_sprite.png">
<img id="ballsSprite" src="images/balls_sprite.png">
<img id="coilySprite" src="images/coily_sprite.png">
<img id="slickSprite" src="images/slick_sprite.png">
<img id="samSprite" src="images/sam_sprite.png">
<img id="wrongwaySprite" src="images/wrongway-sprite.png">
<img id="uggSprite" src="images/ugg_sprite.png">
<img id="swear" src="images/qbert_swear.png">
<img id="life" src="images/life.png">
</div>
<canvas id="qbert-canvas" height="820" width="768"></canvas>
<div class="buttons-div">
<input class="arrow-button" id="button-left" type="button" value="left" />
<input class="arrow-button" id="button-up" type="button" value="up" />
<input class="arrow-button" id="button-down" type="button" value="down" />
<input class="arrow-button" id="button-right" type="button" value="right" />
</div>
<div id="options">
<input id="addCoinButton" type="button" value="Add a coin"/><br/>
<input id="onePlayerStart" type="button" value="1 player start"/><br/>
<input id="twoPlayerStart" type="button" value="2 player start"/><br/>
<label for="canvasWidth">Canvas width (px) : </label><br/>
<input id="canvasWidth" name="canvasWidth" value="768"/><br/>
<label for="canvasHeight">Canvas height (px) : </label><br/>
<input id="canvasHeight" name="canvasHeight" value="820"/><br/>
<label for="nbLevels">Number of levels : </label><br/>
<input id="nbLevels" name="nbLevels" value="7"/><br/>
<label for="cubeSize">Cube size (px): </label><br/>
<input id="cubeSize" name="cubeSize" value="50"/><br/>
<label for="cubeHeight">Cube height (px): </label><br/>
<input id="cubeHeight" name="cubeHeight" value="50"/><br/>
<label for="qbertStartLevel">Qbert start level : </label><br/>
<input id="qbertStartLevel" name="qbertStartLevel" value="1"/><br/>
<label for="qbertStartBlock">Qbert start block : </label><br/>
<input id="qbertStartBlock" name="qbertStartBlock" value="1"/><br/>
<label for="colorLeft">Left side color : </label><br/>
<input id="colorLeft" name="colorLeft" value="#633100"/><br/>
<label for="colorRight">Right side color : </label><br/>
<input id="colorRight" name="colorRight" value="#ff721c"/><br/>
<label for="colorTop">Top side color : </label><br/>
<input id="colorTop" name="colorTop" value="#ebdc7d"/><br/>
<label for="colorBackground">Background color : </label><br/>
<input id="colorBackground" name="colorBackground" value="#000"/><br/>
<label for="colorFrame">Frame color : </label><br/>
<input id="colorFrame" name="colorFrame" value="#000"/><br/>
<label for="qbertColorPalette">Color palette :</label><br/>
<select id="qbertColorPalette" name="qbertColorPalette"></select><br/>
<label for="qbertColorPaletteTop">Top side color palette :</label><br/>
<select id="qbertColorPaletteTop" name="qbertColorPaletteTop"></select><br/>
<label for="qbertLevel">Level selected :</label><br/>
<select id="qbertLevel" name="qbertLevel">
</select><br/>
<label for="qbertRound">Round selected :</label><br/>
<select id="qbertRound" name="qbertRound">
</select><br/>
<label for="qbertLevelType">Type of gameplay :</label><br/>
<select id="qbertLevelType" name="qbertLevelType">
<option value="1">Level #1</option>
<option value="2">Level #2</option>
<option value="3">Level #3</option>
<option value="4">Level #4</option>
<option value="5">Level #5</option>
</select><br/>
<label for="sceneSelection">Current scene :</label><br/>
<select id="sceneSelection" name="sceneSelection">
<option value="title">Title scene</option>
<option value="instructions">Instructions scene</option>
<option value="demo">Demo scene</option>
<option value="highscores">High scores scene</option>
<option value="main">Main game scene</option>
<option value="level">New level scene</option>
<option value="entername">Enter your name scene</option>
</select><br/>
<label for="currentPlayer">Current player :</label><br/>
<select id="currentPlayer" name="currentPlayer">
<option value="0">Player 1</option>
<option value="1">Player 2</option>
</select><br/>
<label for="nbCredits">Number of credits : </label><br/>
<input id="nbCredits" name="nbCredits" value="0"/><br/>
</div>
<script>
class Character {
constructor(type) {
this.type = type;
this.show = true;
this.showOnTop = true;
this.currentRow = 1;
this.currentCube = 1;
this.targetRow = 1;
this.targetCube = 1;
this.moving = false;
this.knelt = false;
this.currentDirection = '';
this.x = 0;
this.y = 0;
this.setTarget = 'off';
this.targetX = 0;
this.targetY = 0;
this.targetYHitDown = true;
this.vx = 0;
this.vy = 0;
this.width = 0;
this.height = 0;
this.pauseTimer = 0;
this.jumpFrameTime = 0.3;
this.jumpFrameTimer = this.jumpFrameTime;
this.jumpPeakTime = 0;
this.jumpPeakTimer = this.jumpPeakTime;
this.jumpCurrentFrame = 0;
this.gravityFactor = 1;
this.angle = 0;
this.landingSound = '';
this.jumpSound = '';
this.playLandingSound = true;
this.playJumpSound = false;
this.playFallSound = true;
}
}
// ======== Region : variables initialisation ========
const canvas = document.getElementById('qbert-canvas');
const ctx = canvas.getContext('2d');
let imagesFolder = 'images/';
let soundsFolder = 'sounds/';
let gameRunning = true;
let firstPowerUp = true;
let pushStart = false;
let allowMovement = false;
let currentScene = 'title';
let secondsPassed = 0;
let oldTimeStamp = 0;
let globalGravityFactor = 200;
let gravity = 9.81 * globalGravityFactor;
let minCharacterGravityFactor = 0.5;
let objectsList = [];
let sceneTransitionTime = 5;
let currentSceneTransitionTime = sceneTransitionTime;
let levelType = [1, 1];
let maxPlayers = 2;
let nbPlayer = 0;
let currentPlayer = 0;
let currentLevelPlayer = [0, 0];
let currentRoundPlayer = [0, 0];
let scorePlayer = [0, 0];
let gameOverPlayer = [true, true];
let gameStartedPlayer = [false, false];
let rankPlayer = [-1, -1];
let maxLives = 10;
let defaultStartLives = 3;
let livesPlayer = [defaultStartLives, defaultStartLives];
let extraLivesPlayer = [0, 0];
// Points-related variables
let pointsFirstExtraLife = 8000;
let pointsAdditionalLife = 14000;
let pointsTargetColor = 25;
let pointsIntermediateColor = 15;
let pointsRemainingDisk = 50;
let pointsCoilyFall = 500;
let pointsSamSlick = 300;
let pointsGreenBall = 100;
let highScoresTable = [
{ name: 'TJC', score: 3000 }, { name: 'JML', score: 2500 }, { name: 'JAH', score: 2000 },
{ name: 'MJS', score: 1750 }, { name: 'ECW', score: 1500 }, { name: 'BLT', score: 1250 },
{ name: 'BMW', score: 1000 }, { name: 'DMW', score: 950 }, { name: 'FDA', score: 900 },
{ name: 'IRS', score: 850 }, { name: 'LBJ', score: 800 }, { name: 'FDR', score: 750 },
{ name: 'JFK', score: 700 }, { name: 'IRT', score: 650 }, { name: 'CSN', score: 600 },
{ name: 'IND', score: 575 }, { name: 'CTA', score: 550 }, { name: 'BMT', score: 525 },
{ name: 'CDB', score: 500 }, { name: 'XRT', score: 475 }, { name: 'LS ', score: 450 },
{ name: 'MET', score: 425 }, { name: 'LUP', score: 400 }
];
// Font-related variables
let fontName = 'Source Code Pro'
let fontDefaultSize = 25;
let fontSmallSize = 15;
let fontBottomMargin = 5;
let spacingCascadeText = 2;
let fontHeightSpacing = fontDefaultSize + fontBottomMargin;
let fontsList = {
standard: String(fontDefaultSize) + 'px "' + fontName + '"',
bold: 'bold ' + String(fontDefaultSize) + 'px "' + fontName + '"',
small: String(fontSmallSize) + 'px "' + fontName + '"',
smallbold: 'bold ' + String(fontSmallSize) + 'px "' + fontName + '"',
};
let underlineHeightPx = 5;
ctx.font = fontsList.bold;
// Variables containing strings to be displayed
let creditsString = 'CREDITS';
let changeToString = 'CHANGE TO:';
let levelString = 'LEVEL:';
let roundString = 'ROUND:';
let bonusString = 'BONUS';
let highScoresString = 'HIGH SCORES';
let gameOverString = 'GAME OVER';
let copyrightLine1 = '©1982 D. GOTTLIEB AND CO.';
let copyrightLine2 = 'ALL RIGHTS RESERVED';
let coinPlayString = '1 COIN = 1 PLAY';
let pushPlayerString = ['PUSH ONE PLAYER START ONLY', 'PUSH ONE OR TWO PLAYER START'];
let instructionsString = [
'JUMP ON SQUARES TO CHANGE THEM TO THE TARGET COLOR',
'STAY ON PLAYFIELD! JUMPING OFF RESULTS IN A FATAL PLUMMET UNLESS A DISK IS THERE',
'AVOID ALL OBJECTS AND CREATURES THAT ARE NOT GREEN',
'USE SPINNING DISKS TO LURE SNAKE TO HIS DEATH',
'EXTRA LIFE AT ' + String(pointsFirstExtraLife) + ' AND EACH ADDITIONAL ' + String(pointsAdditionalLife)
];
let enterNameTitleString = ['YOU DID IT!', 'HI THERE!'];
let messageEnterNameString = [
['YOU HAVE USURPED ALL', 'OTHERS TO BECOME THE', 'KINDLY ENTER YOUR INITIALS', 'FOR ALL TO SEE'],
['WELCOME TO THE NOSER ELITE!', 'YOUR RANKING IS ', 'JOYSTICK SELECTS LETTERS', 'EITHER BUTTON WILL ENTER']
];
let highScoresRankString = [
'SUPREME NOSER!', 'YOU ARE SECOND ONLY TO ONE', 'YOU MUST KNOW SOMETHING!', 'YOU MAKE IT LOOK SO EASY!', 'QUITE IMPRESSIVE ACTUALLY',
'AN OUTSTANDING ACHIEVEMENT', 'AN EXPERT WITH A JOYSTICK', 'NOT SHABBY AT ALL', 'A POTENTIAL CHAMPION', 'YOU MADE THE TOP TEN CLUB!',
'JUST MISSED THE TOP TEN!', 'YOU COULD HAVE DONE WORSE!', 'ALMOST OUT OF THE TEENS!', 'LOOKING GOOD OUT THERE!', 'A TRULY HONORABLE POSITION',
'NOW TRY AND GET SERIOUS!', "IT'S A LONG WAY TO THE TOP", 'PRACTICE MAKES PERFECT!', 'NOTHING TO BRAG ABOUT!', 'ALMOST GOT INTO THE TEENS!',
'ONLY 20 SCORES TO BEAT!', 'NOT BAD FOR A BEGINNER!', 'THE BOTTOM OF THE BARREL!'
];
let highScoresRankErrorString = "WAIT! YOU SHOULDN'T BE HERE!";
let placeholderHighScoreString = '99) AAA 9999999';
let timeString = 'TIME';
let eraseString = 'RUB';
let endString = 'END';
let useIndicationsString = ['USE', 'TO ERASE', 'WHEN DONE'];
let instructionsLines = [];
let playerString = 'PLAYER';
let playerSelectString = ['PLAYER ONE', 'PLAYER TWO'];
let creditsNumber = 0;
let screenPaddingX = 50;
let screenPaddingY = 50;
let cubeSize = 50;
let cubeHeight = 50;
let sin30;
let cos30;
let pyramidLevels = 7;
let pyramidPosX = 10;
let pyramidPosY = 10;
let pyramidHorizontalAlign = 'center';
let pyramidVerticalAlign = 'center';
let flyingTargetX = 0;
let flyingTargetY = 0;
let qbertSize = 50;
let qbert = [new Character('qbert'), new Character('qbert')];
let startRow = 1;
let startCube = 1;
let qbertTitlePosX;
let qbertTitlePosY;
let qbertTitleSpeed = 200;
let qbertInstructionsOffsetX = 50;
let qbertInstructionsOffsetY = 120;
let diskDiameter = 50;
let offsetDiskQbertX = -5;
let offsetDiskQbertY = qbertSize / 2;
// Colour-related variables
const qbertColorsPalettes = [
{
leftColor: '#56A999',
rightColor: '#314646',
topColor: ['#FF6666', '#DEDE00', '#5646EF']
},
{
leftColor: '#663100',
rightColor: '#FF7721',
topColor: ['#0045DE', '#EFDE77', '#21B931']
},
{
leftColor: '#777777',
rightColor: '#212121',
topColor: ['#B9CECE', '#454545', '#2166CE']
},
{
leftColor: '#778787',
rightColor: '#0F0F99',
topColor: ['#A9B90F', '#0066EF', '#990066']
},
{
leftColor: '#000000',
rightColor: '#000000',
topColor: ['#0045EF', '#CECE00', '#FF6666']
},
{
leftColor: '#B9B921',
rightColor: '#B93131',
topColor: ['#870077', '#003199', '#2187CE']
},
{
leftColor: '#B9B921',
rightColor: '#003199',
topColor: ['#00A9DE', '#456655', '#FF5555']
},
{
leftColor: '#004500',
rightColor: '#0F9921',
topColor: ['#0045FF', '#CECE00', '#B96621']
},
{
leftColor: '#000000',
rightColor: '#000000',
topColor: ['#000000', '#0000CE', '#000000']
}
];
const levels = [
{
rounds: [
{ colorPalette: 0, topColorIndex: [2, 1, 0], disks: ['l5', 'r5'], bonus: 1000, characters: ['redball', 'coily'] },
{ colorPalette: 1, topColorIndex: [1, 0, 2], disks: ['l6', 'r7'], bonus: 1250, characters: ['redball', 'coily'] },
{ colorPalette: 2, topColorIndex: [0, 1, 2], disks: ['l4', 'r6'], bonus: 1500, characters: ['coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 3, topColorIndex: [1, 0, 2], disks: ['l1', 'r7'], bonus: 1750, characters: ['redball', 'coily', 'greenball', 'slick', 'sam'] }
],
type: 1,
introSound: soundsFolder + 'level-start.mp3',
introQbertMoves: ['right', 'left', 'down', 'up']
},
{
rounds: [
{ colorPalette: 1, topColorIndex: [0, 1, 2], disks: ['l4', 'r1', 'r5'], bonus: 2000, characters: ['coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 3, topColorIndex: [2, 1, 0], disks: ['l6', 'r1', 'r6'], bonus: 2250, characters: ['coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 0, topColorIndex: [0, 2, 1], disks: ['l3', 'r6'], bonus: 2500, characters: ['redball', 'coily', 'greenball', 'slick', 'sam'] },
{ colorPalette: 4, topColorIndex: [1, 0, 2], disks: ['l2', 'r4'], bonus: 2750, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] }
],
type: 2,
introSound: soundsFolder + 'tune-3.mp3',
introQbertMoves: ['right', 'down', 'left', 'right', 'up', 'down']
},
{
rounds: [
{ colorPalette: 5, topColorIndex: [2, 1, 0], disks: ['l3', 'l5', 'r3', 'r4'], bonus: 3000, characters: ['redball', 'coily', 'greenball', 'slick', 'sam'] },
{ colorPalette: 2, topColorIndex: [1, 0, 2], disks: ['l3', 'l4', 'r4', 'r6'], bonus: 3250, characters: ['coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 1, topColorIndex: [0, 1, 2], disks: ['l1', 'l3', 'r5'], bonus: 3500, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 0, topColorIndex: [1, 2, 0], disks: ['r2', 'r5', 'r7'], bonus: 3750, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] }
],
type: 3,
introSound: soundsFolder + 'tune-2.mp3',
introQbertMoves: ['right', 'down', 'left', 'up', 'down', 'right', 'up']
},
{
rounds: [
{ colorPalette: 1, topColorIndex: [2, 1, 0], disks: ['l1', 'l4', 'l6', 'r2', 'r6', 'r7'], bonus: 4000, characters: ['redball', 'coily', 'greenball', 'slick', 'sam'] },
{ colorPalette: 4, topColorIndex: [0, 2, 1], disks: ['l1', 'l5', 'l6', 'r2', 'r6', 'r7'], bonus: 4250, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 0, topColorIndex: [1, 0, 2], disks: ['l3', 'l5', 'r2', 'r3', 'r5'], bonus: 4500, characters: ['redball', 'coily', 'greenball', 'slick', 'sam'] },
{ colorPalette: 3, topColorIndex: [2, 1, 0], disks: ['l1', 'l2', 'r4', 'r7'], bonus: 4750, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] }
],
type: 4,
introSound: soundsFolder + 'tune-4.mp3',
introQbertMoves: ['down', 'right', 'left', 'up', 'down', 'right', 'left', 'up', 'down']
},
{
rounds: [
{ colorPalette: 0, topColorIndex: [0, 1, 2], disks: ['l1', 'l2', 'l4', 'l6', 'r1', 'r3', 'r7'], bonus: 4750, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 1, topColorIndex: [2, 0, 1], disks: ['l1', 'l5', 'l6', 'r2', 'r4', 'r5'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 2, topColorIndex: [1, 2, 0], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 3, topColorIndex: [0, 1, 2], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] }
],
type: 5,
introSound: soundsFolder + 'tune-2.mp3',
introQbertMoves: ['down', 'right', 'left', 'up', 'down', 'right', 'left', 'up', 'down']
},
{
rounds: [
{ colorPalette: 1, topColorIndex: [2, 0, 1], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 3, topColorIndex: [1, 2, 0], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 0, topColorIndex: [0, 1, 2], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 4, topColorIndex: [2, 0, 1], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] }
],
type: 5,
introSound: soundsFolder + 'tune-4.mp3',
introQbertMoves: ['down', 'right', 'left', 'up', 'down', 'right', 'left', 'up', 'down']
},
{
rounds: [
{ colorPalette: 5, topColorIndex: [1, 2, 0], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 2, topColorIndex: [0, 1, 2], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 1, topColorIndex: [2, 0, 1], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 0, topColorIndex: [1, 2, 0], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] }
],
type: 5,
introSound: soundsFolder + 'tune-3.mp3',
introQbertMoves: ['down', 'right', 'left', 'up', 'down', 'right', 'left', 'up', 'down']
},
{
rounds: [
{ colorPalette: 1, topColorIndex: [0, 1, 2], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 4, topColorIndex: [2, 0, 1], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 0, topColorIndex: [1, 2, 0], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 3, topColorIndex: [0, 1, 2], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] }
],
type: 5,
introSound: soundsFolder + 'level-start.mp3',
introQbertMoves: ['down', 'right', 'left', 'up', 'down', 'right', 'left', 'up', 'down']
},
{
rounds: [
{ colorPalette: 0, topColorIndex: [2, 0, 1], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 1, topColorIndex: [1, 2, 0], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 5, topColorIndex: [0, 1, 2], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] },
{ colorPalette: 3, topColorIndex: [2, 0, 1], disks: ['l3', 'l5', 'r3', 'r4', 'r7'], bonus: 5000, characters: ['redball', 'coily', 'greenball', 'ugg', 'wrongway', 'slick', 'sam'] }
],
type: 5,
introSound: soundsFolder + 'tune-2.mp3',
introQbertMoves: ['down', 'right', 'left', 'up', 'down', 'right', 'left', 'up', 'down']
}
];
let currentColorPalette = [0, 0];
let currentTopColorIndex = [1, 1];
let leftColor;
let rightColor;
let topColorList = [];
let topColor;
let topColorIndexArray = [[], []];
let frameStrokeColor = '#000000';
let backgroundMainColor = '#000000';
let backgroundTitleColor = '#312177';
let backgroudDiskColor = '#00ff00';
let currentMainSceneBackgroundColor = backgroundMainColor;
let fontsColors = { green: '#00B900', orange: '#FF7700', pink: '#EF6699', yellow: '#DEDE00', purple: '#770066', red: '#EF1021', magenta: '#B900B9', blue: '#0045DE' };
let gradientStopPlayerString = [
{ stop: 0.000, color: fontsColors.magenta },
{ stop: 0.333, color: fontsColors.purple },
{ stop: 0.5, color: fontsColors.magenta },
{ stop: 0.667, color: fontsColors.pink },
{ stop: 1.000, color: fontsColors.pink }
];
let gradientPlayerStringSpeed = 0.015;
// Pictures and sprites
let imageQbertLogo = document.getElementById('qbertLogo');
let imageLevelNumbers = document.getElementById('levelNumbers');
let imageQbertFont = document.getElementById('qbertFont');
let imageQbert = document.getElementById('qbertSprite');
let imageSwear = document.getElementById('swear');
let imageBalls = document.getElementById('ballsSprite');
let imageCoily = document.getElementById('coilySprite');
let imageSlick = document.getElementById('slickSprite');
let imageSam = document.getElementById('samSprite');
let imageWrongWay = document.getElementById('wrongwaySprite');
let imageUgg = document.getElementById('uggSprite');
let imageLife = document.getElementById('life');
let powerUpWaitTime = 1;
let currentPowerTime = powerUpWaitTime;
let blinkingTime = 1;
let blinkingTimer = blinkingTime;
let blinkingOnState = true;
// Instructions scene variables
let startInstructionQbertJumpTime = 2;
let instructionsTime = 3;
let instructionsTimer = instructionsTime;
let instructionsShow = [];
let currentInstruction = -1;
let showNextInstruction = false;
let instructionsEnd = false;
let instructionsAnimationInit = false;
let instructionsBallHit = false;
let showSwear = false;
let instructionsPosX;
let instructionsPosY;
let diskColorTime = 0.1;
let diskColorTimer = diskColorTime;
let diskTopColorList = [];
let diskBottomColor;
let disksPositionList = [];
let disksPresenceList = [];
let diskOffsetX = 5;
let diskOffsetY = 10;
let arrowsTime = 1;
let arrowsTimer = arrowsTime;
let arrowsShow = [false, false];
// Characters variables
let characterDropTime = 3;
let characterDropTimer = characterDropTime;
// Main scene variables
let endLevelTime = 2.7;
let nextRoundTime = 2;
let nextRoundShortTime = 1;
let flashColorTime = 0.07;
let diskBonusCountTime = 0.5;
let gameOverTime = 2;
let fallTime = 2;
let flyingDiskTime = 3;
let flyingDiskFallTime = 1;
let backgroundFlashingTime = 0.3;
let characterPauseTime = 0.2;
let multiplayerStartTime = 4;
let multiplayerStartTimer = multiplayerStartTime;
let endLevelTimer = endLevelTime;
let flashColorTimer = flashColorTime;
let nextRoundTimer = nextRoundTime;
let gameOverTimer = gameOverTime;
let fallTimer = fallTime;
let backgroundFlashingTimer = backgroundFlashingTime;
let coilyHatchTimer = characterDropTime;
let endLevel = false;
let showBonus = false;
let countDiskBonus = false;
let playFallSound = true;
let playEndLevelSound = true;
let flyingDiskSequence = false;
let showFlyingDisk = false;
let generateCharacters = true;
let newPlayerStart = false;
let remainingFlyingDisksCounter = 0;
let currentCharacterIndex = 0;
let coilyJumpSoundCounter = 1;
let uggSoundCounter = 1;
let swearSoundCounter = 1;
let samSoundCounter = 1;
// Level scene variables
let playLevelSound = true;
let levelSceneTime = 3;
let levelSwitchMainTime = 1;
let levelQbertMovesIterator;
let levelNumberShow = false;
let levelNumberFirstFlashTime = 0.5;
let levelNumberFlashTime = 0.3;
let levelNumberFlashCounter = 0;
let levelNumberFlashCounterMax = 3;
let levelNumberFlashTimer = levelNumberFirstFlashTime;
let levelSceneTimer;
let levelSwitchMainTimer = levelSwitchMainTime;
let levelSceneTopPadding = 10;
let levelNumberLargeWidth = 100;
let letterLevelStrokeWidth = 20;
let letterLevelStrokeHeight = 20;
let levelNumberTargetWidth = letterLevelStrokeHeight * 3;
let levelPlaygroundCubes = [
false, true, false,
true, true,
false, true, false
];
let levelPlaygroundCubesColors = [0, 0, 0, 0, 0, 0, 0, 0];
// Demo scene variables
let demoSceneTime = 10;
let demoSceneTimer = demoSceneTime;
// High scores scene variables
let highScoresSceneTime = 8;
let highScoresSceneTimer = highScoresSceneTime;
let spaceWidthHighScore = 50;
let spaceHeightHighScore = 40;
let highScoreTitlePaddingTop = 70;
let numberColumsHighScores = 2;
let letterOriginalHeight = 110;
// Enter name scene variables
let enterNameInitials = '';
let enterNameTime = 30;
let enterNameTimer = enterNameTime;
let enterNameGreenBallSize = 40;
let lettersByRow = 6;
let enterNameLettersRows = Math.ceil(28 / lettersByRow);
let spacingCharacter = ' ';
let spaceBetweenCharacters = 5;
let spaceBeforeRow = 3;
let dummyRow = spacingCharacter.repeat(lettersByRow * (1 + spaceBetweenCharacters) - 1);
let enterNameTitleHeight = 50;
let enterNameTitlePosY = screenPaddingY;
let enterNameInfoTextPosY = enterNameTitlePosY + 2 * enterNameTitleHeight;
let enterNameLettersPosX = (canvas.width - ctx.measureText(dummyRow).width) / 2;
let enterNameLettersPosY = enterNameInfoTextPosY + 11 * fontHeightSpacing;
let enterNameGreenBallPosXIni = enterNameLettersPosX - enterNameGreenBallSize * 0.33;
let enterNameGreenBallPosYIni = enterNameLettersPosY - fontHeightSpacing - enterNameGreenBallSize * 0.9;
let enterNameGreenBallPosX = enterNameGreenBallPosXIni;
let enterNameGreenBallPosY = enterNameGreenBallPosYIni;
let currentGreenBallRow = 1;
let currentGreenBallLetter = 1;
// ======== Region : initialisation phase ========
populateSelectColorPalettes();
populateSelectTopColor();
populateLevelsList();
populateRoundsList();
levelSetup();
updateColorInputValues();
buildTopColorIndexArrayAllPlayers();
initInstructionsLines();
computeSinCosCube();
computePositionsAllPlayers();
sceneController(currentScene);
// ======== Region : start game function ========
function startGame() {
initEnterNameLettersPosition();
window.requestAnimationFrame(gameLoop);
}
// ======== Region : iinteraction with the inputs ========
document.getElementById('canvasWidth').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = 768; }
if (parsed <= 0) { parsed = 768; }
document.getElementById('qbert-canvas').setAttribute('width', parsed);
computePositionsAllPlayers();
});
document.getElementById('canvasHeight').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = 820; }
if (parsed <= 0) { parsed = 820; }
document.getElementById('qbert-canvas').setAttribute('height', parsed);
computePositionsAllPlayers();
});
document.getElementById('nbLevels').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = pyramidLevels; }
if (parsed <= 0) { parsed = pyramidLevels; }
if (parsed >= 12) { parsed = 12; }
pyramidLevels = parsed;
buildTopColorIndexArrayAllPlayers();
computePositionsAllPlayers();
});
document.getElementById('cubeSize').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = cubeSize; }
if (parsed <= 0) { parsed = cubeSize; }
cubeSize = parsed;
buildTopColorIndexArrayAllPlayers();
computeSinCosCube();
computePositionsAllPlayers();
});
document.getElementById('cubeHeight').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = cubeHeight; }
if (parsed <= 0) { parsed = cubeHeight; }
cubeHeight = parsed;
buildTopColorIndexArrayAllPlayers();
computePositionsAllPlayers();
});
document.getElementById('qbertStartLevel').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = startRow; }
if (parsed <= 0) { parsed = startRow; }
startRow = parsed;
buildTopColorIndexArrayAllPlayers();
computePositionsAllPlayers();
});
document.getElementById('qbertStartBlock').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = startCube; }
if (parsed <= 0) { parsed = startCube; }
startCube = parsed;
buildTopColorIndexArrayAllPlayers();
computePositionsAllPlayers();
});
document.getElementById('colorLeft').addEventListener('change', function(e) {
leftColor = this.value;
});
document.getElementById('colorRight').addEventListener('change', function(e) {
rightColor = this.value;
});
document.getElementById('colorTop').addEventListener('change', function(e) {
topColor = this.value;
});
document.getElementById('colorBackground').addEventListener('change', function(e) {
backgroundMainColor = this.value;
});
document.getElementById('colorFrame').addEventListener('change', function(e) {
frameStrokeColor = this.value;
});
document.getElementById('qbertColorPalette').addEventListener('change', function(e) {
setColorPalette(this.value);
setDiskColorList();
updateColorInputValues();
buildTopColorIndexArrayAllPlayers();
});
document.getElementById('qbertColorPaletteTop').addEventListener('change', function(e) {
setColorPalette(currentColorPalette[currentPlayer], this.value);
updateColorInputValues();
buildTopColorIndexArrayAllPlayers();
});
document.getElementById('qbertLevelType').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = levelType[currentPlayer]; }
if (parsed <= 0) { parsed = levelType[currentPlayer]; }
levelType[currentPlayer] = parsed;
buildTopColorIndexArrayAllPlayers();
});
document.getElementById('nbCredits').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = creditsNumber; }
if (parsed < 0) { parsed = creditsNumber; }
setNumberCredits(parsed);
if (parsed > 0) {
playSound('coin');
}
});
document.getElementById('sceneSelection').addEventListener('change', function(e) {
sceneController(this.value);
});
document.getElementById('currentPlayer').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = currentPlayer; }
if (parsed < 0) { parsed = currentPlayer; }
currentPlayer = parsed;
changePlayer(currentPlayer);
levelSetup();
});
document.getElementById('qbertLevel').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = currentLevelPlayer[currentPlayer]; }
if (parsed < 0) { parsed = currentLevelPlayer[currentPlayer]; }
currentLevelPlayer[currentPlayer] = parsed;
levelSetup();
updateColorInputValues();
buildTopColorIndexArrayAllPlayers();
sceneController('level');
});
document.getElementById('qbertRound').addEventListener('change', function(e) {
let parsed = parseInt(this.value);
if (isNaN(parsed)) { parsed = currentRoundPlayer[currentPlayer]; }
if (parsed < 0) { parsed = currentRoundPlayer[currentPlayer]; }
currentRoundPlayer[currentPlayer] = parsed;
levelSetup();
updateColorInputValues();
buildTopColorIndexArrayAllPlayers();
sceneController(currentScene);
});
document.getElementById('addCoinButton').addEventListener('click', function(e) {
addCoin();
});
document.getElementById('onePlayerStart').addEventListener('click', function(e) {
player1Pressed(e);
});
document.getElementById('twoPlayerStart').addEventListener('click', function(e) {
player2Pressed(e);
});
document.getElementById('button-left').addEventListener('click', function(e) {
performMove(e, 'left');
});
document.getElementById('button-right').addEventListener('click', function(e) {
performMove(e, 'right');
});
document.getElementById('button-up').addEventListener('click', function(e) {
performMove(e, 'up');
});
document.getElementById('button-down').addEventListener('click', function(e) {
performMove(e, 'down');
});
document.addEventListener('keydown', function(e) {
switch (e.key) {
case 'ArrowUp':
performMove(e, 'up');
break;
case 'ArrowDown':
performMove(e, 'down');
break;
case 'ArrowRight':
performMove(e, 'right');
break;
case 'ArrowLeft':
performMove(e, 'left');
break;
case ' ':
e.preventDefault();
addCoin();
break;
case '1':
player1Pressed(e);
break;
case '2':
player2Pressed(e);
break;
}
});
function player1Pressed(e) {
e.preventDefault();
if (currentScene == 'entername') {
selectLetter();
return;
}
if (pushStart == true) {
nbPlayer = 1;
startNewGame();
}
}
function player2Pressed(e) {
e.preventDefault();
if (currentScene == 'entername') {
selectLetter();
return;
}
if (pushStart == true && creditsNumber > 1) {
nbPlayer = 2;
startNewGame();
}
}
function performMove(e, direction) {
e.preventDefault();
if (allowMovement == false) { return; }
if(currentScene == 'main') {
moveCharacter(qbert[currentPlayer], direction);
} else if (currentScene == 'entername') {
moveGreenBall(direction);
}
}
// ======== Region : game loop + update and drawing loops ========
function gameLoop(timeStamp) {
secondsPassed = (timeStamp - oldTimeStamp) / 1000;
oldTimeStamp = timeStamp;
updateScene(currentScene, secondsPassed);
renderScene(currentScene);
window.requestAnimationFrame(gameLoop);
}
function updateScene(scene, secondsPassed) {
switch (scene) {
case 'main':
updateMainScene(secondsPassed);
break;
case 'title':
updateTitleScene(secondsPassed);
break;
case 'instructions':
updateInstructionsScene(secondsPassed);
break;
case 'demo':
updateDemoScene(secondsPassed);
break;
case 'level':
updateLevelScene(secondsPassed);
break;
case 'highscores':
updateHighScoresScene(secondsPassed);
break;
case 'entername':
updateEnterNameScene(secondsPassed);
break;
}
}
function renderScene(scene) {
switch (scene) {
case 'main':
drawMainScene();
break;
case 'title':
drawTitleScene();
break;
case 'instructions':
drawInstructionsScene();
break;
case 'demo':
drawDemoScene();
break;
case 'level':
drawLevelScene();
break;
case 'highscores':
drawHighScoresScene();
break;
case 'entername':
drawEnterNameScene();
break;
}
}
function sceneController(scene) {