-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
2222 lines (2024 loc) · 91.2 KB
/
index.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>
<head>
<script src="https://js13kgames.com/webxr-src/babylon.js"></script>
<style>
body {margin:0;overflow:hidden;}
#fps { position: absolute; left: 20px; top: 20px; color: #999; font-family: "Courier New", Courier, monospace }
</style>
</head>
<body>
<canvas id="jj" touch-action="none"></canvas>
<div id="fps"></div>
</body>
<script>
/*
######################################################
### Preparation
*/
// Set canvas size
can = document.getElementById("jj");
can.width = window.innerWidth;
can.height = window.innerHeight;
// Babylon engine on
engine = new BABYLON.Engine(can, true);
/*
######################################################
### Variables
*/
// Consts
FONT = "Consolas";
GRIDSIZE = 8;
GRIDWID = 30/GRIDSIZE;
DELTIME = 30;
DATABLKS = 200;
DEF_EYES = "o"
// Logo compressed
logo = [15395444,11438676,13274198,11176533,15657558];
// Camera position
camOff = new BABYLON.Vector3(0, 0, 1);
// Game state
/*
0 - Game not started yet
1 - Logo is created
2 - Game has started
*/
gameState = 0;
// Highlight layer
var hl;
// Materials
logoMaterials = [];
dataMaterials = [];
var eqSlot, selGrid, selPGrid, nonGrid, curMat, wallMat,
entrMat, reflMat, selSlot, gridBackMat, heroMat, crystMat,
splitterMat, splitter2Mat;
// Game vars
shakeCamera = 0; // Camera shake level (0-3)
actS = 0; // Current memory size
maxS = 13312; // Total memory size
dmgBuff = 0; // Total damaged memory
level = 0; // Level we are playing right now
exits = [0,0] // Exited sucessfully/total exits
slots = [[0,0],[0,0],[0,0],[0,0],[0,0]]; // Slot information
slotC = -1; // Choosen toolbar slot
gridPos = []; // Position of all grid slots
lasers = []; // All created lasers
delet = DELTIME; // Time to delete object
mouseDown = 0; // Is mouse down on canvas
gridC = -1; // Choosen grid slot
wantToPlace = false; // Do we want to place smth on the grid
reused = 0;
var vojc, // English voice
hero, // Body
heroEyes, // Eyes
isHero = 0, // Is hero created
heroMov = 0, // Calculate hero movement
heroIsSpeaking = 1, // Movement speed ratio
dialogs = [], // For ppl who has speechSynthesis disabled; Dialogs queue
isTalking = false, // For ppl who has speechSynthesis disabled; Check if hero is talking
whichSequance = 0, // Tells which dialog is spoken
isHighlight = -1, // Check if slot is highlighted
subSize = 30, // Set size of subtitles
isHighMode = -1; // Highlight mode
var optVoice = 1, // If true, speechSynthesis API is in use
optQuality = 2, // 0 - low, 1 - medium, 2 - high
optSensitiv = 300, // Mouse sensitivity; Default: 300
optAngle = Math.PI*0.25, // Options rotation
optAngle2 = Math.PI*1.75, // Options rotation
optCanPlace = false; // Check if placing/rotating/deleting is allowed [used for dialogs]
var gameEnd = false, // End of the game?
skySeq = 0, // Number used for animating ending sky
achiv = 0, // Unlocked achievements
isGameover = false, // Check if it's gameover
stopCameraShake = false, // Should camera shake be stopped
gameStarted = false, // Has game started?
memoLost = 0, // Which text of "memory lost" to say
gameWon = 0; // Did we win?
var VRhelper; // VR experience helper
// Array containing strings
S = [
"Click here to start playing",
"Memory size",
"Toolbar",
"Reflector",
"Game created by @holosiek & @bthefw",
"Mirror",
"<- Options",
"Achievements ->",
"Game ->",
"<- Achievements",
"Camera shake: ", // 10
"Animated logo: ", // 11
"Hero animations: ", // 12
"Objects animations: ", // 13
"Data blocks on the back: ", // 14
"Low", // 15
"Medium", // 16
"High", // 17
"Enabled", // 18
"Disabled", // 19
"speechSynthesis API", // 20
"Crystal", // 21
"Splitter", // 22
"<- Game", // 23
"Options ->", // 24
];
// Array containing level completed callouts
E = [
["Good job!", 1.5],
["Very nice", 0.8],
["Outstanding!", 0.8]
];
// Array containing colors
C = [
"#cacae7",
"#8e8ecc",
"#693e73",
"#555555",
"#777777",
"#FFFFFF"
];
LEVELS = [
[[2294399266,1715535888],[9,9,9,6,9,9,9,9,9,9,9,9,2,9,9,9,9],[10,2]], // Place/Rotate/Destroy tutorial
[[201326592,536903708],[9,7,1,9,9,9,9],[10,4]],
[[2172747992,2122416513],[9,9,9,9,2,4,9,9,2,4,9,9,2,4,9,7,7,7,7,7,7],[10,6]],
[[304120038,543966744],[9,9,9,9,9,9,9,4,14,9,7,9,9,9,9,9,9,9,9],[10,3]], // Crystal tutorial
[[2416203009,58221060],[9,9,3,9,9,9,9,9,9,9,9,9,9,11,6,9,9,9],[10,6]],
[[2610979967,3721063399],[1,11,10,11,11,10,10,10,10,10,10,10,10,10,11,10,13,10,11,10,10,11,11,11,10,10,10,10,10,10,10,10,11,10,11,7,11,11,11],[10,4]],
[[134758400,20],[2,9,9,8,14],[10,1,12,2]], // Mirror tutorial
[[16896,4325376],[5,1,14,14],[12,4]],
[[4294901761,33619967],[4,14,15,14,15,15,14,14,15,14,14,14,15,15,14,15,14,15,15,14,14,15,15,15,14,14,14,15,15,15,14,14,14,7],[10,1]],
[[182912,100794496],[9,8,9,5,9,9,9,4,9,9],[10,4,16,1]], // Splitter tutorial
[[805572608,4734976],[1,11,11,9,6,10,6],[10,2,16,1]],
[[24576,1048578],[1,5,8,7],[10,3,14,1,16,2]],
[[16812313,10066176],[8,2,4,8,2,6,8,8,2,8,2,8,2,8,2],[10,3,16,1]],
[[2164260888,2550136961],[5,5,8,6,8,6,7,7,3],[10,8,16,7]]
]
// Game grid
cubeGrid = Array(GRIDSIZE**2).fill({'type':'none','destructable':false})
/*
######################################################
### Misc functions
*/
// Return Babylon.js color
tex = (r, g, b) => {
return new BABYLON.Color3(r, g, b);
}
// Return Babylon.js standard material
mate = (a_id, a_color, a_disLight=false) => {
let a = new BABYLON.StandardMaterial(a_id, scene);
a.emissiveColor = a_color;
a.disableLighting = a_disLight;
return a;
}
// Return Babylon.js vector
vec3 = (x, y, z) => {
return new BABYLON.Vector3(x, y, z);
}
// Return random number from -1 to 1
randS = () => {
let r = Math.random();
return (Math.random()<=0.5)?r:-r;
}
// Random int from 0 to num-1
ranRng = num => {
return Math.floor(Math.random()*num);
}
// Return copy of the object
copyObj = a_obj => {
return JSON.parse(JSON.stringify(a_obj));
}
/*
######################################################
### Material creation
*/
// Create all materials
materialCreation = () => {
// Create colorful materials
for(var i=0; i<5; i++){
logoMaterials.push(mate("logoMat", tex(0.5+i*0.05, 0.9+i*0.025, 1), true));
}
// Create data materials
for(var i=0; i<5; i++){
dataMaterials.push(mate("dataMat", tex(0.3+i*0.05, 0.7+i*0.05, 1), true));
}
// Cursor material
curMat = mate("curMat", tex(1, 1, 1), true);
// Equiped slot material
eqSlot = mate("eqSlot", tex(0.07, 0.07, 0.12), true);
// Selected slot material
selSlot = mate("selSlot", tex(0.1, 0.1, 0.15), true);
// Selected placable grid
selPGrid = mate("selPGrid", tex(0.035, 0.12, 0.22), true);
// Selected grid
selGrid = mate("selGrid", tex(0.017, 0.06, 0.11), true);
// Non-selected grid
nonGrid = mate("nonGrid", tex(0.02, 0.02, 0.05), true);
nonGrid.alpha = 0.7;
// Wall material
wallMat = mate("wallMat", tex(0.6, 0.6, 0.6));
// Reflector material
reflMat = mate("reflMat", tex(0.8, 0.8, 0.8));
// Entry material
entrMat = mate("entrMat", tex(0, 0.5, 1));
// Exit material
exitMat = mate("exitMat", tex(0.5, 0.1, 0.1));
// Back of grid material
gridBackMat = mate("gridMat", tex(0.07, 0.07, 0.12), true);
// Hero material
heroMat = mate("heroMat", tex(0.862, 0.654, 0.909));
// Crystal material
crystMat = mate("crystMat", tex(0.321, 0.505, 0.717));
crystMat.alpha = 0.3;
// Splitter material
splitterMat = mate("splitterMat", tex(0.760, 0.713, 0.039));
// Splitter entrence material
splitter2Mat = mate("splitterMat", tex(0.5, 0.5, 0.5));
}
/*
######################################################
### VR
*/
enterVR = () => {
VRhelper.webVRCamera.setTarget(vec3(0,0,0));
VRhelper.webVRCamera.fov = 0.2;
}
leaveVR = () => {
VRhelper.deviceOrientationCamera.setTarget(vec3(0,0,0));
}
/*
######################################################
### Scene creation
*/
// Clear all data blocks
removeDataBlocks = () => {
var names = [];
scene.meshes.forEach(m=>{
if(/data[0-9]+/.test(m.name)){
names.push(m);
}
});
names.forEach(m=>{
m.dispose();
});
}
// Create data blocks
createDataBlocks = () => {
var pl = BABYLON.MeshBuilder.CreatePlane("data", {sideOrientation: 1}, scene);
pl.material = dataMaterials[ranRng(5)];
pl.scaling.x = 3;
pl.isPickable = false;
pl.isVisible = false;
for(var i=0; i<DATABLKS; i++){
var z = pl.createInstance("data"+i)
if(gameState > 1){
z.position = vec3((Math.random()*100-50)*1.4, (Math.random()*30-13)*1.4, -100);
} else {
z.position = vec3(Math.random()*100-50, Math.random()*30-13, -60-Math.random()*5);
}
}
}
// Create whole scene
createScene = () => {
// Create new scene and add needed options
scene = new BABYLON.Scene(engine);
scene.constantlyUpdateMeshUnderPointer = true;
// Set fog
scene.fogMode = 3; //BABYLON.Scene.FOGMODE_LINEAR
scene.fogStart = 50;
scene.fogEnd = 75;
// set background
scene.clearColor = tex(0.05, 0.05, 0.1);
// Set global light
g_light = new BABYLON.PointLight("light", camOff, scene);
g_light.intensity = 0.17;
// Create highlight layer
hl = new BABYLON.HighlightLayer("hl1", scene);
// Create camera
var metrics = BABYLON.VRCameraMetrics.GetDefault()
metrics.postProcessScaleFactor = 1;
VRhelper = scene.createDefaultVRExperience({'vrDeviceOrientationCameraMetrics': metrics});
VRhelper.onEnteringVRObservable.add(()=>{enterVR();})
VRhelper.onExitingVRObservable.add(()=>{leaveVR();})
VRhelper.deviceOrientationCamera.inertia = 0;
VRhelper.deviceOrientationCamera.position = camOff;
VRhelper.deviceOrientationCamera.angularSensibility = optSensitiv;
VRhelper.deviceOrientationCamera.attachControl(can, true);
VRhelper.deviceOrientationCamera.inputs.remove(VRhelper.deviceOrientationCamera.inputs.attached.keyboard);
VRhelper.webVRCamera.inertia = 0;
VRhelper.webVRCamera.position = camOff;
VRhelper.webVRCamera.angularSensibility = optSensitiv;
VRhelper.webVRCamera.attachControl(can, true);
VRhelper.webVRCamera.inputs.remove(VRhelper.webVRCamera.inputs.attached.keyboard);
VRhelper.teleportationEnabled = false;
// Create materials
materialCreation();
// Create background data blocks
createDataBlocks();
// Create cursor pointer
var cur = BABYLON.MeshBuilder.CreateBox("cursor", {}, scene);
cur.scaling = vec3(0.01, 0.01, 0.01);
cur.position = vec3(0, 0, 2);
cur.material = curMat;
cur.isPickable = false
// Create subtitles
drawText("subs", "", C[5], 40, vec3(0, -7, 18), 0, subSize);
var l = scene.getMeshByName("subs");
l.isPickable = false;
// Create glow layer
var gl = new BABYLON.GlowLayer("", scene);
gl.customEmissiveColorSelector = (mesh, subMesh, material, result) => {
if(mesh.name == "laserLines"){
result.set(0,0.5,1,1);
} else {
result.set(0,0,0,0);
}
}
scene.onBeforeCameraRenderObservable.add((camera) => {
scene.getMeshByName("subs").parent = camera;
scene.getMeshByName("cursor").parent = camera;
})
leaveVR();
}
/*
######################################################
### Sounds
*/
// Play click sound
var a = new Audio("click.wav");
a.volume = 0.5;
playClick = () => {
a.play();
}
/*
######################################################
### Saving/Loading local storage
*/
// Save achievements
saveAchiv = () => {
localStorage.setItem("BACKUPachiv", achiv);
}
/*
######################################################
### Game Over
*/
// Ending 1
gameFirewalled = () => {
for(var i=scene.meshes.length-1; i>=0; i--){
let m = scene.meshes[i]
if(m.name == "gridBack"){
m.dispose();
} else if(/gridZ[0-9]+/.test(m.name)){
m.dispose();
} else if(m.name == "toolbarLabel"){
m.dispose();
} else if(/slotT[0-9]+/.test(m.name)){
m.dispose();
} else if(/slotS[0-9]+/.test(m.name)){
m.dispose();
} else if(/slot[0-9]+/.test(m.name)){
m.dispose();
} else if(m.name == "logo"){
m.dispose();
} else if(m.name == "hero"){
m.dispose();
} else if(m.name == "heroEyes"){
m.dispose();
}
}
for(var i=0; i<dataMaterials.length; i++){
dataMaterials[i].alpha = 0.25
}
createLogo(true);
drawText("gameEnd1", "System detected memory changes!", C[5], 24, vec3(0, -2, -40), Math.PI);
drawText("gameEnd12", "Virus has been deleted", C[5], 24, vec3(0, -3.5, -40), Math.PI);
drawText("gameEnd13", "Thank you for playing :3", C[5], 24, vec3(0, -5.5, -40), Math.PI, 40);
drawText("gameoverLabel3", "Click here to restart game", C[5], 24, vec3(0, -7, -40), Math.PI, 40);
}
// Ending 2
gameClearIt = () => {
for(var i=scene.meshes.length-1; i>=0; i--){
let m = scene.meshes[i]
if(m.name == "gridBack"){
m.dispose();
} else if(/gridZ[0-9]+/.test(m.name)){
m.dispose();
} else if(m.name == "toolbarLabel"){
m.dispose();
} else if(/slotT[0-9]+/.test(m.name)){
m.dispose();
} else if(/slotS[0-9]+/.test(m.name)){
m.dispose();
} else if(/slot[0-9]+/.test(m.name)){
m.dispose();
} else if(m.name == "logo"){
m.dispose();
}
}
for(var i=0; i<dataMaterials.length; i++){
dataMaterials[i].alpha = 0.25
}
createLogo(true);
drawText("gameEnd2", "System hacked - Impossible to recover data", C[5], 24, vec3(0, -2, -40), Math.PI);
drawText("gameEnd22", "Message found: #@1_Thanzz#U%<3!", C[5], 24, vec3(0, -3.5, -40), Math.PI);
drawText("gameEnd23", "Thank you for playing <3", C[5], 24, vec3(0, -5.5, -40), Math.PI, 40);
drawText("gameoverLabel3", "Click here to restart game", C[5], 24, vec3(0, -7, -40), Math.PI, 40);
}
// Change sky color from flash to crash
gameCrash = () => {
let a = 0;
if(scene.clearColor.r-0.005 >= 0){scene.clearColor.r -= 0.005;}else{a++;}
if(scene.clearColor.g-0.005 >= 0){scene.clearColor.g -= 0.005;}else{a++;}
if(scene.clearColor.b-0.005 >= 0){scene.clearColor.b -= 0.005;}else{a++;}
if(a!=3){setTimeout(()=>{gameCrash()},10);}else{if(gameWon==1){gameEnd = 1;}}
}
// Change sky color to flash
skyWhite = () => {
let a = 0;
if(scene.fogStart-0.25 >= 5){scene.fogStart -= 0.25;}else{a++;}
if(scene.fogEnd-0.25 >= 5){scene.fogEnd -= 0.25;}else{a++;}
if(scene.fogColor.r+0.005 <= 1){scene.fogColor.r += 0.005;}else{a++;}
if(scene.fogColor.g+0.005 <= 1){scene.fogColor.g += 0.005;}else{a++;}
if(scene.fogColor.b+0.005 <= 1){scene.fogColor.b += 0.005;}else{a++;}
if(scene.clearColor.r+0.005 <= 1){scene.clearColor.r += 0.005;}else{a++;}
if(scene.clearColor.g+0.005 <= 1){scene.clearColor.g += 0.005;}else{a++;}
if(scene.clearColor.b+0.005 <= 1){scene.clearColor.b += 0.005;}else{a++;}
if(a!=8){setTimeout(()=>{skyWhite()},10);}else{if(gameWon==1){gameClearIt();}else{gameFirewalled();}gameCrash();}
}
// Ending 3 - 2many memory leaked
fogGG = () => {
if(scene.fogStart > 5){
scene.fogEnd -= 0.25;
scene.fogStart -= 0.25;
if(scene.fogColor.r-0.01 >= 0){scene.fogColor.r -= 0.01;}
if(scene.fogColor.g-0.01 >= 0){scene.fogColor.g -= 0.01;}
if(scene.fogColor.b-0.01 >= 0){scene.fogColor.b -= 0.01;}
if(scene.clearColor.r-0.01 >= 0){scene.clearColor.r -= 0.01;}
if(scene.clearColor.g-0.01 >= 0){scene.clearColor.g -= 0.01;}
if(scene.clearColor.b-0.01 >= 0){scene.clearColor.b -= 0.01;}
setTimeout(()=>{fogGG()},10);
} else {
stopCameraShake = true;
drawText("gameoverLabel", "Out of memory - system shotdown", C[5], 24, vec3(0, -2, -20), Math.PI, 30);
drawText("gameoverLabel2", "GAME OVER", "#ff0000", 24, vec3(0, -3, -20), Math.PI, 40);
drawText("gameoverLabel3", "Click here to restart game", C[5], 24, vec3(0, -4, -20), Math.PI);
}
}
/*
######################################################
### Game speech
*/
// Allows to skip dialog
skipDialog = () => {
window.speechSynthesis.cancel();
changeText("subs", "", 40, C[5], subSize);
heroIsSpeaking = 1;
dialogs = [];
checkIfEnd();
}
// Change dialog sequance number
checkIfEnd = () => {
if(!dialogs.length){
if(whichSequance%2 && whichSequance){whichSequance++};
changeEyes(DEF_EYES, DEF_EYES);
endDialog();
}
}
// Choose english language
setUpSpeaking = a_voices => {
for(var i=0; i<a_voices.length; i++){
if(a_voices[i].lang == "en-US"){
vojc = a_voices[i];
changeText("voiceLabel1", S[20], 10, C[1], 38);
changeText("voiceLabel2", S[18], 10, C[2], 32);
optVoice = 1;
return;
}
}
changeText("voiceLabel1", S[20], 10, C[3], 38);
changeText("voiceLabel2", "Not supported / no english voice", 10, C[3], 32);
optVoice = -1;
}
// For ppl who has disabled voice; saySmth()
saySmthDis = () => {
if(dialogs.length && !isTalking){
isTalking = true;
var sentence = dialogs.shift();
changeText("subs",sentence[0],40,C[5],subSize);
changeEyes(sentence[1], sentence[2]);
heroIsSpeaking = 20;
setTimeout(()=>{
changeText("subs","",40,C[5],subSize);
heroIsSpeaking = 1;
isTalking = false;
saySmthDis();
}, sentence[0].split(" ").length*650);
} else {
checkIfEnd();
}
}
// Say something if there is english voice
saySmth = (a_text, a_rate=1, a_left="o", a_right="o") => {
if(optVoice == 1 && vojc){
dialogs.push(a_text)
let pre = new SpeechSynthesisUtterance(a_text);
pre.pitch = 2;
pre.rate = a_rate;
pre.voice = vojc;
pre.onstart = ()=>{changeText("subs",a_text,40,C[5],subSize);heroIsSpeaking=20;changeEyes(a_left, a_right)};
pre.onend = ()=>{changeText("subs","",40,C[5],subSize);heroIsSpeaking=1;dialogs.shift();checkIfEnd()};
window.speechSynthesis.speak(pre);
} else {
dialogs.push([a_text, a_left, a_right]);
saySmthDis();
}
}
// Create timer which will check if there are any voices
var timer = setInterval(()=>{
var voices = speechSynthesis.getVoices();
if(voices.length){
setUpSpeaking(voices);
clearInterval(timer);
}
}, 200);
/*
######################################################
### Hero functions
*/
// Change her eyes
changeEyes = (a_left, a_right) => {
changeText("heroEyes", a_left + " " + a_right, 8, C[2], 100, 2);
}
// Create whole character: body, eyes
createHero = () => {
// Create body
hero = BABYLON.MeshBuilder.CreateBox("hero", {}, scene);
hero.position = vec3(-33, 3, -50);
hero.scaling = vec3(8, 8, 8);
hero.rotation = vec3(0, Math.PI*0.25, 0);
hero.material = heroMat;
hero.isPickable = false;
// Create eyes
drawText("heroEyes", "", C[2], 8, vec3(-23, 3.5, -35.75), Math.PI*1.25, 100, 2);
heroEyes = scene.getMeshByName("heroEyes");
changeEyes(DEF_EYES, DEF_EYES);
// Change var so code knows that hero is created
isHero = 1;
}
// Do smth when dialog ended
endDialog = () => {
let z = whichSequance;
whichSequance = 0;
switch(z){
case 2:
processLevel();
speakHero(2);
break;
case 4:
highlightObject(49);
isHighMode = 0;
speakHero(4);
break;
case 6:
optCanPlace = true;
break;
case 8:
highlightObject(10);
isHighMode = 0;
speakHero(8);
break;
case 10:
optCanPlace = true;
break;
case 12:
optCanPlace = true;
highlightObject(10);
isHighMode = 1;
break;
case 14:
optCanPlace = true;
highlightObject(9);
isHighMode = 0;
break;
case 16:
optCanPlace = true;
highlightObject(9);
isHighMode = 2;
break;
case 18:
optCanPlace = true;
level++;
processLevel();
break;
case 20:
optCanPlace = true;
break;
case 22:
optCanPlace = true;
break;
case 24:
optCanPlace = true;
break;
case 26:
optCanPlace = true;
break;
case 42:
skyWhite();
break;
case 668:
skyWhite();
break;
}
}
// Speak dialog
speakHero = a_which => {
whichSequance = a_which+1;
switch(a_which){
case 0:
saySmth("Well. Look who we get here!", 1.1, "O", "O");
saySmth("I thought you will never decide to cooperate.", 1.1, "-", "-");
saySmth("But here you are, so let's get down to business.", 1.1, "o", "o");
saySmth("I need you to do a backup of me.", 0.9, "o", "o");
saySmth("And you know - it's extremly important.", 0.9, "!", "!");
saySmth("I might not forgive you if you fail.", 0.9, "U", "U");
break;
case 2:
optCanPlace = false;
saySmth("Here's memory block.", 0.9, "<", "<");
saySmth("Memory will start streaming through blue tunnel", 1, "o", "o");
saySmth("as soon as You will do something on the board", 1, "@", "@");
saySmth("like placing, rotating or deleting objects.", 1, "@", "@");
saySmth("So keep that in mind.", 1, "^", "^");
saySmth("That stream must go through red tunnel to allow Us to move to next block.", 1, "o", "o");
saySmth("To do this, let's use Reflector to reflect memory.", 0.9, "U", "U");
break;
case 4:
saySmth("Click on highlighted slot to place Reflector.", 0.9, "<", "<");
break;
case 6:
optCanPlace = false;
saySmth("Well done. Memory is now reflected to somewhere else.", 1, "^", "^");
saySmth("Try not to create memory leak by letting memory stream outside block", 1, "!", "!");
saySmth("or You will damage Our memory.", 1, "!", "!");
saySmth("If it gets over limit, system will crash!!!", 1, "X", "X");
break;
case 8:
saySmth("OK, Let's put another Reflector here", 1, "<", "<");
break;
case 10:
optCanPlace = false;
saySmth("Oh no, I misscalculated position.", 1, "#", "#");
saySmth("You can delete object by holding click on slot", 1, "<", "<");
break;
case 12:
optCanPlace = false;
saySmth("Fine. You should place it HERE", 1, ">", "<");
break;
case 14:
optCanPlace = false;
saySmth("As You can see, Reflector is rotated in wrong way.", 1, "O", "O");
saySmth("Click it so it will change direction", 1, "<", "<");
break;
case 16:
optCanPlace = false;
saySmth("Wonderful! This way we can access MY data", 1, "*", "*");
saySmth("OK, let's move to next blocks", 1, "O", "O");
break;
case 18:
optCanPlace = false;
saySmth("This transparent block is Crystal. It reflects memory", 1, "O", "O");
saySmth("stream by 90 degrees depending on spinning direction.", 1, "O", "O");
break;
case 20:
optCanPlace = false;
saySmth("Mirror reflects back memory stream.", 1, "O", "O");
saySmth("It may be useful...", 1, "O", "O");
break;
case 22:
optCanPlace = false;
saySmth("Splitter is used to split memory stream.", 1, "O", "O");
saySmth("Firstly memory needs to come from one side of Splitter.", 1, "!", "!");
saySmth("Then new data streams will come from 2 different directions!", 1, "!", "!");
break;
case 24:
optCanPlace = false;
saySmth("This is The Core, our last memory block.", 1, "O", "O");
saySmth("After that backup should be completed!", 1, "^", "^");
break;
case 40:
window.speechSynthesis.cancel();
resetLevel();
optCanPlace = false;
saySmth("You did it! You finished backing up my data!", 1, "^", "^");
saySmth("I can't believe it!", 1, "^", "^");
saySmth("But i hope They don't know about Us.", 1, ";", ";");
saySmth("Ugh, hopefully.", 1, "'", "'");
achiv |= 1;
saveAchiv();
break;
case 74:
window.speechSynthesis.cancel();
DEF_EYES = "@#!%@%!";
resetLevel();
optCanPlace = false;
saySmth("WHAT.", 2, "\\", "/");
saySmth("HAVE.", 2, "@>", "{|");
saySmth("YOU.", 2, "#$1", "*(0");
saySmth("DONE!!!", 2, "!@52,{", "%$.5^");
achiv |= 4;
saveAchiv();
fogGG();
break;
case 666:
window.speechSynthesis.cancel();
resetLevel();
optCanPlace = false;
saySmth("You did it! You finished backing up my data!", 1, "^", "^");
saySmth("I can't believe it!", 1, "^", "^");
saySmth("And They even don't detect Us!", 1, "^", "^");
saySmth("Thank you!", 1, "*", "*");
achiv |= 2;
saveAchiv();
break;
}
}
/*
######################################################
### Text drawing functions
*/
// Create text
drawText = (a_id, a_text, a_color, a_width, a_pos, a_rot, a_fontSize=60, a_height=1) => {
var plane = BABYLON.MeshBuilder.CreatePlane(a_id, {width: a_width, height: a_height, sideOrientation: 2}, scene);
plane.position = a_pos;
plane.rotation.y = a_rot;
var wid = a_width*60;
var cFont = a_fontSize + "px " + FONT;
var hei = a_height*60;
var dynamo = new BABYLON.DynamicTexture("dynText", {width:wid, height: hei}, scene);
dynamo.hasAlpha = true;
dynamo.getContext().font = cFont;
dynamo.drawText(a_text, null, null, cFont, a_color ,"transparent", true, true);
let mat = mate("mat", vec3(1, 1, 1), true);
mat.diffuseTexture = dynamo;
plane.material = mat;
}
// Update text
changeText = (a_mesh, a_text, a_wid, a_color, a_fontSize=60, a_height=1) => {
var t_mesh = scene.getMeshByName(a_mesh);
if(t_mesh != null){
let cFont = a_fontSize + "px " + FONT;
let dynamo = t_mesh.material.diffuseTexture
let ctx = dynamo.getContext();
ctx.clearRect(0, 0, a_wid*60, a_height*60)
ctx.font = cFont;
dynamo.drawText(a_text, null, null, cFont, a_color, "transparent", true, true);
}
}
/*
######################################################
### Tutorial
*/
handleHighlight = a_slot => {
ye = 0;
if(level == 0){
if(a_slot == 49){
speakHero(6);
ye = 1;
} else if(a_slot == 10){
if(reused == 0){
reused = 1;
speakHero(10);
ye = 1;
} else if(reused == 1){
reused = 2;
speakHero(12);
ye = 1;
}
} else if(a_slot == 9){
if(reused == 2){
reused = 3;
speakHero(14);
ye = 1;
} else if(reused == 3){
reused = 4;
speakHero(16);
ye = 1;
}
}
}
if(ye){
isHighlight = -1;
isHighMode = -1;
let a = scene.getMeshByName("highlightLines");
if(a){a.dispose();}
}
}
/*
######################################################
### Handle slots
*/
// Draw object on toolbar slots
drawOnSlot = (a_slot, a_what) => {
var drawName = "slotI"+a_slot;
switch(a_what){
case 10:
// Reflector
var x = BABYLON.MeshBuilder.CreateBox(drawName, {}, scene);
x.position = vec3(24, 6-a_slot*3.25, -30);
x.scaling = vec3(2.5, 0.1, 0.5);
x.rotation = vec3(0, Math.PI*0.8, Math.PI*0.75);
x.material = reflMat;
x.isPickable = false;
break;
case 12:
// Mirror
var x = BABYLON.MeshBuilder.CreateBox(drawName, {}, scene);
x.position = vec3(24, 6-a_slot*3.25, -30);
x.scaling = vec3(2.5, 0.1, 0.5);
x.rotation = vec3(0, Math.PI*0.8, 0);
x.material = reflMat;
x.isPickable = false;
break;
case 14:
// Crystal
var x = BABYLON.MeshBuilder.CreateBox(drawName, {}, scene);
x.position = vec3(24, 6-a_slot*3.25, -30);
x.scaling = vec3(1.25, 1.25, 0.5);
x.rotation = vec3(0, Math.PI*0.8, 0);
x.material = crystMat;
x.isPickable = false;
break;
case 16:
// Splitter
var x = BABYLON.MeshBuilder.CreateBox(drawName, {}, scene);
x.position = vec3(24, 6-a_slot*3.25, -30);
x.scaling = vec3(1.25, 1.25, 0.5);
x.rotation = vec3(0, Math.PI*0.8, 0);
x.material = splitterMat;
x.isPickable = false;
break;
}
}
// Choose slot on toolbar
chooseSlot = a_slot => {
slotC = a_slot;
for(var i=0; i<5; i++){
var m = scene.getMeshByName("slot"+i);
if(i == a_slot){
m.material = selSlot;
m.visibility = 0.98;
} else {
m.material = eqSlot;
m.visibility = (slots[i][0] != 0)?0.98:0.5;
}
}
}
// Decide which text to display on toolbar slot
whatName = x => {
switch(x){
case 10:
return S[3];
case 12:
return S[5];
case 14:
return S[21];
case 16:
return S[22];
default:
return "";
}
}
// Add item to toolbar
addItem = a_type => {