-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
executable file
·2824 lines (2448 loc) · 91.5 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>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>First Person Shooter Game</title>
<style>
body{margin: 0; padding: 0; font-family:'Helvetica Neue',sans-serif; cursor: crosshair;overflow: hidden;}
/*scoreboard*/
#scoreboard {position: fixed; top: 0; right: 0; /*width: 350px;*/ text-align: center; font-family: serif; font-size: 1rem; display: none; background: #aaa; border-radius: 5px; padding: 0 0.3rem;}
#scoreboard table {border-bottom: 1px solid #fff; }
#scoreboard p {margin: 8px auto;}
#scoretable th{color: #1E88E5; padding: 0 6px;}
.color_cl{width: 10px;}
#color1{background: yellow; }
#color2{background: orange; }
/*general css for .info_page*/
.info_page{ position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: grey; opacity: 0.85; text-align: center; color: #fff; z-index: 100; display: none;}
.info_page h1{margin-top: 60px; font-family: cursive; font-weight: bolder; font-size: 3rem;}
.info_page h2{margin: 35px auto 15px auto; font-family: cursive; font-weight: bolder; font-size: 2rem;text-shadow:cyan 0 -1px 3px;}
.info_page h3{margin-top: 25px; font-family: cursive; font-weight: bolder; font-size: 1.5rem; color: #d04c4c;}
.info_page h4{margin: 15px;}
.cyan{color: cyan;}
/* instruction page */
button{font-size: 1rem; padding: 5px 15px; color: #fff; border-radius: 16px; border: none; margin: 0 auto; cursor: pointer; outline: none; background: #009688; font-family:'Helvetica Neue',sans-serif; text-shadow:#C17C3A 0 -1px 0;}
button:hover{transform: scale(1.15); -webkit-transform: scale(1.15);}
#game_info, #game_link{color:cyan; }
#mini_map{position: fixed; top:0; left: 0; width: 200px; height: 200px; background: #73c3aa; z-index: 90;}
#instruction, #game_start {display: block;}
#instruction p{margin: 5px auto;}
.waiting, .not_waiting{display: none;}
#choose_game_type button{ margin: 0 12px;}
/* other info pages */
#heal {background: green; opacity: 0.35;}
#hurt {background: red; opacity: 0.35; }
.how_to_play{margin: 15px auto; text-align: left; width: 25rem;}
#game_start, #resume{margin: 12px auto; background: orange; border: 1px solid #fff; }
.startover{border: 1px solid #fff; background: #00BCD4; margin: 20px 20px;}
#result_text{color: #fff; margin: 3.5rem auto 25px auto; text-shadow:cyan 0 -1px 6px;}
.top_scores{margin: 15px auto; border-radius: 10px; background: steelblue; padding: 15px; font-family:'Helvetica Neue',sans-serif; text-shadow:#C17C3A 0 -1px 0; font-size: 1rem;}
.top_scores td{padding: 5px 10px;}
.top_scores th{border-bottom: 1px solid #fff;}
.mouse_displaySVG { position: absolute; right: 0; bottom: 0; z-index: 80; }
/* start button amination */
.animated {
-webkit-animation-duration: 2s;
animation-duration: 2s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
animation-iteration-count:infinite;
-webkit-animation-iteration-count:infinite;
}
@-webkit-keyframes pulse {
0% { -webkit-transform: scale(1); }
50% { -webkit-transform: scale(1.2); }
100% { -webkit-transform: scale(1); }
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.1); }
100% { transform: scale(1); }
}
.pulse {
-webkit-animation-name: pulse;
animation-name: pulse;
}
/*choose player number*/
#choose_player { display: none;}
.player_btn { margin: 0 8px; }
/* choose game id */
#choose_game_id{position: absolute; top: 200px; left: 50px; background: #009688; border-radius: 10px; display: none; text-shadow:#C17C3A 0 -1px 0; box-shadow: 2px 2px 8px #aaa; padding: 0 5px; border: 1px solid #fff;}
.change_game_id{display: block; border: none; background: none;}
#close_game_id{position: absolute; top:-8px; right: -8px; border-radius: 10px; border: 2px solid #fff; background: cyan; display: none;}
.animated2 {
-webkit-animation-duration: 2s;
animation-duration: 2s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
@-webkit-keyframes flipInX {
0% { -webkit-transform: perspective(400px) rotateX(90deg);
opacity: 0;
}
40% { -webkit-transform: perspective(400px) rotateX(-10deg); }
70% { -webkit-transform: perspective(400px) rotateX(10deg); }
100% { -webkit-transform: perspective(400px) rotateX(0deg);
opacity: 1;
}
}
@keyframes flipInX {
0% { transform: perspective(400px) rotateX(90deg);
opacity: 0;
}
40% { transform: perspective(400px) rotateX(-10deg); }
70% { transform: perspective(400px) rotateX(10deg); }
100% { transform: perspective(400px) rotateX(0deg);
opacity: 1;
}
}
.flipInX {
-webkit-backface-visibility: visible ; /*important*/
-webkit-animation-name: flipInX;
backface-visibility: visible; /*important*/
animation-name: flipInX;
}
/* control pannel*/
.control{ position: absolute; bottom: 0; left: 10px; z-index: 110; height: 35px;}
.control_btn {width: 35px; height: 35px; border: none; margin: auto; vertical-align: top;}
#question{background: url("/images/question.png"); background-size: cover;background-repeat: no-repeat; }
#home{background: url("/images/home.png"); background-size: cover;background-repeat: no-repeat; }
#setting{background: url("/images/setting.png"); background-size: cover;background-repeat: no-repeat; }
#key_error{color:red; display: none;}
#close_keyset{border: 1px solid #fff; background: orange;}
.sound_control{height: 35px; margin: auto; display: inline-block; text-align: center; font: sans-serif; font-weight: bolder; font-size: 12px; }
/* choose map btn */
#choose_map {margin: 20px auto;}
.map_btn{width: 100px; height: 100px; display: inline-block; margin: 15px; border: 1px solid #fff; border-radius: 5px;}
#map1{background: url("/images/map1.png"); box-shadow: 2px 2px 8px yellow;}
#map2{background: url("/images/map2.png"); }
#map3{background: url("/images/map3.png"); }
#map1, #map2, #map3{ background-size: cover;}
/* show direction pannel */
#direction{position: absolute; top:0; left: 200px; width: 55px; height: 45px; z-index: 90;}
#topleft {background: url("/images/tl.png");}
#topright{background: url("/images/tr.png");}
#bottomright{background: url("/images/br.png");}
#bottomleft{background: url("/images/bl.png");}
#top{background: url("/images/t.png");}
#bottom{background: url("/images/b.png");}
#right{background: url("/images/r.png");}
#left{background: url("/images/l.png");}
#middle{outline: none; vertical-align: top;}
.arrow{ color:#000; font-size: 10px; text-align: center; outline: 1px solid #ccc; display: inline-block; width: 15px; height: 15px; opacity: 0.2; margin: 0; padding: 0;}
/* touch pannel */
.touch_pannel{position: absolute; bottom: 0; width: 100%; height: 200px; z-index: 100; display: none;}
#look_around{position: absolute; left: 10px; bottom: 90px; width: 150px; height: 40px; border: 2px solid #fff; font-size: 20px; padding: 0; background: url('/images/look_arrow.png'); background-repeat: no-repeat; background-position: center center; opacity: 0.5; border-radius: 16px; }
#shoot_btn{position: absolute; right: 55px; bottom: 160px; width: 40px; height: 40px; background: orange; border-radius: 22px; border: 2px solid #fff; box-shadow: 1px 0px 1px 1px #aaa; padding: 0; font-size: 30px;text-align: center; color: #fff;}
#move_around{position: absolute; right: 0; bottom: 0; width: 150px; height: 150px; background: url('/images/move_arrow.png'); opacity: 0.5; border: 1px solid #fff; }
/*responsive design */
@media screen and (min-width: 450px) and (max-width: 700px) {
html {font-size: 11px;}
.info_page h1, .info_page h2, .info_page h3 { margin: 12px auto 0 auto;}
.info_page h4, #choose_map h4, #game_info h4{/*font-size: 0.7rem;*/ margin: 8px auto 0 auto;}
button{/*font-size: 0.8rem;*/ padding: 3px 5px; color: #fff; border-radius: 10px;}
#game_start, #resume, .startover, #close_keyset{margin: 8px auto; }
.map_btn{width: 60px; height: 60px; margin: 0 10px;}
#mini_map{width: 100px; height: 100px;}
#direction{left: 100px; }
#scoreboard table{padding: 3px;}
#scoretable th{ padding: 0 3px;}
.status_cl{display: none;}
#result_text{margin: 12px auto 0 auto; }
.top_scores{margin: 8px auto; padding: 2px;}
#choose_game_id{ top: 90px; left: 10px; }
#choose_game_id h4{margin: 10px auto 0 auto;}
#close_game_id{ display: block;}
}
@media screen and (max-width: 449px) {
html {font-size: 11px;}
.info_page h1, .info_page h2, .info_page h3 { margin: 12px auto 0 auto;}
.info_page h4, #choose_map h4, #game_info h4{/*font-size: 0.7rem;*/ margin: 8px auto 0 auto;}
button{ padding: 3px 8px; color: #fff; border-radius: 10px;}
#choose_game_type button{ margin: 12px auto; display: block;}
#game_start, #resume, .startover, #close_keyset{margin: 8px auto; }
.map_btn{width: 60px; height: 60px; margin: 5px 10px;}
#mini_map{width: 100px; height: 100px;}
#direction{left: 100px; }
#scoreboard table{padding: 3px;}
#scoretable th{ padding: 0 3px;}
.status_cl{display: none;}
#result_text{margin: 12px auto 0 auto; }
.top_scores{margin: 8px auto; padding: 2px;}
#choose_game_id{ top: 90px; left: 10px; }
#choose_game_id h4{margin: 10px auto 0 auto;}
#close_game_id{display: block;}
}
</style>
</head>
<body>
<div class="touch_pannel">
<div id="look_around"></div>
<div id="move_around"></div>
<div id="shoot_btn">+</div>
</div><!-- .touch_pannel -->
<div id='scoreboard'>
<table id='scoretable'>
<tr>
<th>Player</th>
<th class="color_cl"></th>
<th class="status_cl">Status</th>
<th>Score</th>
<th>Health</th>
</tr>
<tr class="p1_score">
<td id='p1'>1</td>
<td class="color_cl" id="color1"></td>
<td class="status_cl" id="status1"></td>
<td id="score1">online</td>
<td id="health1"></td>
</tr>
<tr class="p2_score">
<td id='p2'>2</td>
<td class="color_cl" id="color2"></td>
<td class="status_cl" id="status2">online</td>
<td id="score2"></td>
<td id="health2"></td>
</tr>
</table>
<p id = "play_time"></p>
</div><!-- #scoreboard -->
<div class="info_page" id="instruction">
<h2> First Person Shooter Game </h2>
<h4 id="game_info">Current Game ID:{{ game_link }}</h4>
<hr>
<div id="choose_game_type">
<h4>Choose game type:
<button class="game_type_btn" id="em">Explore Maze</button>
<button class="game_type_btn" id="s3">Survive 3 Mins</button>
<button class="game_type_btn" id="cf">Get Flag</button>
</h4>
</div><!-- .choose_game_type -->
<div id="choose_player">
<h4>Choose number of player(s):
<button class="player_btn" id="1player">One</button>
<button class="player_btn" id="2player">Two</button>
</h4>
</div><!-- .choose_player -->
<div id="choose_game_id" class="animated2 flipInX">
<button id="close_game_id">X</button>
<h4>Games need 2nd player</h4>
<h4>(click id to join)</h4>
<hr>
<div class= "avail_ids"></div>
</div><!-- .choose_player -->
<div id="choose_map">
<h4>Choose a map:
<button class="map_btn" id="map1"></button>
<button class="map_btn" id="map2"></button>
<button class="map_btn" id="map3"></button>
</h4>
</div><!-- .choose_map -->
<h4 class="waiting">Waiting for another player ...</h4>
<h4 class="not_waiting cyan">Another player joins in ...</h4>
<button id="game_start" class="animated pulse"> START </button>
<p>Log in to save your score: {{ user_name }} <a href="{{ login_key }}">{{ gate }}</a></p>
</div><!-- #instruction -->
<div class="info_page" id="ready">
<h2> Ready </h2>
<h2> GO </h2>
</div><!-- #ready -->
<div class="info_page" id="pause">
<h2> First Person Shooter Game </h2>
<hr>
<div class="how_to_play">
<!-- <h4><span class="cyan">Explor Maze:</span> explore the maze and move around</h4>
<h4><span class="cyan">Survive 3 Minutes:</span> score as many as you can in 3 minutes</h4>
<h4><span class="cyan">Capture Flag:</span> get to the flag (red) as soon as you can</h4>
<h4><span class="cyan">If you die:</span> your score, health and position will be reset </h4> -->
<br>
<h3><span class="cyan">How to Play:</span></h3>
<h4 class="pc" ><span class="cyan">Move:</span> W, S, A, D </h4>
<h4 class="pc" ><span class="cyan">Look Around:</span> Mouse Move</h4>
<h4 class="pc" ><span class="cyan">Shoot:</span> Mouse Click</h4>
<h4 class="mobile" ><span class="cyan">Move:</span> Slide on MOVE Area </h4>
<h4 class="mobile" ><span class="cyan">Look Around:</span> Slide on LOOK Area </h4>
<h4 class="mobile" ><span class="cyan">Shoot:</span> Cross Button</h4>
<h4><span class="cyan">Play with Another Friend:</span> <br>ask you friend to join the game <span id="game_link">{{ game_link }}</span> </h4>
</div><!-- .how_to_play -->
<button id="resume" class="animated pulse" >Resume</button>
<button class="startover">StartOver</button>
</div><!-- #pause -->
<div class="info_page" id="result">
<h1 id="result_text"></h1>
<table class="top_scores animated2 flipInX">
<tr>
<th>Rank</th>
<th>User</th>
<th>Time</th>
<th>Score</th>
</tr>
</table>
<button class="startover"> Start A New Game </button>
</div><!-- #results -->
<div class="info_page" id="reset">
<h2> You Die </h2>
<h2> Reset ...</h2>
</div><!-- #reset -->
<div class="info_page" id="choose_key">
<h2> Sounds: </h2>
Shoot sound on:<input type="radio" name="shoot_sound" value="on" checked>
off:<input type="radio" name="shoot_sound" value="off">
<br>
Bird sound on:<input type="radio" name="bird_sound" value="on" checked>
off:<input type="radio" name="bird_sound" value="off">
<hr>
<h2> Define Your Own Keys: </h2>
<h4 class="cyan"> choose a movement and press the key for this movement:</h4>
Left:<input type="radio" name="moving_direction" value="left" checked>
Right:<input type="radio" name="moving_direction" value="right">
Forward:<input type="radio" name="moving_direction" value="forward">
Backward:<input type="radio" name="moving_direction" value="backward">
<h4>Current:</h4>
<h4>Left: <span class="left cyan">A</span>, Right: <span class="right cyan">D</span>, Forward: <span class="forward cyan">W</span>, Backward: <span class="backward cyan">S</span> </h4>
<h4 id="key_error">One key is used for multiple movements!</h4>
<button id="close_keyset">Close</button>
</div><!-- #choose_key -->
<div class="control">
<button class="control_btn" id="home" title="main menu"></button>
<button class="control_btn" id="question" title="how to play"></button>
<button class="control_btn" id="setting" title="settings"></button>
<!-- <button id="ai_shoot">ai_off</button> -->
</div><!-- #control -->
<div id="mini_map"></div>
<div id="direction">
<div class="arrow" id="topleft"></div>
<div class="arrow" id="top"></div>
<div class="arrow" id="topright"></div>
<div class="arrow" id="left"></div>
<div class="arrow" id="middle">■</div>
<div class="arrow" id="right"></div>
<div class="arrow" id="bottomleft"></div>
<div class="arrow" id="bottom"></div>
<div class="arrow" id="bottomright"></div>
</div><!-- .direction -->
<div class="info_page" id="hurt"></div>
<div class="info_page" id="heal"></div>
<!-- audio -->
<audio id="player_sound" src="/audio/player_sound.m4a" ></audio>
<audio id="blast" src="/audio/explosion.m4a" ></audio>
<audio id="ai_sound" src="/audio/ai_sound.m4a" ></audio>
<audio id="birds" src="/audio/birds008.mp3" ></audio>
<!-- script -->
<script src='/_ah/channel/jsapi'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r72/three.min.js"></script>
<script src="/js/Flag.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<!-- <script src='/js/SubdivisionModifier.js'></script> -->
<!-- custom Shader for cube glow -->
<script id="vertexShader" type="x-shader/x-vertex">
uniform vec3 viewVector;
uniform float c;
uniform float p;
varying float intensity;
void main()
{
vec3 vNormal = normalize( normalMatrix * normal );
vec3 vNormel = normalize( normalMatrix * viewVector );
intensity = pow( c - dot(vNormal, vNormel), p );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
</script>
<!-- fragment shader a.k.a. pixel shader for cube glow-->
<script id="fragmentShader" type="x-shader/x-vertex">
uniform vec3 glowColor;
varying float intensity;
void main()
{
vec3 glow = glowColor * intensity;
gl_FragColor = vec4( glow, 0.3 );
// gl_FragColor = vec4( glowColor, 0.5);
}
</script>
<!-- code for making fireball with perlin noise -->
<script id="perlin_vertexShader" type="x-shader/x-vertex" >
//
// GLSL textureless classic 3D noise "cnoise",
// with an RSL-style periodic variant "pnoise".
// Author: Stefan Gustavson (stefan.gustavson@liu.se)
// Version: 2011-10-11
//
// Many thanks to Ian McEwan of Ashima Arts for the
// ideas for permutation and gradient selection.
//
// Copyright (c) 2011 Stefan Gustavson. All rights reserved.
// Distributed under the MIT license. See LICENSE file.
// https://github.com/ashima/webgl-noise
//
vec3 mod289(vec3 x)
{
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 mod289(vec4 x)
{
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 permute(vec4 x)
{
return mod289(((x*34.0)+1.0)*x);
}
vec4 taylorInvSqrt(vec4 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
vec3 fade(vec3 t) {
return t*t*t*(t*(t*6.0-15.0)+10.0);
}
// Classic Perlin noise
float cnoise(vec3 P)
{
vec3 Pi0 = floor(P); // Integer part for indexing
vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1
Pi0 = mod289(Pi0);
Pi1 = mod289(Pi1);
vec3 Pf0 = fract(P); // Fractional part for interpolation
vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0
vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
vec4 iy = vec4(Pi0.yy, Pi1.yy);
vec4 iz0 = Pi0.zzzz;
vec4 iz1 = Pi1.zzzz;
vec4 ixy = permute(permute(ix) + iy);
vec4 ixy0 = permute(ixy + iz0);
vec4 ixy1 = permute(ixy + iz1);
vec4 gx0 = ixy0 * (1.0 / 7.0);
vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;
gx0 = fract(gx0);
vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);
vec4 sz0 = step(gz0, vec4(0.0));
gx0 -= sz0 * (step(0.0, gx0) - 0.5);
gy0 -= sz0 * (step(0.0, gy0) - 0.5);
vec4 gx1 = ixy1 * (1.0 / 7.0);
vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;
gx1 = fract(gx1);
vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);
vec4 sz1 = step(gz1, vec4(0.0));
gx1 -= sz1 * (step(0.0, gx1) - 0.5);
gy1 -= sz1 * (step(0.0, gy1) - 0.5);
vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);
vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);
vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);
vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);
vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);
vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);
vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);
vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);
vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
g000 *= norm0.x;
g010 *= norm0.y;
g100 *= norm0.z;
g110 *= norm0.w;
vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
g001 *= norm1.x;
g011 *= norm1.y;
g101 *= norm1.z;
g111 *= norm1.w;
float n000 = dot(g000, Pf0);
float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));
float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));
float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));
float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));
float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));
float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));
float n111 = dot(g111, Pf1);
vec3 fade_xyz = fade(Pf0);
vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);
vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);
float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
return 2.2 * n_xyz;
}
// Classic Perlin noise, periodic variant
float pnoise(vec3 P, vec3 rep)
{
vec3 Pi0 = mod(floor(P), rep); // Integer part, modulo period
vec3 Pi1 = mod(Pi0 + vec3(1.0), rep); // Integer part + 1, mod period
Pi0 = mod289(Pi0);
Pi1 = mod289(Pi1);
vec3 Pf0 = fract(P); // Fractional part for interpolation
vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0
vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
vec4 iy = vec4(Pi0.yy, Pi1.yy);
vec4 iz0 = Pi0.zzzz;
vec4 iz1 = Pi1.zzzz;
vec4 ixy = permute(permute(ix) + iy);
vec4 ixy0 = permute(ixy + iz0);
vec4 ixy1 = permute(ixy + iz1);
vec4 gx0 = ixy0 * (1.0 / 7.0);
vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;
gx0 = fract(gx0);
vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);
vec4 sz0 = step(gz0, vec4(0.0));
gx0 -= sz0 * (step(0.0, gx0) - 0.5);
gy0 -= sz0 * (step(0.0, gy0) - 0.5);
vec4 gx1 = ixy1 * (1.0 / 7.0);
vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;
gx1 = fract(gx1);
vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);
vec4 sz1 = step(gz1, vec4(0.0));
gx1 -= sz1 * (step(0.0, gx1) - 0.5);
gy1 -= sz1 * (step(0.0, gy1) - 0.5);
vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);
vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);
vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);
vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);
vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);
vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);
vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);
vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);
vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
g000 *= norm0.x;
g010 *= norm0.y;
g100 *= norm0.z;
g110 *= norm0.w;
vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
g001 *= norm1.x;
g011 *= norm1.y;
g101 *= norm1.z;
g111 *= norm1.w;
float n000 = dot(g000, Pf0);
float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));
float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));
float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));
float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));
float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));
float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));
float n111 = dot(g111, Pf1);
vec3 fade_xyz = fade(Pf0);
vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);
vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);
float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
return 2.2 * n_xyz;
}
// Include the Ashima code here!
varying float noise;
uniform float time;
float turbulence( vec3 p ) {
float w = 100.0;
float t = -.5;
for (float f = 1.0 ; f <= 10.0 ; f++ ){
float power = pow( 2.0, f );
t += abs( pnoise( vec3( power * p ), vec3( 10.0, 10.0, 10.0 ) ) / power );
}
return t;
}
void main() {
noise = 10.0 * -.10 * turbulence( .5 * normal + time );
float b = 5.0 * pnoise( 0.05 * position + vec3( 2.0 * time ), vec3( 100.0 ) );
float displacement = - 10. * noise + b;
vec3 newPosition = position + normal * displacement;
gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 );
}
</script>
<script id="perlin_fragmentShader" type="x-shader/x-vertex" >
varying float noise;
uniform sampler2D tExplosion;
float random( vec3 scale, float seed ){
return fract( sin( dot( gl_FragCoord.xyz + seed, scale ) ) * 43758.5453 + seed ) ;
}
void main() {
float r = .01 * random( vec3( 12.9898, 78.233, 151.7182 ), 0.0 );
vec2 tPos = vec2( 0, 1.0 - 1.3 * noise + r );
vec4 color = texture2D( tExplosion, tPos );
gl_FragColor = vec4(color.rgb,0.3 );
}
</script>
<script type="text/javascript">
// -------------------------------------------- |
// - 3D First Person Shooter Game - |
// - with Three.js and d3.js - |
// - by Wenjie Tang - |
// -------------------------------------------- |
// -------------------------------------------- |
// - Some Global Variables - |
// -------------------------------------------- |
// game state
var state = {
player_num: 1,
game_type: "em",
game_key: '{{ game_key }}',
me: '{{ me }}'
};
var gameStart = false;
// scene object variables
var renderer, scene, camera, pointLight, spotLight;
// field variables
var fieldWidth = 300, fieldHeight = 300;
// cube variables
var cubeX = 10, cubeY = 10, cubeZ = 30;
// wall grid
var gridSizeX = 30, gridSizeY = 30, wallGrid = [];
// map
var map1 = [ // 1 2 3 4 5 6 7 8 9
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1,],
[1, 1, 0, 0, 1, 0, 0, 1, 0, 1,],
[1, 1, 0, 0, 0, 0, 0, 1, 0, 1,],
[1, 0, 0, 1, 0, 2, 0, 0, 0, 1,],
[1, 0, 0, 2, 0, 0, 2, 0, 0, 1,],
[1, 1, 0, 0, 2, 1, 1, 1, 1, 1,],
[1, 0, 0, 0, 0, 2, 0, 0, 0, 1,],
[1, 0, 0, 1, 0, 0, 0, 1, 0, 1,],
[1, 1, 0, 0, 1, 0, 0, 1, 0, 1,],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1,],
],
map2 = [ // 1 2 3 4 5 6 7 8 9
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1,],
[1, 0, 0, 1, 1, 0, 0, 1, 0, 1,],
[1, 1, 0, 1, 0, 0, 0, 0, 0, 1,],
[1, 0, 0, 0, 0, 1, 1, 0, 0, 1,],
[1, 0, 0, 2, 0, 1, 2, 1, 0, 1,],
[1, 1, 0, 0, 2, 0, 1, 0, 1, 1,],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 1,],
[1, 0, 0, 0, 1, 1, 0, 0, 0, 1,],
[1, 1, 0, 0, 1, 1, 0, 1, 1, 1,],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1,],
],
map3 = [ // 1 2 3 4 5 6 7 8 9
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1,],
[1, 0, 0, 0, 1, 0, 0, 1, 0, 1,],
[1, 1, 0, 0, 1, 0, 0, 0, 0, 1,],
[1, 0, 1, 0, 0, 0, 1, 1, 2, 1,],
[1, 0, 0, 0, 0, 1, 2, 0, 0, 1,],
[1, 1, 1, 0, 2, 0, 0, 0, 1, 1,],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 1,],
[1, 0, 0, 0, 0, 1, 0, 1, 0, 1,],
[1, 1, 0, 0, 1, 1, 0, 1, 1, 1,],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1,],
];
var map, mapW = map1.length, mapH = map1[0].length;
map = map1; //default map
// Semi-constants
var WIDTH = window.innerWidth,
HEIGHT = window.innerHeight,
ASPECT = WIDTH / HEIGHT,
UNITSIZE = 250,
WALLHEIGHT = UNITSIZE / 3,
AISPEED = 5;
MOVESPEED = 20,
LOOKSPEED = 0.075,
BULLETMOVESPEED = MOVESPEED * 25,
NUMAI = 5,
SAFEDISTANCE = 40,
PROJECTILEDAMAGE = 20;
// var YGLOW_COLOR = "#ffdb00", BGLOW_COLOR = "#2fcbff";
var YGLOW_COLOR = "#fff", BGLOW_COLOR = "#ffdb00";
var scene, camera, renderer,
wallParent = new THREE.Object3D(),
aiParent = new THREE.Object3D(),
bulletParent = new THREE.Object3D(),
another_player;
var flag_anim = false;
var runAnim = true, gameStart = false;
var mouse = new THREE.Vector2();
mouse.x = 0; mouse.y = 0;
var health, score, startTime, elapsedTime;
// audio
var player_sound, ai_sound, blast, birds_sound;
//channel
var send_to_channel = false;
var last_walk_update = Date.now();
//test
var ai_shoot = true;
// survive time
var total_time = 180000;
// page control
var show_intro = false, show_result = false, show_keyboard = false;
// movement key control
var key = {left: 65 , right: 68 , forward: 87, backward: 83 }
// touch screen
var touchable, TMOVE_WIDTH =150, TMOVE_HEIGHT = 150;
var touch_mouse = {x: WIDTH/2, y: HEIGHT/2};
// -------------------------------------------- |
// - Setup and Draw the scene - |
// -------------------------------------------- |
function setup()
{
// set up all the 3D objects in the scene
createScene();
setupAI();
drawMiniMap();
// now reset score and health
gameStart = false;
// render
draw();
}
// var last_update = Date.now();
function draw()
{
if(runAnim){
// draw THREE.JS scene
renderer.render(scene, camera);
// loop draw function call
requestAnimationFrame(draw);
if(gameStart&&state.game_type != "em"){
send_to_channel = false;
updateBullets();
updateAI();
if(fireball_list.length > 0){ updateFireBall(); }
checkHealth();
// displayTime();
// checkReachFlag();
if(state.game_type == "cf"){
display_cf_Time();
checkReachFlag();
if(flag_anim) render_flag();
}
if(state.game_type == "s3"){
display_s3_Time();
checkTime();
}
}
else if(gameStart&&state.game_type == "em"){
updateBullets();
}
redrawMap();
}
}
function createScene()
{
scene = new THREE.Scene(); // The "world" environment. Holds all other objects.
// Set up camera so we know from where to render the scene
camera = new THREE.PerspectiveCamera(60, ASPECT, 1, 10000); // Field Of Viw, aspect ratio, near, far
camera.position.y = UNITSIZE * .2; // Raise the camera off the ground
camera.position.z = 100;
camera.position.x = 0;
// move camera to get top view
// camera.position.z = 0;
// camera.position.x = 0;
// camera.position.y = 2100;
// camera.rotation.x = -Math.PI/2;
scene.add(camera); // Add the camera to the scene
// Handle drawing as WebGL (faster than Canvas but less supported by browsers)
renderer = new THREE.WebGLRenderer();
renderer.setSize(WIDTH, HEIGHT); // Give the renderer the canvas size explicitly
renderer.setClearColor( "#D6F1FF");// sky color
// Add the canvas to the document
document.body.appendChild(renderer.domElement); // Add the canvas to the document
// Lighting
var directionalLight1 = new THREE.DirectionalLight( "#ffffff", 0.6 );
directionalLight1.position.set( -1.5, 1, -1.5 );
scene.add( directionalLight1 );
var directionalLight2 = new THREE.DirectionalLight( "#ffffff", 1.2);
// var directionalLight2 = new THREE.HemisphereLight( 0x0000ff, 0x00ff00, 0.6 );
directionalLight2.position.set( 100, 100, 100 );
scene.add( directionalLight2 );
var units = mapW;
// Geometry: floor
// THREE.ImageUtils.crossOrigin = '';
var floorTexture = THREE.ImageUtils.loadTexture('./images/floor1.jpg');
floorTexture.wrapS = floorTexture.wrapT = THREE.RepeatWrapping;
floorTexture.repeat.set(units*3, units*3);
floorTexture.anisotropy = 36;
var floor = new THREE.Mesh(
new THREE.BoxGeometry(units * UNITSIZE, 10, units * UNITSIZE),
new THREE.MeshLambertMaterial({map : floorTexture})
);
scene.add(floor);
scene.add(wallParent);
scene.add(aiParent);
scene.add(bulletParent);
// Geometry: walls
var cube = new THREE.BoxGeometry(UNITSIZE, WALLHEIGHT, UNITSIZE);
var wallTexture1 = THREE.ImageUtils.loadTexture('./images/wall-1.jpg');
var materials = new THREE.MeshLambertMaterial({map: wallTexture1});
// var wallTexture2 = t.ImageUtils.loadTexture('./images/wall-1.jpg');
// var materials = [
// new t.MeshLambertMaterial({map: wallTexture1}),
// new t.MeshLambertMaterial({map: wallTexture1}),
// ];
for (var i = 0; i < mapW; i++) {
for (var j = 0, m = map[i].length; j < m; j++) {
if (map[i][j]) {
var wall = new THREE.Mesh(cube, materials);
// wall.name = "wall";
// var wall = new t.Mesh(cube, materials[map[i][j]-1]);
// wall.castShadow = true;
// wall.receiveShadow = true;
wall.position.x = (i - units/2) * UNITSIZE;
wall.position.y = WALLHEIGHT/2;
wall.position.z = (j - units/2) * UNITSIZE;
wall.castShadow = true;
wallParent.add(wall);
}
}
}
// add axis arrowhelper
// var dir = new THREE.Vector3( 1, 0, 0 );
// var origin = new THREE.Vector3( 0, 0, 0 );
// var length = 100;
// var xArrow = new THREE.ArrowHelper( dir, origin, length, "red" );
// scene.add( xArrow );
// dir = new THREE.Vector3( 0, 1, 0 );
// origin = new THREE.Vector3( 0, 0, 0 );
// var yArrow = new THREE.ArrowHelper( dir, origin, length, "darkgreen" );
// scene.add( yArrow );
// dir = new THREE.Vector3( 0, 0, 1 );
// origin = new THREE.Vector3( 0, 0, 0 );
// var zArrow = new THREE.ArrowHelper( dir, origin, length, "blue" );
// scene.add( zArrow );
// shadows
renderer.shadowMap.enabled = true;
// directionalLight1.castShadow = true;
directionalLight2.castShadow = true;
floor.castShadow = true;
floor.receiveShadow = true;
}
// -------------------------------------------- |
// - Changes of the Game - |
// -------------------------------------------- |
// start a new game
function change_map(map_num){
$('.map_btn').css('box-shadow','none');
d3.select("svg").remove();
if (map_num == 1) { map = map1; $('#map1').css('box-shadow','2px 2px 8px yellow');}
else if (map_num == 2) { map = map2; $('#map2').css('box-shadow','2px 2px 5px yellow');}
else { map = map3; $('#map3').css('box-shadow','2px 2px 5px yellow');}
createNewWall(map_num);
camera.position.set(state.game_data[state.player_str].x, UNITSIZE*.2, state.game_data[state.player_str].z);
if(state.player_num == 1){
initialize_1p();
}
else if(state.player_num == 2){
initialize_2p();
}
// render
drawMiniMap();
runAnim = true;
draw();
}
function createNewWall(map_num){
for( var i = wallParent.children.length - 1; i >= 0; i--) {
wallParent.remove(wallParent.children[i]);
}
var cube = new THREE.BoxGeometry(UNITSIZE, WALLHEIGHT, UNITSIZE);
if (map_num == 1) {
var wallTexture1 = THREE.ImageUtils.loadTexture('./images/wall-1.jpg');
}
else if (map_num == 2) {
var wallTexture1 = THREE.ImageUtils.loadTexture('./images/wall-2.jpg');
}
else {
var wallTexture1 = THREE.ImageUtils.loadTexture('./images/wall-3.jpg');
}
var materials = new THREE.MeshLambertMaterial({map: wallTexture1});
// var wallTexture2 = t.ImageUtils.loadTexture('./images/wall-1.jpg');
// var materials = [
// new t.MeshLambertMaterial({map: wallTexture1}),
// new t.MeshLambertMaterial({map: wallTexture1}),
// ];
var units = mapW;
for (var i = 0; i < mapW; i++) {
for (var j = 0, m = map[i].length; j < m; j++) {
if (map[i][j]) {
var wall = new THREE.Mesh(cube, materials);
// wall.name = "wall";
// var wall = new t.Mesh(cube, materials[map[i][j]-1]);
// wall.castShadow = true;
// wall.receiveShadow = true;
wall.position.x = (i - units/2) * UNITSIZE;
wall.position.y = WALLHEIGHT/2;
wall.position.z = (j - units/2) * UNITSIZE;
wall.castShadow = true;
wallParent.add(wall);
}
}
}
}
function game_begin(){
$(".info_page").hide();
$("#ready").show();
$("#ready").fadeOut(600);
gameStart = true;
runAnim = true;
startTime = Date.now();
redrawMap();
draw();
}
function get_avail_gameid(){
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
show_avail_gameid(xmlHttp.responseText);
}