-
Notifications
You must be signed in to change notification settings - Fork 13
/
practice.html
1850 lines (1849 loc) · 113 KB
/
practice.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 name="viewport" content="width=device-width, initial-scale=1.0">
<title>FPS5 Multiplayer</title>
<style>
html, body {
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
/* cursor: default url(./cursors/cursor2.png), auto!important; */
overflow: hidden !important;
user-select: none !important;
transition: top .2s;
background: #eeeeee;
}
* {
cursor: url(./cursors/cursor1.png), auto !important;
}
.scoreboard {
position: absolute;
background: #444;
width: 75px;
height: 45px;
padding: 5px;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
z-index: 9999;
left: 100%;
margin-left: -80px;
top: 85vh;
font-size: 12px;
letter-spacing: 2px;
color: #25750a;
font-family: 'Courier New', Courier, monospace;
font-weight: 600;
box-shadow: 0 0 10px 4px #25750a;
}
hr {
outline-color: #25750a;
border-color: #25750a;
}
.ui #rounds {
position: absolute;
background: #444;
left: 90%;
top: 50px;
color: #25750a;
padding: 3px;
font-family: 'Courier New', Courier, monospace;
letter-spacing: -2px;
font-weight: 600;
box-shadow: 0 0 10px 4px #25750a;
border: 2px solid #333;
height: 80px;
}
.ui img:not(.statustext) {
position: absolute;
left: 0;
top: -10px;
margin: 0;
padding: 0;
}
.swal-overlay {
background: transparent !important;
pointer-events: none !important;
}
.swal-title {
font-size: 30px;
}
/* .crosshair {
position: absolute;
left: 50% !important;
top: 50% !important;
width: 25px;
margin-left: -12.5px !important;
margin-top: -12.5px !important;
z-index: 9999;
filter: invert(100%);
} */
.health {
position: relative;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background: #444;
}
.health-wrapper {
position: absolute;
width: 300px;
height: 35px;
left: 50%;
margin-left: -150px;
top: 50px;
border: 2px solid #333;
box-shadow: 0px 0px 10px 7px #25750a;
z-index: 99999;
}
body {
top: 0px;
}
.statustext {
position: absolute;
top: -10%;
left: 50%;
width: 50%;
margin-left: -25%;
display: none;
}
.ui .radar {
position: absolute;
left: 50px !important;
top: 70% !important;
}
#visor {
pointer-events: none !important;
}
canvas:first {
position: absolute;
width: 62.5vw;
height: 100vw;
left: 50% !important;
margin-left: -31.25vw !important;
}
.splitframe {
position: absolute;
height: 50%;
top: 50%;
margin: 0;
padding: 0;
border: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
z-index: 9999;
}
.splitframe0 {
position: absolute;
height: 50%;
top: 0;
margin: 0;
padding: 0;
border: 0;
left: 0;
right: 0;
width: 100%;
z-index: 9999;
}
#radar-obj {
position: absolute;
margin-top: -5%;
z-index: 9999;
background: #ff0000;
padding: 5px;
border-radius: 100%;
}
.crosshair {
position: absolute;
width: 10px;
height: 10px;
margin: 0;
padding: 0;
border-radius: 50%;
border: 2px solid #444;
background: transparent;
left: 50%;
top: 50%;
margin-left: -5px;
margin-top: -5px;
}
.swal-modal {
background: #444;
box-shadow: 0px 0px 10px 5px #ff4444;
}
.swal-modal * {
color: #ff4444;
}
.swal-button {
background: #ff4444 !important;
color: #333 !important;
box-shadow: none !important;
outline: none !important;
}
* {
white-space: nowrap;
}
.loader {
position: absolute;
width: 100vw;
height: 100vh;
margin: 0;
background-color: #444;
display: flex;
justify-content: center;
align-items: center;
align-content: center;
margin: 0 !important;
left: 0 !important;
top: 0 !important;
right: 0 !important;
bottom: 0 !important;
z-index: 999999;
/* background-image: url(./images/spartan.png); */
background-repeat: no-repeat;
background-position: 50px 45%;
background-size: 25vw;
}
.loader-1 {
width: 8vmax;
height: 8vmax;
border-right: 4px solid #25750a;
border-radius: 100%;
animation: spinRight 800ms linear infinite;
margin: 0;
margin-top: -100px;
}
.loader-1:before, .loader-1:after {
content: "";
width: 6vmax;
height: 6vmax;
display: block;
position: absolute;
left: calc(50% - 3vmax);
border-left: 3px solid #25750a;
border-radius: 100%;
animation: spinLeft 800ms linear infinite;
}
.loader-1:after {
width: 4vmax;
height: 4vmax;
top: calc(50% - 2vmax);
left: calc(50% - 2vmax);
border: 0;
border-right: 2px solid #25750a;
animation: none;
}
@keyframes spinLeft {
from {
transform: rotate(0deg);
}
to {
transform: rotate(720deg);
}
}
@keyframes spinRight {
from {
transform: rotate(360deg);
}
to {
transform: rotate(0deg);
}
}
.progress-bar {
position: absolute;
width: 100px;
height: 10px;
padding: 5px;
background: #333;
left: 50%;
margin-left: -50px;
}
#progress {
margin: 0;
width: 1%;
height: 100%;
background: #25750a;
}
#weapontext {
position: absolute;
left: 50%;
color: #333;
text-shadow: 0 2px #ff4444;
font-size: 20px;
font-weight: 600;
font-family: monospace, Arial;
z-index: 9999;
bottom: 50px;
width: 1000px;
margin-left: -500px;
text-align: center;
}
a:active {
border: 2px solid currentColor;
border-radius: 2px;
}
.pause-menu {
position: absolute;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: #333;
background: rgba(15,15,15,.5);
z-index: 9999;
}
.pause-tab {
position: relative;
top: 200px;
left: 0;
margin: 0;
margin-bottom: 30px;
background: #444;
display: inline-block;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
padding: 5px;
width: 250px;
color: #333;
text-shadow: 0 2px #25750a;
text-align: center;
box-shadow: 0 3px 5px #25750a;
}
</style>
<script src="https://cdn.jsdelivr.net/gh/Parking-Master/Gametime.js-2.0@latest/gametime.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/gh/Parking-Master/Gametime.js@latest/js/username-generator.min.js"></script> -->
</head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-2ZQ6TMGVXJ"></script>
<script>
window.dataLayer=window.dataLayer||[];
function gtag(){dataLayer.push(arguments);}
gtag("js", new Date());
gtag("config", "G-2ZQ6TMGVXJ");
</script>
<body style="margin:0!important;">
<div class="loader">
<div class="loader-1"></div>
<br>
<h2 style="font-size:20px;text-align:center;position:absolute;margin-top:100px;color:#25750a">LOADING<br><div class="progress-bar"><div id="progress"></div></div></h2>
</div>
<div class="pause-menu" style="display:none">
<h1 style="color:#25750a;font-weight:bold;font-family:monospace;position:absolute;left:20px;top:20px;font-size:75px;margin:0">PAUSED</h1>
<div class="pause-tab" onclick="unpause()">Continue</div><br>
<div class="pause-tab" onclick="confirm('Are you sure? All player will be disconnected.')&&cancelSearch()">Leave game</div><br>
<div class="pause-tab" onclick="openSettings()">Settings</div><br>
</div>
<!-- <audio id="explosion" src="sounds/explosion.mp3" volume="1" current-time=".1"></audio> -->
<audio id="grenade_explosion" src="sounds/grenade_explosion.mp3" volume="1" current-time=".1"></audio>
<audio id="death1" src="sounds/death1.mp3" volume="1" current-time="0"></audio>
<audio id="death2" src="sounds/death2.mp3" volume="1" current-time="0"></audio>
<audio id="death3" src="sounds/death3.mp3" volume="1" current-time="0"></audio>
<audio id="death4" src="sounds/death4.mp3" volume="1" current-time="0"></audio>
<!-- <audio id="death5" src="sounds/death5.mp3" volume="1" current-time="0"></audio> -->
<!-- <audio id="death6" src="sounds/death6.mp3" volume="1" current-time="0"></audio> -->
<audio id="ricochet1" src="sounds/ricochet1.mp3" volume=".4" current-time="0"></audio>
<audio id="ricochet2" src="sounds/ricochet2.mp3" volume=".4" current-time="0"></audio>
<audio id="ricochet3" src="sounds/ricochet3.mp3" volume=".4" current-time="0"></audio>
<audio id="walking" src="sounds/walking.mp3" loop volume=".5"></audio>
<audio id="ambience" src="sounds/ambience.mp3" autoplay loop volume="1"></audio>
<audio id="gunsound-burst" src="sounds/guns/default_rifle.mp3"></audio>
<audio id="gunsound-pistol" src="sounds/guns/colt_m1911.mp3"></audio>
<audio id="gunsound-assault" src="sounds/guns/ar-15.mp3"></audio>
<audio id="gunsound-sniper" src="sounds/guns/hk-g28.mp3"></audio>
<audio id="gunsound-rocket" src="sounds/guns/spnkr.mp3"></audio>
<audio id="countdown" src="sounds/countdown.mp3"></audio>
<audio id="game-over" src="sounds/game_over.mp3"></audio>
<audio id="time-warning" src="sounds/timewarning.mp3"></audio>
<audio id="warthog-sound" src="sounds/warthog.mp3" loop></audio>
<audio id="punch" src="sounds/punch.mp3"></audio>
<audio id="slayer" src="sounds/slayer.mp3"></audio>
<audio id="click" src="sounds/click.mp3"></audio>
<script src="https://parking-master.github.io/FPS3/js/three.min.js"></script>
<!-- <script src="https://threejs.org/examples/js/loaders/OBJLoader.js"></script> -->
<script src="https://threejs.org/examples/js/loaders/GLTFLoader.js"></script>
<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js/examples/js/libs/fflate.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/alvaromontoro/gamecontroller.js@latest/dist/gamecontroller.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/Parking-Master/Gametime.js-2.0@latest/gametime.js"></script>
<audio id="gunsound-pistol" src="sounds/guns/colt_m1911.mp3"></audio>
<audio id="gunsound-rifle" src="sounds/guns/default_rifle.mp3"></audio>
<audio id="gunsound-uzi" src="sounds/guns/uzi.mp3"></audio>
<audio id="gunsound-shotgun" src="sounds/guns/shotgun.mp3"></audio>
<audio id="gunsound-rocket" src="sounds/guns/rocket.mp3"></audio>
<audio id="reload-pistol-easy" src="sounds/reloads/pistol/easy-reload.mp3"></audio>
<audio id="reload-pistol-full" src="sounds/reloads/pistol/full-reload.mp3"></audio>
<audio id="reload-rifle-easy" src="sounds/reloads/rifle/easy-reload.mp3"></audio>
<audio id="reload-rifle-full" src="sounds/reloads/rifle/full-reload.mp3"></audio>
<audio id="reload-sniper-easy" src="sounds/reloads/sniper/easy-reload.mp3"></audio>
<audio id="reload-sniper-full" src="sounds/reloads/sniper/full-reload.mp3"></audio>
<audio id="reload-assault-easy" src="sounds/reloads/assault/easy-reload.mp3"></audio>
<audio id="reload-assault-full" src="sounds/reloads/assault/full-reload.mp3"></audio>
<audio id="reload-uzi-easy" src="sounds/reloads/uzi/easy-reload.mp3"></audio>
<audio id="reload-uzi-full" src="sounds/reloads/uzi/full-reload.mp3"></audio>
<audio id="reload-shotgun-easy" src="sounds/reloads/shotgun/easy-reload.mp3"></audio>
<audio id="reload-shotgun-full" src="sounds/reloads/shotgun/full-reload.mp3"></audio>
<audio id="reload-rocket-easy" src="sounds/reloads/rocket/easy-reload.mp3"></audio>
<audio id="reload-rocket-full" src="sounds/reloads/rocket/full-reload.mp3"></audio>
<!-- <script src="https://unpkg.com/[email protected]/dist/cannon-es.js"></script> -->
<script>
Gamepad.Context={},Gamepad.Trigger={},Gamepad.Panel={},Gamepad.Item={},Gamepad.JoyStick={},Gamepad.JoyStick.R={},Gamepad.JoyStick.L={},Gamepad.D={},Gamepad.Context.AButtonPressed=function(){},Gamepad.onConnect=function(){},Gamepad.Context.BButtonPressed=function(){},Gamepad.Context.XButtonPressed=function(){},Gamepad.Context.YButtonPressed=function(){},Gamepad.Trigger.LeftButtonPressed=function(){},Gamepad.Trigger.RightButtonPressed=function(){},Gamepad.Panel.LeftButtonPressed=function(){},Gamepad.Panel.RightButtonPressed=function(){},Gamepad.Item.NavButtonPressed=function(){},Gamepad.Item.PauseButtonPressed=function(){},Gamepad.JoyStick.L.Pressed=function(){},Gamepad.JoyStick.R.Pressed=function(){},Gamepad.JoyStick.UpMoved=function(){},Gamepad.JoyStick.DownMoved=function(){},Gamepad.JoyStick.RightMoved=function(){},Gamepad.JoyStick.LeftMoved=function(){},Gamepad.JoyStick.UpCanceled=function(){},Gamepad.JoyStick.DownCanceled=function(){},Gamepad.JoyStick.RightCanceled=function(){},Gamepad.JoyStick.LeftCanceled=function(){},Gamepad.D.UpButtonPressed=function(){},Gamepad.D.DownButtonPressed=function(){},Gamepad.D.LeftButtonPressed=function(){},Gamepad.D.RightButtonPressed=function(){},gameControl.on("connect",(function(e){Gamepad.onConnect();for(let t=0;t<Math.min(17,e.buttons);t++)e.on("button"+t,(function(){0==t?Gamepad.Context.AButtonPressed():1==t?Gamepad.Context.BButtonPressed():2==t?Gamepad.Context.XButtonPressed():3==t?Gamepad.Context.YButtonPressed():4==t?Gamepad.Trigger.LeftButtonPressed():5==t?Gamepad.Trigger.RightButtonPressed():6==t?Gamepad.Panel.LeftButtonPressed():7==t?Gamepad.Panel.RightButtonPressed():8==t?Gamepad.Item.NavButtonPressed():9==t?Gamepad.Item.PauseButtonPressed():10==t?Gamepad.JoyStick.L.Pressed():11==t?Gamepad.JoyStick.R.Pressed():12==t?Gamepad.D.UpButtonPressed():13==t?Gamepad.D.DownButtonPressed():14==t?Gamepad.D.LeftButtonPressed():15==t&&Gamepad.D.RightButtonPressed()})).before("button"+t,()=>{}).after("button"+t,()=>{});for(let t=0;t<Math.min(2,e.axes);t++){const n=["up","down","right","left"];for(let a=0;a<n.length;a++)e.on(n[a]+t,(function(){"up"==n[a]?Gamepad.JoyStick.UpMoved():"right"==n[a]?Gamepad.JoyStick.RightMoved():"left"==n[a]?Gamepad.JoyStick.LeftMoved():"down"==n[a]&&Gamepad.JoyStick.DownMoved()})).after(n[a],()=>{n[a]=="up"?Gamepad.JoyStick.UpCanceled():n[a]=="down"?Gamepad.JoyStick.DownCanceled():n[a]=="left"?Gamepad.JoyStick.LeftCanceled():n[a]=="right"?Gamepad.JoyStick.RightCanceled():void(0)})}})).on("beforeCycle",(function(){}));
</script>
<div id="container"></div>
<div class="ui" style="opacity:0">
<div class="scoreboard">
<span class="player1">A - <span class="score">0</span></span>
<hr style="margin:0">
<span class="player2">B - <span class="score">0</span></span>
<hr style="margin:0">
<div id="time"><span id="minutes">0</span>:<span id="seconds">00</span></div>
</div>
<div class="health-wrapper">
<div class="health"></div>
</div>
<span id="visor"><img src="images/textures/visor.png" style="height:105vh;width:100vw" />
<div class="crosshair"></div>
<img class="radar" src="images/radar.png" width="10%" />
<img id="scope" src="images/scope.png" width="100%" height="100%" style="position:absolute;visibility:hidden;margin:0;padding:0;left:0;top:0;right:0;bottom:0;z-index:9999" />
<img id="scope1" src="images/scope1.png" width="100%" height="100%" style="position:absolute;visibility:hidden;margin:0;padding:0;left:0;top:0;right:0;bottom:0;z-index:9999" />
<!-- <div id="radar-obj"></div> -->
<span id="rounds"><img src="images/guns/rifle.png" width="100%" style="margin-top:10px" /><br style="margin-top:25px"><span id="counter">36</span> − <span id="magcount">3</span> − <span id="grenadecount">2</span></span>
<img id="hiteffect" src="images/hit.png" width="100%" height="100%" style="margin:0;padding:0;opacity:0;width:100vw;height:100vw" />
</div>
<p id="weapontext" style="display:none">Hold [T] to pick up <span class="weapon-name"></span></p>
<!-- <script type="module">
import * as CANNON from 'https://unpkg.com/[email protected]/dist/cannon-es.js';
window.CANNON = CANNON;
</script> -->
<!-- <script src="https://cdn.jsdelivr.net/gh/Parking-Master/FPS@master/gametime-socket.js"></script> -->
<script>
defaultKeys = "f,b,r, ,t,m,y,i,z,p";
keyControls = {
"shoot": (localStorage["prefsKeyControls"] || defaultKeys).split(",")[0],
"punch": (localStorage["prefsKeyControls"] || defaultKeys).split(",")[1],
"reload": (localStorage["prefsKeyControls"] || defaultKeys).split(",")[2],
"jump": (localStorage["prefsKeyControls"] || defaultKeys).split(",")[3],
"interact": (localStorage["prefsKeyControls"] || defaultKeys).split(",")[4],
"throwGrenade": (localStorage["prefsKeyControls"] || defaultKeys).split(",")[5],
"switchWeapon": (localStorage["prefsKeyControls"] || defaultKeys).split(",")[6],
"zoomIn": (localStorage["prefsKeyControls"] || defaultKeys).split(",")[7],
"zoomOut": (localStorage["prefsKeyControls"] || defaultKeys).split(",")[8],
"pause": (localStorage["prefsKeyControls"] || defaultKeys).split(",")[9]
};
function showText(e) {
document.querySelector("#weapontext").textContent = e;
document.querySelector("#weapontext").style.display = "block";
}
function hideText() {
document.querySelector("#weapontext").textContent = "";
document.querySelector("#weapontext").style.display = "none";
}
function checkTouching(e,t){let o=e.position.y-e.geometry.parameters.height/2,r=e.position.y+e.geometry.parameters.height/2,i=e.position.x+e.geometry.parameters.width/2,p=e.position.x-e.geometry.parameters.width/2,a=e.position.z-e.geometry.parameters.depth/2,m=e.position.z+e.geometry.parameters.depth/2,s=t.position.y-t.geometry.parameters.height/2,h=t.position.y+t.geometry.parameters.height/2,g=t.position.x+t.geometry.parameters.width/2,n=t.position.x-t.geometry.parameters.width/2,y=t.position.z-t.geometry.parameters.depth/2,d=t.position.z+t.geometry.parameters.depth/2;return!(r<s||i<n||o>h||p>g||a>d||m<y)}
connectedUsers = 0;
score1 = 0;
score2 = 0;
setScore = 10;
setTime = 10;
setGrenades = 2;
primaryRounds = 36;
secondaryRounds = 10;
gunMeleeRotationY = 0;
fullAutoFiring = false;
currentPerformance = (localStorage["performance"] || "100") - 0;
// currentPerformance > 90 ? window.devicePixelRatio = 2 : (currentPerformance > 60 ? window.devicePixelRatio = 1 : (currentPerformance > 20 ? window.devicePixelRatio = .5 : void(0)));
currentMap = (new URLSearchParams(location.search).get("map") || "cargo").toUpperCase();
setInterval(() => {
if (fullAutoFiring && currentWeapon == "assault") {
fire(1, 5);
}
}, 80);
setInterval(() => {
if (fullAutoFiring && currentWeapon == "uzi") {
fire(1, 3);
}
}, 50);
currentWeaponPosition = "primary";
gunsounds = {
pistol: document.getElementById("gunsound-pistol"),
sniper: document.getElementById("gunsound-sniper"),
rifle: document.getElementById("gunsound-rifle"),
assault: document.getElementById("gunsound-assault"),
uzi: document.getElementById("gunsound-uzi"),
shotgun: document.getElementById("gunsound-shotgun"),
rocket: document.getElementById("gunsound-rocket")
};
reloadsounds = {
easy: {
pistol: document.getElementById("reload-pistol-easy"),
rifle: document.getElementById("reload-rifle-easy"),
sniper: document.getElementById("reload-sniper-easy"),
assault: document.getElementById("reload-assault-easy"),
uzi: document.getElementById("reload-uzi-easy"),
shotgun: document.getElementById("reload-shotgun-easy"),
rocket: document.getElementById("reload-rocket-easy")
},
full: {
pistol: document.getElementById("reload-pistol-full"),
rifle: document.getElementById("reload-rifle-full"),
sniper: document.getElementById("reload-sniper-full"),
assault: document.getElementById("reload-assault-full"),
uzi: document.getElementById("reload-uzi-full"),
shotgun: document.getElementById("reload-shotgun-full"),
rocket: document.getElementById("reload-rocket-full")
}
};
healthUpgradeTimeout = 1;
animated = false;
const scene = new THREE.Scene();
const camera=new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,.1,1e3),renderer=new THREE.WebGLRenderer(currentPerformance<30?{antialias:false,powerPreference:"high-performance"}:{antialias:true});renderer.setSize(window.innerWidth,window.innerHeight),document.body.appendChild(renderer.domElement),renderer.setPixelRatio(window.devicePixelRatio-(currentPerformance<25?(1.2):(currentPerformance<50?1:.5)));
function isTouchDevice(){return!!window.matchMedia("(pointer: coarse)").matches}
isTouchDevice()?(()=>{const{Euler:e,EventDispatcher:t,Vector3:n}=THREE;var o;o=!1;var i=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent),c=document.body.clientWidth/2,r=(document.body.clientHeight,window.innerHeight),s=function(t,s){o=!!i,void 0===s&&(console.warn('THREE.PointerLockControls: The second parameter "domElement" is now mandatory.'),s=document.body),this.domElement=s,this.isLocked=!1;var m,u,d,a=this,h={type:"change"},v={type:"lock"},l={type:"unlock"},E=new e(0,0,0,"YXZ"),p=Math.PI/2,k=Math.PI/3.8,L=Math.PI/9,f=new n,y=0,M=0;function x(){}function P(e){u=e.touches[0].clientY,m=e.touches[0].clientX,y=m-c,M=u-(r-100),E.setFromQuaternion(t.quaternion),E.y=.005*y,E.x=.005*M,E.x=Math.max(-p,Math.min(L,E.x)),E.y=Math.max(-k,Math.min(k,E.y)),t.quaternion.setFromEuler(E),a.dispatchEvent(h),console.log(M)}function w(e){}function g(e){if(!1!==a.isLocked){var n=e.movementX||e.mozMovementX||e.webkitMovementX||0,o=e.movementY||e.mozMovementY||e.webkitMovementY||0;E.setFromQuaternion(t.quaternion),E.y-=.002*n,E.x-=.002*o,E.x=Math.max(-p,Math.min(p,E.x)),E.y=Math.max(-k,Math.min(k,E.y)),t.quaternion.setFromEuler(E),a.dispatchEvent(h)}}function b(){document.pointerLockElement===a.domElement?(a.dispatchEvent(v),a.isLocked=!0):(a.dispatchEvent(l),a.isLocked=!1)}function F(){console.error("THREE.PointerLockControls: Unable to use Pointer Lock API")}this.connect=function(){document.addEventListener("mousemove",g,!1),document.addEventListener("touchstart",x,!1),document.addEventListener("touchmove",P,!1),document.addEventListener("pointerlockchange",b,!1),document.addEventListener("pointerlockerror",F,!1)},this.disconnect=function(){document.removeEventListener("mousemove",g,!1),document.removeEventListener("touchend",w,!1),document.removeEventListener("touchmove",onTouchmove,!1),document.removeEventListener("pointerlockchange",b,!1),document.removeEventListener("pointerlockerror",F,!1)},this.dispose=function(){this.disconnect()},this.getObject=function(){return t},this.getDirection=(d=new n(0,0,-1),function(e){return e.copy(d).applyQuaternion(t.quaternion)}),this.moveForward=function(e){f.setFromMatrixColumn(t.matrix,0),f.crossVectors(t.up,f),t.position.addScaledVector(f,e)},this.moveRight=function(e){f.setFromMatrixColumn(t.matrix,0),t.position.addScaledVector(f,e)},this.lock=1==o?function(){a.isLocked=!0,this.connect()}:function(){this.domElement.requestPointerLock()},this.unlock=function(){document.exitPointerLock()},this.connect()};(s.prototype=Object.create(t.prototype)).constructor=s,window.PointerLockControls=s})():(()=>{const _euler=new THREE.Euler(0,0,0,"YXZ"),_vector=new THREE.Vector3,_changeEvent={type:"change"},_lockEvent={type:"lock"},_unlockEvent={type:"unlock"},_PI_2=Math.PI/2;class PointerLockControls extends THREE.EventDispatcher{constructor(e,t){super(),void 0===t&&(console.warn('THREE.PointerLockControls: The second parameter "domElement" is now mandatory.'),t=document.body),this.domElement=t,this.isLocked=!1,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.pointerSpeed=1;const o=this;function n(t){if(!1===o.isLocked)return;const n=t.movementX||t.mozMovementX||t.webkitMovementX||0,r=t.movementY||t.mozMovementY||t.webkitMovementY||0;_euler.setFromQuaternion(e.quaternion),_euler.y-=.002*n*o.pointerSpeed,_euler.x-=.002*r*o.pointerSpeed,_euler.x=Math.max(_PI_2-o.maxPolarAngle,Math.min(_PI_2-o.minPolarAngle,_euler.x)),e.quaternion.setFromEuler(_euler),o.dispatchEvent(_changeEvent)}function r(){o.domElement.ownerDocument.pointerLockElement===o.domElement?(o.dispatchEvent(_lockEvent),o.isLocked=!0):(o.dispatchEvent(_unlockEvent),o.isLocked=!1)}function c(){console.error("THREE.PointerLockControls: Unable to use Pointer Lock API")}this.connect=function(){o.domElement.ownerDocument.addEventListener("mousemove",n),o.domElement.ownerDocument.addEventListener("pointerlockchange",r),o.domElement.ownerDocument.addEventListener("pointerlockerror",c)},this.disconnect=function(){o.domElement.ownerDocument.removeEventListener("mousemove",n),o.domElement.ownerDocument.removeEventListener("pointerlockchange",r),o.domElement.ownerDocument.removeEventListener("pointerlockerror",c)},this.dispose=function(){this.disconnect()},this.getObject=function(){return e},this.getDirection=function(){const t=new THREE.Vector3(0,0,-1);return function(o){return o.copy(t).applyQuaternion(e.quaternion)}}(),this.moveForward=function(t){_vector.setFromMatrixColumn(e.matrix,0),_vector.crossVectors(e.up,_vector),e.position.addScaledVector(_vector,t)},this.moveRight=function(t){_vector.setFromMatrixColumn(e.matrix,0),e.position.addScaledVector(_vector,t)},this.lock=function(){this.domElement.requestPointerLock()},this.unlock=function(){o.domElement.ownerDocument.exitPointerLock()},this.connect()}}window.PointerLockControls=PointerLockControls})();
scene.add(camera);
map = new THREE.Mesh();
light=new THREE.PointLight(0xf7f7ea,2),light.position.set(-10,20,-10),scene.add(light);
light1=new THREE.SpotLight(15196368,1),light1.position.set(-10,50,-50),light1.castShadow=!0,scene.add(light1);
follower = new THREE.Mesh(new THREE.BoxGeometry(.5,1,.5));
gun = new THREE.Mesh();
clock = new THREE.Clock();
myPlayer = new THREE.Mesh();
otherPlayer = new THREE.Mesh();
otherLooker = new THREE.Mesh();
looker = new THREE.Mesh();
melee = false;
gunAnimations = [];
shotsLeft = 10;
primaryMagsLeft = 3 + 1;
secondaryMagsLeft = 4 + 1;
gunLocked = true;
isZoomed = false;
walkAxisYLocked = true;
defaultY = .35;
health = 100;
respawnPoints = [
[0, 0, 8],
currentMap == "CARGO" ? [5, .35, 37] : [0, -1, 46]
];
textures = {
"spark": (new THREE.TextureLoader).load("images/textures/spark.png"),
"smoke": (new THREE.TextureLoader).load("images/textures/smoke.png"),
"flame": (new THREE.TextureLoader).load("images/textures/flame.png"),
"hole": (new THREE.TextureLoader).load("images/textures/bullethole.png"),
"scratch": (new THREE.TextureLoader).load("images/textures/scratch.png")
};
ordinances = [];
altNames = {
"rifle": "Concept 35R",
"pistol": "9mm G17",
"sniper": "HK-G28",
"assault": "M16 A2",
"uzi": "UZI",
"shotgun": "Remington 870",
"rocket": "SPNKR Rocket Launcher"
};
otherPlayerFollower = new THREE.Mesh(new THREE.BoxGeometry(.45,1.5,.4));
scene.add(otherPlayerFollower);
otherPlayerFollower.visible = false;
isJumping = false;
otherSelectedCharacter = "mark-vi";
lockIntersection = false;
function respawn(position) {
let x = position[0];
let y = position[1];
let z = position[2];
camera.rotation.set(0, 0, 0);
camera.position.set(x, y, z);
swal.close();
health = 100;
document.querySelector(".health").style.width = "100%";
document.querySelector("#hiteffect").style.opacity = "0";
document.querySelector(".health-wrapper").style.boxShadow = "0px 0px 10px 7px #25750a";
shotsLeft = 10;
primaryRounds = 36;
secondaryRounds = 10;
primaryRoundsDefault = 36;
secondaryRoundsDefault = 10;
if (currentMode == "fiesta") {
fixedLoadout[0]=weaponDefs[Math.floor(Math.random()*weaponDefs.length)];
fixedLoadout[1]=weaponDefs[Math.floor(Math.random()*weaponDefs.length)];
} else if (currentMode == "snipers") {
fixedLoadout[0]="sniper";
fixedLoadout[1]="sniper";
} else if (currentMode == "rocknrail") {
fixedLoadout[0]="rocket";
fixedLoadout[1]="railgun";
} else if (currentMode == "slayer") {
fixedLoadout = (localStorage["prefsLoadout"] || "rifle,pistol").split(",");
}
magsLeft = 3;
primaryMagsLeft = 3;
secondaryMagsLeft = 4;
grenadesLeft = setGrenades;
primaryGun = weapons[fixedLoadout[0]].scene;
secondGun = weapons[fixedLoadout[1]].scene;
currentWeaponPosition = "primary";
loadout = fixedLoadout;
currentWeapon = fixedLoadout[0];
for(let i=0;i<2;i++){gametime.run("endPlayerWalk",[camera.position.x+","+camera.position.y+","+camera.position.z+","+camera.rotation.x+","+camera.rotation.y+","+camera.rotation.z+","+gametime.user.position])}
controls.isLocked = true;
walkAxisYLocked = true;
scene.add(gun);
scene.add(myPlayer);
document.querySelector(".ui").style.visibility = "visible";
for (let i = 0; i < 2; i++) {
document.dispatchEvent(new KeyboardEvent("keydown",{key:"y"}));
}
}
function error(code) {
if (code == 404) { alert("Error: This lobby does not exist. You will return to the menu"); location.replace("/") }
}
function startCountdown(time) {
let seconds = 0;
let minutes = time;
let n = setInterval(() => {
if (seconds <= 0 && minutes <= 0) {
if (score1 > score2) {
score1 = setScore;
} else if (score2 > score1) {
score2 = setScore;
}
return GameOver(), clearInterval(n);
}
seconds <= 0 ? (minutes--, seconds = 59, document.querySelector("#time").querySelector("#seconds").textContent = (seconds<10?"0"+seconds.toString():seconds.toString())) : (seconds--, document.querySelector("#time").querySelector("#seconds").textContent = (seconds<10?"0"+seconds.toString():seconds.toString()));
document.querySelector("#time").querySelector("#minutes").textContent = minutes;
minutes == 5 && seconds <= 0 && document.querySelector("#time-warning").play();
}, 950);
}
function GameOver() {
if (score1 >= setScore || score2 >= setScore) {
document.querySelector("#game-over").play();
if (score1 >= setScore && gametime.user.position == 1 || score2 >= setScore && gametime.user.position == 2) {
swal({
title: "Game over",
text: "You win!",
closeOnEsc: false,
closeOnEnterKey: false,
closeOnSpaceKey: false,
closeOnClickOutside: false
}).then(() => {
location.replace("/");
});
} else {
swal({
title: "Game over",
text: "You lose...",
closeOnEsc: false,
closeOnEnterKey: false,
closeOnSpaceKey: false,
closeOnClickOutside: false
}).then(() => {
location.replace("/");
});
}
return true;
}
return false;
}
primaryRoundsDefault = primaryRounds;
secondaryRoundsDefault = secondaryRounds;
function throwGrenade(){let b=0;"undefined"==typeof grenade||grenadesLeft<=0||!canThrowGrenade||(canThrowGrenade=!1,grenadesLeft--,grenade.position.copy(camera.position),grenade.rotation.copy(camera.rotation),grenade.scale.set(.2,.2,.2),"CARGO"==currentMap&&(()=>{let e,a=grenade.clone();scene.add(a),a.updateMatrix(),a.translateZ(-.5);let t=setInterval((()=>{map.traverse((n=>{collision(a,n)&&n instanceof THREE.Mesh&&n!=gun&&n!=a&&n instanceof THREE.Mesh&&(()=>{let g=document.querySelector("#ricochet"+(Math.floor(Math.random()*3)+1)).cloneNode();let u=(1-(distanceTo(a.position,camera.position)/5));((u<=0&&(u=0)),(u>=1&&(u=1)));g.volume=u;g.play();return true})()&&((n.name.includes("Container")||n.name.includes("Warthog"))&&console.log(n),e=n,(()=>{let e=.1,t=setInterval((()=>{map.traverse((e=>{collision(a,e)&&e instanceof THREE.Mesh&&e!=gun&&e!=a&&e instanceof THREE.Mesh&&(()=>{let g=document.querySelector("#ricochet"+(Math.floor(Math.random()*3)+1)).cloneNode();let u=(1-(distanceTo(a.position,camera.position)/5));((u<=0&&(u=0)),(u>=1&&(u=1)));g.volume=u;g.play();return true})()&&(console.log(e),(()=>{let e=.1,t=setInterval((()=>{map.traverse((e=>{collision(a,e)&&e instanceof THREE.Mesh&&e!=gun&&e!=a&&e instanceof THREE.Mesh&&(()=>{let g=document.querySelector("#ricochet"+(Math.floor(Math.random()*3)+1)).cloneNode();let u=(1-(distanceTo(a.position,camera.position)/5));((u<=0&&(u=0)),(u>=1&&(u=1)));g.volume=u;g.play();return true})()&&clearInterval(t)})),e+=-.001,a.translateY(e)}))})(),clearInterval(t))})),e+=-.001,a.translateY(e)}))})(),setTimeout((()=>{let e=new THREE.Mesh(new THREE.CircleGeometry(2,30),new THREE.MeshBasicMaterial({color:16777215,map:(new THREE.TextureLoader).load("images/textures/explosion.png"),transparent:!0}));let g=document.querySelector("#grenade_explosion").cloneNode();let u=(1-(distanceTo(a.position,camera.position)/5))+.2;((u<=0&&(u=.2)),(u>=1&&(u=1)));g.volume=u;g.play();scene.remove(a),e.position.copy(a.position),e.rotation.copy(a.rotation),a.updateMatrix(),e.translateY(2),(()=>{let e=new THREE.Mesh(new THREE.CircleGeometry(4,30),new THREE.MeshBasicMaterial({map:textures["smoke"],transparent:!0}));e.position.copy(a.position),e.rotation.copy(a.rotation),e.updateMatrix(),e.lookAt(camera.position),e.translateY(1);let t=setInterval((()=>{e.translateY(.0025),e.material.opacity<0||(e.material.opacity+=-.0025)}));setTimeout((()=>clearInterval(t)),10000)})(),e.lookAt(camera.position),scene.add(e);let t=setInterval((()=>{distanceTo(camera.position,e.position)<=4?(gametime.run("eleminate",[gametime.user.position]),document.querySelector("#hiteffect").style.opacity=1,setTimeout(()=>{document.querySelector("#hiteffect").style.opacity=0},1000)):(distanceTo(otherPlayer.position,e.position)<=4&&gametime.run("eleminate",[1==gametime.user.position?2:1])),e.material.opacity<=0?(clearInterval(t),scene.remove(e)):(e.scale.set(e.scale.x+.3,e.scale.y+.3,e.scale.z+.3),e.material.opacity+=-.05)}))}),2e3),clearInterval(t))})),b+=.001,a.translateZ(-.1),a.position.y+=(-b)}))})(),setTimeout((()=>{canThrowGrenade=!0}),750))}grenadesLeft=setGrenades,canThrowGrenade=!0;(new THREE.GLTFLoader).load("models/weapons/grenades/frag.glb",(e)=>{grenade=e.scene});
/* Gametime.js event variables */
gametime.set("key", "pub-c-c44c8fc4-612e-4fc3-b875-4398f01da63c", "sub-c-b6832794-3c08-11ec-b2c1-a25c7fcd9558");
gametime.set("channel", "practice-lobby-"+(Math.random()*Math.random()*Math.random())+"_offline");
gametime.make("leftGame");
gametime.make("playerWalk");
gametime.make("moveWarthog");
gametime.make("endPlayerWalk");
gametime.make("playerRotate");
gametime.make("hit");
gametime.make("eleminate");
gametime.make("respawn");
gametime.make("selectCharacter");
gametime.make("playerJump");
gametime.make("pickupWeapon");
gametime.make("shot");
gametime.make("connect");
gametime.make("syncCountdown");
countdown = false;
gametime.on("moveWarthog", function(data) {
let player = data.split(",")[0];
let warthog = data.split(",")[1];
let posx = data.split(",")[2];
let posy = data.split(",")[3];
let posz = data.split(",")[4];
let rotx = data.split(",")[5];
let roty = data.split(",")[6];
let rotz = data.split(",")[7];
if (player == gametime.user.position) {
return;
}
warthogs[warthog].position.set(posx, posy, posz);
warthogs[warthog].rotation.set(rotx, roty, rotz);
otherPlayer.position.y = 1000000;
});
gametime.on("leftGame", function() {
swal({
icon: "error",
title: "Warning",
text: "One or more players have left the game session.\nYou will return to the main menu.",
button: "Return"
}).then(() => { gametime.disconnect(), location.assign("/") });
});
window.addEventListener("beforeunload", () => {
gametime.run("leftGame");
});
gametime.on("pickupWeapon", function(e) {
ordinances[e].position.y=10000;
scene.remove(ordinances[e]);
});
gametime.on("syncCountdown", function(d) {
d != gametime.user.position && (countdown = true);
});
gametime.on("shot", function(data) {
let player = data.split(",")[4];
let wpn = data.split(",")[0];
let epos = {x:data.split(",")[1]-0,y:data.split(",")[2]-0,z:data.split(",")[3]-0};
if (player == gametime.user.position) {
return;
}
document.body.appendChild(gunsounds[wpn].cloneNode()).play();
(()=>{let e=new THREE.Mesh(new THREE.CircleGeometry(.05,20),new THREE.MeshBasicMaterial({map:textures["hole"],transparent:true}));e.position.set(epos.x,epos.y,epos.z),e.updateMatrix(),e.lookAt(camera.position),scene.add(e),setTimeout(()=>scene.remove(e),100)})();
(new THREE.GLTFLoader).load("models/muzzle_flash.glb",(e)=>{e=e.scene;e.position.copy(otherPlayer.position),e.scale.set(.6,.6,.6),e.rotation.copy(otherPlayer.rotation),e.updateMatrix(),e.translateY(1.3),e.translateZ(-1),e.rotateY(.6),scene.add(e),setTimeout(()=>scene.remove(e),50)});
otherPlayer.getObjectByName("WeaponConceptACE35Rglb").rotation.x+=.04;
otherPlayer.getObjectByName("clavicle_r_039").rotation.y+=.1;
setTimeout(() => {
otherPlayer.getObjectByName("WeaponConceptACE35Rglb").rotation.x+=-.04;
otherPlayer.getObjectByName("clavicle_r_039").rotation.y+=-.1;
}, 50);
});
gametime.on("connect", function() {
connectedUsers++;
});
gametime.on("respawn", function(data) {
let player = data.split(",")[0];
if (player == gametime.user.position) {
return;
}
let x = data.split(",")[1];
let y = data.split(",")[2];
let z = data.split(",")[3];
otherPlayer.rotation.set(0, 0, 0);
otherPlayer.position.set(x, y, z);
scene.add(otherPlayer);
});
let r = false;
let hasDied = false;
gametime.on("eleminate", function(player) {
if (hasDied) {
return;
}
setTimeout(() => { r = false }, 1000);
hasDied = true;
setTimeout(() => { hasDied = false }, 5000);
document.querySelector("#death3").play();
if (player != gametime.user.position) {
GameOver();
scene.remove(otherPlayer);
switchToDeath(otherPlayer);
otherPlayer.position.y = 1000000;
gametime.user.position == 1 && !r ? (score1++, r = true) : (score2++, r = true);
return;
}
camera.position.y = 1000000;
gametime.user.position == 1 && !r ? (score2++, r = true) : (score1++, r = true);
switchToDeath(camera);
let t = 5;
let spawnPoint = respawnPoints[Math.floor(Math.random() * respawnPoints.length)];
let otherSpawnPoint = [respawnPoints[0],respawnPoints[1]-.35,respawnPoints[2]];
swal({
title: "You died!",
text: "You will respawn in " + t + " seconds...",
closeOnEsc: false,
closeOnEnterKey: false,
closeOnSpaceKey: false,
closeOnClickOutside: false
});
let i = setInterval(() => {
t <= 0 ? (clearInterval(i), respawn(spawnPoint), gametime.run("respawn", [gametime.user.position + "," + otherSpawnPoint.join(",")])) : t--;
document.querySelector(".swal-text").textContent = "You will respawn in " + t + " seconds...";
}, 1000);
});
gametime.on("hit", function(player) {
if (player != gametime.user.position) {
return;
}
health += -1;
clearTimeout(healthUpgradeTimeout);
healthUpgradeTimeout = setTimeout(() => { health = 100, document.querySelector("#hiteffect").style.opacity = 0, document.querySelector(".health").style.width = health + "%" }, 5000);
if (health <= 0) {
gametime.run("eleminate", [gametime.user.position]);
}
if (health <= 50) {
document.querySelector(".health-wrapper").style.boxShadow = "0px 0px 10px 7px #ff4444";
} else {
document.querySelector(".health-wrapper").style.boxShadow = "0px 0px 10px 7px #25750a";
}
document.querySelector(".health").style.width = health + "%";
let n = setInterval(() => {
if (document.querySelector("#hiteffect").style.opacity >= 1) {
return clearInterval(n), (() => {
let n = setInterval(() => {
if (document.querySelector("#hiteffect").style.opacity <= 0) {
return clearInterval(n);
}
document.querySelector("#hiteffect").style.opacity = String((document.querySelector("#hiteffect").style.opacity-0) - .1);
});
})();
}
document.querySelector("#hiteffect").style.opacity = String((document.querySelector("#hiteffect").style.opacity-0) + .1);
});
});
gametime.on("playerJump", function(data) {
let player = data.split(",")[1];
let defaultY = data.split(",")[0];
console.log(defaultY);
if (player == gametime.user.position) {
return;
}
((defaultY)=>{let t=.5;let h=setInterval(()=>{if(t<=0){return(clearInterval(h),(()=>{let t=0;let h=setInterval(()=>{if(otherPlayer.position.y<=defaultY){return(clearInterval(h))}(t+=.05);otherPlayer.position.y+=-t},25)})())}(t+=-.05);otherPlayer.position.y+=t},25)})(defaultY);
});
gametime.on("playerRotate", function(pos) {
if (pos.split(",")[3] == gametime.user.position) {
return;
}
otherPlayer.rotation.order = "YXZ";
otherPlayer.rotation.y = pos.split(",")[1];
otherPlayer.getObjectByName("neck_02_071").rotation.z = pos.split(",")[0];
// otherPlayer.getObjectByName("WeaponConceptACE35Rglb").rotation.x = pos.split(",")[0]-1;
});
gametime.on("selectCharacter", function(data) {
let character = data.split(",")[0];
let player = data.split(",")[1];
if (player == gametime.user.position) {
return;
}
otherSelectedCharacter = character;
createCharacter(data.split(",")[2]);
});
gametime.on("endPlayerWalk", function(data) {
let player = data.split(",")[6];
if (player == gametime.user.position) {
return;
}
let a = mixer1.clipAction(characterAnimations[0]);
a.stop();
otherIsWalkingForward=false;
otherIsWalkingBackward=false;
otherIsWalkingLeft=false;
otherIsWalkingRight=false;
otherPlayer.position.set(data.split(",")[0]-0,data.split(",")[1]-1.25,data.split(",")[2]-0);
otherPlayer.rotation.y = data.split(",")[4]-0;
});
gametime.on("playerWalk", function(data) {
let player = data.split(",")[7];
let e = data.split(",")[6];
if (player == gametime.user.position) {
return;
}
let a = mixer1.clipAction(characterAnimations[0]);
a.play();
otherPlayer.position.set(data.split(",")[0]-0,data.split(",")[1]-1.25,data.split(",")[2]-0);
otherPlayer.rotation.y = data.split(",")[4]-0;
if (e == "ArrowUp") {
otherIsWalkingForward = true;
}
if (e == "ArrowDown") {
otherIsWalkingBackward = true;
}
if (e == "ArrowLeft") {
otherIsWalkingLeft = true;
}
if (e == "ArrowRight") {
otherIsWalkingRight = true;
}
});
gametime.onconnect = function() {
gametime.run("connect");
gametime.run("selectCharacter", [(new URLSearchParams(location.search).get("character")||"mark-vi")+","+gametime.user.position+","+(localStorage["prefsArmorColor"]||"#fff")]);
};
warthogsToAdd = [];
function createWarthog(position, rotation) {
warthogsToAdd.push(position.concat(rotation));
}
createWarthog([-12, 0, 34], [0, Math.PI+.75, 0]);
createWarthog([-12, 0, 30], [0, Math.PI+.75, 0]);
warthogs=[];for(let i=0;i<warthogsToAdd.length;i++){(new THREE.GLTFLoader).load("models/vehicles/warthog.glb",(e)=>{warthogs.push(e.scene),e.scene.obstructed=false,e.scene.scale.set(2,2,2),e.scene.name="Warthog",e.scene.maxshot=100,map.add(e.scene),e.scene.position.set(warthogsToAdd[i][0],warthogsToAdd[i][1],warthogsToAdd[i][2]),e.scene.rotation.set(warthogsToAdd[i][3],warthogsToAdd[i][4],warthogsToAdd[i][5]),scene.add(e.scene)})}
/* End Gametime.js event variables */
let raycaster = new THREE.Raycaster();
raycastTargets = [otherPlayerFollower];
center = new THREE.Vector2(0,0);
function animate() {
animated = true;
otherPlayerFollower.position.copy(otherPlayer.position);
otherPlayerFollower.rotation.copy(otherPlayer.rotation);
otherPlayerFollower.updateMatrix();
otherPlayerFollower.translateY(.8);
isInWarthog?(camera.position.copy(currentVehicle.position),camera.position.z+=.4,camera.position.y+=.5,walkAxisYLocked=false,canFire=false):void(0);
primaryRounds<=0?primaryRounds=0:(secondaryRounds<=0&&(secondaryRounds=0));
(currentWeaponPosition=="primary"?primaryMagsLeft:secondaryMagsLeft)<=0&&(currentWeaponPosition=="primary"?primaryRounds:secondaryRounds)<=0&&!isReloading?showText("No ammo left. Press ["+keyControls.switchWeapon.toUpperCase()+"] to switch weapon."):(!isTouchingOrdinance&&hideText());
myPlayer.position.copy(camera.position);
myPlayer.rotation.y = camera.rotation.y;
myPlayer.translateY(-1.15);
myPlayer.translateZ(.2);
myPlayer.scale.set(.5,.5,.5);
distanceTo(otherPlayer.position,camera.position)>=40?otherPlayer.visible=false:otherPlayer.visible=true;
if(currentMap=="HAVEN"){
if(camera.position.x<=-2&&camera.position.z>=9.5&&camera.position.x>=-7.1&&camera.position.z<=14.3&&camera.position.y>=0&&camera.position.y<=1){
camera.position.x+=(.05);
}else if(camera.position.x<=-2&&camera.position.z>=9.5&&camera.position.x>=-7.1&&camera.position.z<=14.3&&camera.position.y>=1){
(defaultY=1.35);
}else if(camera.position.x>=2&&camera.position.z>=9.5&&camera.position.x<=7.1&&camera.position.z<=14.3&&camera.position.y>=0&&camera.position.y<=1){
camera.position.x+=(-.05);
}else if(camera.position.x>=2&&camera.position.z>=9.5&&camera.position.x<=7.1&&camera.position.z<=14.3&&camera.position.y>=1){
(defaultY=1.35);
}else if(camera.position.x<=.8&&camera.position.x>=-.8&&camera.position.z>=14.2&&camera.position.z<=18.35){
camera.rotation.y<=Math.PI/2?camera.position.x+=(-.05):camera.position.x+=(.05);
}else{
camera.position.x>=-2&&camera.position.x<=2&&camera.position.z.toFixed(0)==8&&(defaultY=.2);
camera.position.x>=-2&&camera.position.x<=2&&camera.position.z.toFixed(0)==7&&(defaultY=-.2);
camera.position.x>=-2&&camera.position.x<=2&&camera.position.z.toFixed(0)==6&&(defaultY=-.6);
camera.position.x>=-2&&camera.position.x<=2&&camera.position.z.toFixed(0)==5&&(defaultY=-1);
camera.position.x>=-2&&camera.position.x<=2&&camera.position.z.toFixed(0)==4&&(defaultY=-1.4);
camera.position.x>=-2&&camera.position.x<=2&&camera.position.z.toFixed(0)==3&&(defaultY=-1.8);
!(camera.position.z.toFixed(0)<=8&&camera.position.x>=-2&&camera.position.x<=2)&&(defaultY=.35);
}
}else{
map.traverse((i)=>{i.isMesh&&(i.name.includes("Container")||i.name.includes("Warthog"))&&(collision(i,follower)&&stopMoving(true,i))});
collision(otherPlayerFollower,follower)&&stopMoving(true,otherPlayerFollower);
new URLSearchParams(location.search).get("blob")||(map.position.y = -308.5);
}
gunIdle = false;
setInterval(() => { if (gunIdle || !animated || typeof mixer1 == "undefined" || typeof mixer3 == "undefined" || /rocket|shotgun/gi.test(currentWeapon)) { return } gunIdle = true; let e = (currentWeapon=="rifle"?mixers[weaponDefs.indexOf(currentWeapon)].clipAction(gunAnimations[0]):(currentWeapon=="pistol"?mixer3.clipAction(secondGunAnimations[0]):mixers[weaponDefs.indexOf(currentWeapon)].clipAction(gunsAnimations[weaponDefs.indexOf(currentWeapon)][0]))); e.play() });
raycastTargets[0] = otherPlayerFollower;
looker.position.copy(camera.position),looker.rotation.copy(camera.rotation),looker.updateMatrix(),looker.translateZ(-2);
intersection!=null?(document.querySelector(".crosshair").style.boxShadow="0px 0px 10px 2px #ff4444"):(document.querySelector(".crosshair").style.boxShadow="0px 0px 10px 2px #25750a");
walkAxisYLocked && (camera.position.y = defaultY);
// document.querySelector("#radar-obj").style.top = (distanceTo(camera.position, otherPlayer.position) * 30) + "px";
if (gunLocked) { !isZoomed ? (gun.position.copy(camera.position),gun.rotation.copy(camera.rotation),gun.updateMatrix(),gun.translateX(.1),gun.translateY(-.85),gun.scale.set(.1,.1,.1),gun.rotateY(-.05),(melee&&gun.rotateY(gunMeleeRotationY),gun.translateZ(gunMeleeRotationY/25),gun.translateX(-(gunMeleeRotationY/100)))) : (gun.position.copy(camera.position),gun.rotation.copy(camera.rotation),gun.updateMatrix(),(currentWeapon=="rifle"?(scene.children.indexOf(gun)>-1&&scene.remove(gun)):gun.translateX(-.255)),gun.translateY(-.84),gun.scale.set(.1,.1,.1),gun.rotateX(-.025),gun.rotateY(-.05),gun.rotateZ(-.2),(currentWeapon=="assault"&&(gun.position.copy(camera.position),gun.rotation.copy(camera.rotation),gun.updateMatrix(),(currentWeapon=="rifle"?(scene.children.indexOf(gun)>-1&&scene.remove(gun)):gun.translateX(-.1)),gun.translateY(-.86),gun.scale.set(.1,.1,.1),gun.rotateX(-.025),gun.rotateY(-.05),gun.rotateZ(-.1)))) }
if (gunLocked && currentWeapon == "uzi" && isZoomed) { (gun.position.copy(camera.position),gun.rotation.copy(camera.rotation),gun.updateMatrix(),(currentWeapon=="rifle"?(scene.children.indexOf(gun)>-1&&scene.remove(gun)):gun.translateX(-.115)),gun.translateY(-.84),gun.scale.set(.1,.1,.1),gun.rotateX(-.025),gun.rotateY(-.05),gun.rotateZ(-.1),(currentWeapon=="assault"&&(gun.position.copy(camera.position),gun.rotation.copy(camera.rotation),gun.updateMatrix(),(currentWeapon=="rifle"?(scene.children.indexOf(gun)>-1&&scene.remove(gun)):gun.translateX(-.1)),gun.translateY(-.86),gun.scale.set(.1,.1,.1),gun.rotateX(-.025),gun.rotateY(-.05),gun.rotateZ(-.1)))) }
if (gunLocked && (currentWeapon == "shotgun" || currentWeapon == "rocket") && isZoomed) { (gun.position.copy(camera.position),gun.rotation.copy(camera.rotation),gun.updateMatrix(),gun.translateX(.1),gun.translateY(-.85),gun.scale.set(.1,.1,.1),gun.rotateY(-.05),(melee&&gun.rotateY(gunMeleeRotationY),gun.translateZ(gunMeleeRotationY/25),gun.translateX(-(gunMeleeRotationY/100)))) }
let delta = clock.getDelta();
if (typeof mixer1 != "undefined") mixer1.update(delta+.02);
if (typeof mixer2 != "undefined") mixer2.update(delta+.02);
if (typeof mixer4 != "undefined") mixer3.update(delta);
mixers.length>0&&(()=>{for(let i=0;i<mixers.length;i++){typeof mixers[i]!="undefined"&&mixers[i].update((isReloading&¤tWeapon=="rocket"?delta-.01:(currentWeapon=="shotgun"?delta+.01:delta)))}})();
follower.position.copy(camera.position);
document.querySelector("#rounds").querySelector("#counter").textContent = (currentWeaponPosition=="primary"?primaryRounds:secondaryRounds);
document.querySelector("#rounds").querySelector("#magcount").textContent = ((currentWeaponPosition=="primary"?primaryMagsLeft:secondaryMagsLeft) < 0 ? 0 : (currentWeaponPosition=="primary"?primaryMagsLeft:secondaryMagsLeft));
document.querySelector("#rounds").querySelector("#grenadecount").textContent = grenadesLeft;
document.querySelector(".player1").querySelector(".score").textContent = score1;
document.querySelector(".player2").querySelector(".score").textContent = score2;
currentPerformance < 100 ? setTimeout(() => {
renderer.render(scene, camera);
}, (100 - currentPerformance) * 5) : (renderer.render(scene, camera));
requestAnimationFrame(animate);
}
camera.rotation.order = "YXZ";
document.addEventListener("mousemove", function(e) {
if (!controls.isLocked) { return e.preventDefault() }
!isFreePlay && setTimeout(() => gametime.run("playerRotate", [camera.rotation.x+","+camera.rotation.y+","+camera.rotation.z+","+gametime.user.position]), 100);
document.querySelector(".radar").style.transform = `rotate(${-(()=>{const a=camera.rotation.y,t=a>0?a:2*Math.PI+a;return THREE.MathUtils.radToDeg(t)})()}deg)`;
});
currentMode = "slayer";
weaponDefs = ["rifle", "pistol", "sniper", "assault", "uzi", "shotgun", "rocket"];
fixedLoadout=[];
if (currentMode == "fiesta") {
fixedLoadout[0]=weaponDefs[Math.floor(Math.random()*weaponDefs.length)];
fixedLoadout[1]=weaponDefs[Math.floor(Math.random()*weaponDefs.length)];
} else if (currentMode == "snipers") {
fixedLoadout[0]="sniper";
fixedLoadout[1]="sniper";
} else if (currentMode == "rocknrail") {
fixedLoadout[0]="rocket";
fixedLoadout[1]="railgun";
} else if (currentMode == "slayer") {
fixedLoadout = (localStorage["prefsLoadout"] || "rifle,pistol").split(",");
}
loadout = fixedLoadout;
document.querySelector("#rounds").querySelector("img").src = "images/guns/" + fixedLoadout[0] + ".png";
currentWeapon = loadout[0];
weapons = {
"rifle": {},
"pistol": {},
"sniper": {},
"assault": {},
"uzi": {},
"shotgun": {},
"rocket": {}
};
mixers = [];
gunsAnimations = [];
loadingProgress=0;
ordinanceTouching = false;
for (let i = 0; i < weaponDefs.length; i++) {
(new THREE.GLTFLoader).load("models/weapons/"+weaponDefs[i]+".glb", (gun) => {
weapons[weaponDefs[i]] = gun;
mixers[i] = new THREE.AnimationMixer(gun.scene);
gunsAnimations[i] = gun.animations;
});
}
let manager=new THREE.LoadingManager;manager.onProgress=function(e,a,n){loadingProgress=(a/n*100).toFixed(0)};let Loaders={Map:new THREE.GLTFLoader(manager).load(new URLSearchParams(location.search).get("blob")?decodeURIComponent(currentMap.toLowerCase()):"models/maps/"+currentMap+"/scene.gltf", (map) => {
currentMap=="CARGO"&&(map.scene.getObjectByProperty("type","DirectionalLight").intensity=.4);
window.map = map.scene;
scene.add(map.scene);
map.scene.scale.set(1.65, 1.65, 1.65);
new URLSearchParams(location.search).get("blob")||(map.scene.position.y = -310);