-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm4k.js
1530 lines (1400 loc) · 48.2 KB
/
m4k.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var server_initted = false;
var gameCanvas = document.getElementById("game");
gameCanvas.style.display = "none";
var map = new Uint8Array(64 * 64 * 64); // all blocks
var loading = document.getElementById("loading");
var info_a = document.getElementById("info_a");
var body = document.getElementsByTagName("body")[0];
var textar = document.createElement("textarea");
textar.style.position = "absolute"
textar.style.top = "-1000px"
textar.style.left = "-1000px"
body.appendChild(textar)
var w = 300;
var h = 250;
ctx = gameCanvas.getContext("2d");
ctx.imageSmoothingEnabled = false;
ctx.mozImageSmoothingEnabled = false; // < No longer needed on Firefox
ctx.webkitImageSmoothingEnabled = false;
ctx.msImageSmoothingEnabled = false;
ctx.oImageSmoothingEnabled = false;
pixels = ctx.createImageData(w, h); // initialize the image data array
for (i = 0; i < w * h; i++) { // make alpha channel opaque
pixels.data[i * 4 + 3] = 255;
}
var inittedMap = false;
// some event for when someone chats. Can be used for scripting
function onChatMessage() {};
var name = "USER 0X" + (Math.floor(Math.random() * 256).toString(16)).toUpperCase().padStart(2, "0");
var Socket;
function createSocket() {
var mapSegmentsLoaded = 0;
Socket = new WebSocket("ws://" + window.location.host);
Socket.onmessage = function(msg) {
var res = JSON.parse(msg.data)
if(res.type == "map_seg") {
mapSegmentsLoaded++;
loading.innerText = "Loaded segment [" + mapSegmentsLoaded + " of 64]"
for(var i = 0; i < 4096; i++) {
map[res.segment * 4096 + i] = res.data[i];
}
if(mapSegmentsLoaded >= 64) {
console.log("Loaded map")
init();
}
}
if(res.type == "block_changed") {
var index = res.index;
var block = res.block;
var mode = res.mode;
if(mode == 1) {
map[index] = block;
} else if(mode == 0) {
map[index] = 0;
}
}
if(res.type == "chat") {
console.log(">> " + res.name + ": " + res.message)
onChatMessage(res.message);
}
//console.log(res)
}
Socket.onopen = function() {
console.log("socket opened")
/*if(!server_initted) {
server_initted = true;
init();
}*/
if(!inittedMap) {
Socket.send(JSON.stringify({
type: "request_map"
}))
inittedMap = true
}
}
Socket.onclose = function() {
setTimeout(function() {
console.log("Reconnected socket");
createSocket();
}, 2000)
}
}
// Socket.send(msg)
createSocket();
var automaticGameSize = false; //if true, it changes game resolution to screen size (will be slow on bigger windows.)
var move_speed = 0.1
var camera_move_speed = 0.005 //camera speed using mouse
var keyboard_camera_move_speed = 0.015 //camera speed using arrow keys
var clientW = window.innerWidth; // window sizes
var clientH = window.innerHeight;
var ctx, pixels;
var texmap = new Uint32Array(16 * 16 * 3 * 27); // all textures
// a b c d
//a: width, b: height, c: amount of textures for some sides of a block, d: number of textures
var MD_left = false; // mouse down left
var MD_right = false; // mouse down right
var pointLock = false // Is the cursor (pointer) locked so that the camera can be moved by the mouse?
var CantClick = 0; // execute click, make CantClick 1, wait 500 or 250 MS and make CantClick 0. Makes sure clicks are not executed for every frame
var HCW = 0; // at first, wait 500 MS after holding mouse button down. Then repeat clicks 250 MS apart after HCW = 1
var Night = 0 // Night or day
var FPSlabel = document.getElementById("fps")
var mouseWheel; // function executed on a mouse wheel scroll
function init() { // initialize texture, canvas pixels, events, and the clock
loading.style.display = "none"; // hide loading label
gameCanvas.style.display = ""; // show gameCanvas
setTimeout(function() {
info_a.style.display = "none";
}, 3000)
var glass_colors = [0, 0xFEFEFE, 0xC0F5FE, 0xB3D6DB]
var glass_map = "1110111111111112100000010000000210010020000000001010000000000012110000000100020310000000100020000000000200000003102000200000000312000000000000031000000010000000000000010000010010000020000010030200000000010003200000000020000310000000000000021333330033033332"
for ( var i = 1; i <= 25; i++) { // for each texture
var br = 255 - ((Math.random() * 96) | 0); // number between 160 - 255 (gives texture a random noise)
for ( var y = 0; y < 16 * 3; y++) {
for ( var x = 0; x < 16; x++) {
var color = 0x966C4A; // default color (brown-like)
if (i == 3) { // stone
color = 0x7F7F7F;
}
if (i != 3 || ((Math.random() * 3) | 0) === 0) {
br = 255 - ((Math.random() * 96) | 0); // reset the random noise
}
if ((i == 1 && y < (((x * x * 3 + x * 81) >> 2) & 3) + 18)) { // grass
color = 0x6AAA40;
} else if ((i == 1 && y < (((x * x * 3 + x * 81) >> 2) & 3) + 19)) {
br = br * 2 / 3;
}
if (i == 4) { // brick
color = 0xB53A15;
if ((x + (y >> 2) * 4) % 8 === 0 || y % 4 === 0) {
color = 0xBCAFA5;
}
}
if (i == 5) { // wood
color = 0x675231;
if (x > 0 && x < 15
&& ((y > 0 && y < 15) || (y > 32 && y < 47))) {
color = 0xBC9862;
var xd = (x - 7);
var yd = ((y & 15) - 7);
if (xd < 0)
xd = 1 - xd;
if (yd < 0)
yd = 1 - yd;
if (yd > xd)
xd = yd;
br = 196 - ((Math.random() * 32) | 0) + xd % 3 * 32;
} else if (((Math.random() * 2) | 0) === 0) {
br = br * (150 - (x & 1) * 100) / 100;
}
}
var brr = br;
if (y >= 32)
brr /= 2;
if (i == 6) { // leaves
color = 0x50D937;
if (((Math.random() * 2) | 0) === 0) {
color = 0;
brr = 255;
}
}
if (i == 7) { // water
color = 0x4040ff;
}
if(i == 8) { // glass
color = glass_colors[glass_map[(y%16)*16+x]]
brr = 255;
}
if(i == 9) { // green crystal
var y_ = y%16
color = ((x+y_)*4352)
if(color < 1) color = 1
brr = 255
}
if(i == 10) { // WHITE
color = 0xDDDDDD;
brr = 255
}
if(i == 11) { // BLACK
color = 0x191616;
brr = 255
}
if(i == 12) { // RED
color = 0x963430;
brr = 255
}
if(i == 13) { // GREEN
color = 0x35461B;
brr = 255
}
if(i == 14) { // BLUE
color = 0x2E388D;
brr = 255
}
if(i == 15) { // ORANGE
color = 0xDB7D3E;
brr = 255
}
if(i == 16) { // MAGENTA
color = 0xB350BC;
brr = 255
}
if(i == 17) { // LIGHT BLUE
color = 0x6B8AC9;
brr = 255
}
if(i == 18) { // YELLOW
color = 0xB1A627;
brr = 255
}
if(i == 19) { // LIME
color = 0x41AE38;
brr = 255
}
if(i == 20) { // PINK
color = 0xD08499;
brr = 255
}
if(i == 21) { // GRAY
color = 0x404040;
brr = 255
}
if(i == 22) { // LIGHT GRAY
color = 0x9AA1A1;
brr = 255
}
if(i == 23) { // CYAN
color = 0x2E6E89;
brr = 255
}
if(i == 24) { // PURPLE
color = 0x7E3DB5;
brr = 255
}
if(i == 25) { // BROWN
color = 0x4F321F;
brr = 255
}
var col = (((color >> 16) & 0xff) * brr / 255) << 16
| (((color >> 8) & 0xff) * brr / 255) << 8
| (((color) & 0xff) * brr / 255); // adjust the noise (brr) to each rgb in the color. the color is a number between 0 and 16777215
texmap[x + y * 16 + i * 256 * 3] = col; // add to texture map
}
}
}
for(let s = 0; s < 3; s++)
for(let yy = 0; yy < 16*3; yy++)
for(let x = 0; x < 16; x++) {
var y = yy % 16
var idx = x*1 + y*16 + s*256 + 26*256*3;
texmap[idx] = ((x^y)*0x000810);
if((x-8)**2 + (y-8)**2 > 8**2) texmap[idx] &= 0;
texmap[idx] |= 0xF000000;
}
gameCanvas.requestPointerLock = gameCanvas.requestPointerLock || gameCanvas.mozRequestPointerLock || gameCanvas.webkitRequestPointerLock // functions to lock the pointer
gameCanvas.onclick = function(e) {
if(!pointLock) {
if(gameCanvas.requestPointerLock) gameCanvas.requestPointerLock() // lock the pointer
}
}
gameCanvas.onmouseup = function(e){if(e.which == 1) MD_left = false; if(e.which == 3) MD_right = false}
gameCanvas.onmousedown = function(e){if(e.which == 1) MD_left = true; if(e.which == 3) MD_right = true; clickTimer = Date.now(); HCW = 0; CantClick = 0}
mouseWheel = function(e) {
var delta = e.deltaY || e.wheelDelta
var d;
if(delta < 0) d = true // scroll up
if(delta > 0) d = false // scroll down
if(d === true) {
selectedBlock++;
if(selectedBlock >= BlockLabel.length) selectedBlock = 1;
updateCornerStr()
updates = true
}
if(d === false) {
selectedBlock--;
if(selectedBlock < 1) selectedBlock = BlockLabel.length - 1
updateCornerStr()
updates = true
}
}
if(gameCanvas.onmousewheel === null) gameCanvas.onmousewheel = mouseWheel
if(gameCanvas.onmousewheel === undefined && gameCanvas.onwheel === null) gameCanvas.onwheel = mouseWheel
gameCanvas.onmousemove = function(e) {
var canvasW = parseInt(gameCanvas.style.width.split("px")[0]);
var canvasH = parseInt(gameCanvas.style.height.split("px")[0])
MX = Math.floor((w / canvasW) * e.offsetX)
MY = Math.floor((h / canvasH) * e.offsetY)
if(!pointLock) return
var dx = -e.movementX
var dy = -e.movementY
if (dx >= 0) { //turn left
xRot -= dx*camera_move_speed;
if(xRot < 0) {
xRot = pi*2 - (Math.abs(xRot) % (pi*2))
}
}
if (dx < 0) { //turn right
xRot -= dx*camera_move_speed;
xRot %= pi*2
}
if (dy >= 0) {
if (yRot < pi / 2) {
yRot += dy*camera_move_speed;
if(!(yRot < pi / 2)) yRot = pi / 2;
} else {
yRot = pi / 2;
}
}
if (dy < 0) {
if (yRot > -pi / 2) {
yRot += dy*camera_move_speed;
if(!(yRot > -pi / 2)) yRot = -pi / 2;
} else {
yRot = -pi / 2;
}
}
updates = true
}
if ("onpointerlockchange" in document) {
document.addEventListener('pointerlockchange', lockChangeAlert, false);
} else if ("onmozpointerlockchange" in document) {
document.addEventListener('mozpointerlockchange', lockChangeAlert, false);
}
function lockChangeAlert() {
if(document.pointerLockElement === gameCanvas ||
document.mozPointerLockElement === gameCanvas) {
pointLock = true // locked
} else {
pointLock = false // unlocked
}
}
setInterval(clock, 33); // start the clock
}
var pi = Math.PI
var clickTimer; // timer updated the mouse button is clicked
var updates = true;
function clock() { //executed every frame (not in sync with renderer)
if (camdirX == 1) { //turn left
xRot -= keyboard_camera_move_speed;
if(xRot < 0) {
xRot = pi*2 - (Math.abs(xRot) % (pi*2))
}
}
if (camdirX == 2) { //turn right
xRot += keyboard_camera_move_speed;
xRot %= pi*2
}
if (camdirX == 1) { //turn left
xRot -= keyboard_camera_move_speed;
if(xRot < 0) {
xRot = pi*2 - (Math.abs(xRot) % (pi*2))
}
}
if (camdirX == 2) { //turn right
xRot += keyboard_camera_move_speed;
xRot %= pi*2
}
if (camdirY == 1) {
if (yRot < pi / 2) {
yRot += keyboard_camera_move_speed;
if(!(yRot < pi / 2)) yRot = pi / 2;
} else {
yRot = pi / 2;
}
}
if (camdirY == 2) {
if (yRot > -pi / 2) {
yRot -= keyboard_camera_move_speed;
if(!(yRot > -pi / 2)) yRot = -pi / 2;
} else {
yRot = -pi / 2;
}
}
function blockUpd(index, block, mode) {
Socket.send(JSON.stringify({
type: "block_upd",
index: index,
block: block,
mode: mode
}))
}
var updated = -1; // if player is stuck in a wall, don't delete surrounding blocks if one block is placed
if(MD_left && (pointLock || !gameCanvas.requestPointerLock) && !MD_right) {
if(var14 >= 0 && var14 <= map.length && CantClick === 0) {
map[var14] = 0
blockUpd(var14, null, 0);
CantClick = 1
}
if(Date.now() - clickTimer >= 250 && HCW === 1) {
CantClick = 0
clickTimer = Date.now()
}
if(Date.now() - clickTimer >= 500 && HCW === 0) {
CantClick = 0
HCW = 1;
clickTimer = Date.now()
}
}
if(MD_right && (pointLock || !gameCanvas.requestPointerLock) && !MD_left) {
if(var14 >= 0 && var14 <= map.length && CantClick === 0) {
map[var14 + var15] = selectedBlock
blockUpd(var14 + var15, selectedBlock, 1);
updated = var14 + var15
CantClick = 1
}
if(Date.now() - clickTimer >= 250 && HCW === 1) {
CantClick = 0
clickTimer = Date.now()
}
if(Date.now() - clickTimer >= 500 && HCW === 0) {
CantClick = 0
HCW = 1;
clickTimer = Date.now()
}
}
if(updated >= 0) {
for (var n37 = 0; n37 < 12; ++n37) { // makes sure blocks placed inside player are removed
var n38 = ((ox + (n37 >> 0 & 0x1) * 0.6 - 0.3)|0) - 1
var n39 = ((oy + ((n37 >> 2) - 1) * 0.8 + 0.65)|0) - 1
var n40 = ((oz + (n37 >> 1 & 0x1) * 0.6 - 0.3)|0) - 1
var INDEX = (n40 | 0) << 12 | (n39 | 0) << 6 | (n38 | 0)
if (n38 >= 0 && n39 >= 0 && n40 >= 0 && n38 < 64 && n39 < 64 && n40 < 64 && INDEX === updated) {
map[INDEX] = 0;
}
}
}
//gravity and hit detecion
var yCos = Math.cos(yRot);
var ySin = Math.sin(yRot);
var xCos = Math.cos(xRot);
var xSin = Math.sin(xRot);
var n24 = (W - S) * move_speed;
var n25 = (D - A) * move_speed;
var n26 = n9 * 0.5;
var n27 = n10 * 0.99;
var n28 = n11 * 0.5;
n9 = n26 + (xSin * n24 + xCos * n25);
n11 = n28 + (xCos * n24 - xSin * n25);
n10 = n27 + 0.016;
var n29 = 0;
MovePlayer: while ((n29 < 3)) { //Each loop is an axis (X, Y, Z)
var n30 = ox + n9 * (((n29 + 0) % 3 / 2 | 0));
var n31 = oy + n10 * (((n29 + 1) % 3 / 2 | 0));
var n32 = oz + n11 * (((n29 + 2) % 3 / 2 | 0));
for (var n33 = 0; n33 < 12; ++n33) {
var n34 = ((n30 + (n33 >> 0 & 1) * 0.6 - 0.3)|0) - 1
var n35 = ((n31 + ((n33 >> 2) - 1) * 0.8 + 0.65)|0) - 1
var n36 = ((n32 + (n33 >> 1 & 1) * 0.6 - 0.3)|0) - 1
if (n34 < 0 || n35 < 0 || n36 < 0 || n34 >= 64 || n35 >= 64 || n36 >= 64 || map[n36 << 12 | n35 << 6 | n34] > 0 || (Shift == 1 && n29 === 1)) { // Is there a collision?
if (n29 === 1) {
if (Jump > 0 && n10 > 0) { // if player is not in air, make player jump
n10 = -0.23;
} else {
n10 = 0;
}
}
++n29;
continue MovePlayer; //Immediately stop and go back to top of the loop (if n29 < 3)
}
}
ox = n30;
oy = n31;
oz = n32;
++n29;
}
}
window.requestAnimationFrame = window.requestAnimationFrame || window.msRequestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.oRequestAnimationFrame || function(c) {setTimeout(c, 30)}
var FrameCount = 0;
function RAF() { // Clock for rendering...
window.requestAnimationFrame(function(){
renderMinecraft()
FrameCount++
RAF()
})
}
setInterval(function(){ // set up FPS display
FPSlabel.innerText = "FPS: " + FrameCount
FrameCount = 0;
}, 1000)
RAF()
var FNT = [0,0,1,1,1,0,0,0,0,1,1,0,1,1,0,0,1,1,0,0,0,1,1,0,1,1,0,0,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,0,0,1,1,0,1,1,0,0,0,1,1,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,1,1,1,0,0,1,1,1,1,0,1,1,1,1,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] // NES font (at least from games owned by Nintendo)
var FNT_LEN = FNT.length/64; // how many characters?
//Characters: ABCDEFGHIJKLMNOPQRSTUVWXYZ,! ?.©0123456789<>????-????¦+-/~
//Camera controls
var camdirX = 0; // Left/Right
var camdirY = 0; // Up/Down
var MX, MY // Mouse positions
var move_speed_default = move_speed
var key_P = false; // the keys P and L
var key_L = false;
var debug_key = false;
window.onkeydown = function(e) {
textar.focus();
var code = e.keyCode ? e.keyCode : e.which;
if(!ChatBar) {
switch(code) {
case 32: Jump=1; break
case 16: move_speed=0.01; Shift = 1; break
case 87: W=1; break
case 83: S=1; break
case 65: A=1; break
case 68: D=1; break
case 37: camdirX=1; break
case 39: camdirX=2; break
case 38: camdirY=1; break
case 40: camdirY=2; break
case 88: move_speed=0.2; break // X to sprint
case 80: if(!key_P) {gameCanvas.onmousedown({which: 3}); key_P = true}; break // P to place block
case 76: if(!key_L) {gameCanvas.onmousedown({which: 1}); key_L = true}; break // L to break block
case 190: mouseWheel({deltaY: -1}); break;// . (>) Select next block
case 188: mouseWheel({deltaY: 1}); break // , (<) Select previous block
case 84: ChatBar = true; break;
case 71: debug_key = true
}
} else if(ChatBarBuffer.length < MaxChatLen || code == 8 || code == 13 || code == 38 || code == 37 || code == 39 || code == 220) { // add letters to chat bar
var previous = ChatBarBuffer.length
if(code >= 65 && code <= 90 && !e.ctrlKey) chatInsertChar(code-65) // a-z
if(code >= 48 && code <= 57 && !e.shiftKey) chatInsertChar(code-48 + 32) // 0-9
if(code == 32) chatInsertChar(28) // space
if(code == 190 && !e.shiftKey) chatInsertChar(30) // .
if(code == 49 && e.shiftKey) chatInsertChar(27) // !
if(code == 191 && e.shiftKey) chatInsertChar(29) // ?
if(code == 188 && !e.shiftKey) chatInsertChar(26) // ,
if(code == 188 && e.shiftKey) chatInsertChar(42) // <
if(code == 190 && e.shiftKey) chatInsertChar(43) // >
if(code == 189) chatInsertChar(55) // -
if(code == 191 && !e.shiftKey) chatInsertChar(56) // /
if(code == 192 && e.shiftKey) chatInsertChar(57) // ~
if(previous != ChatBarBuffer.length) {
incCursor()
}
if(code === 13) { // enter
processCommand(ChatBarBuffer)
PreviousChatBuffer = ChatBarBuffer.slice(0)
ChatBarBuffer = [];
ChatOffset = 0;
ChatBar = false;
CursorPosition = 0
}
if(code == 38) {
ChatBarBuffer = PreviousChatBuffer.slice(0)
CursorPosition = ChatBarBuffer.length
} // up arrow
if(code == 8) {
deleteChatChar()
} // backspace
if(code == 37) { // < arrrow
if(CursorPosition > 0) decCursor()
}
if(code == 39) { // > arrow
if(CursorPosition < ChatBarBuffer.length) incCursor()
}
if(code == 220) { // \ key
autoCompleteCommand()
}
}
};
window.onkeyup = function(e) {
var code = e.keyCode ? e.keyCode : e.which;
switch(code) {
case 32: Jump=0; break
case 16: move_speed=move_speed_default; Shift = 0; break
case 87: W=0; break
case 83: S=0; break
case 65: A=0; break
case 68: D=0; break
case 37:
case 39: camdirX=0; break
case 38:
case 40: camdirY=0; break
case 88: move_speed=move_speed_default; break
case 80: gameCanvas.onmouseup({which: 3}); key_P = false; break
case 76: gameCanvas.onmouseup({which: 1}); key_L = false; break
case 71: debug_key = false
}
};
textar.oninput = function(e) {
var tval = textar.value;
if(e.inputType == "insertFromPaste" && ChatBar) { // paste?
chatWriteText(tval.toUpperCase());
}
textar.value = "";
}
var ChatFontLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ,! ?.©0123456789<>...........-/~"
function sendChat(name, str) {
Socket.send(JSON.stringify({
type: "send_chat",
message: str,
name: name
}))
console.log("[You] " + name + ": " + str)
}
function processCommand(bufferdata) {
var string = "";
for(var i = 0; i < bufferdata.length; i++){
string += ChatFontLetters.charAt(bufferdata[i])
}
if(string == "") return;
if(string.charAt(0) != "/") {
sendChat(name, string.toLowerCase());
}
if(string.charAt(0) === "/") {
string = string.substr(1);
string = string.split(" ")
if(string[0] === "NICK") {
name = string[1]
}
if(string[0] === "CLEARALL") {
for(var x = 0; x < 64; x++){
for(var y = 0; y < 64; y++){
for(var z = 0; z < 64; z++){
var i = z << 12 | y << 6 | x;
map[i] = 0
}
}
}
}
if(string[0] === "SETBLOCK") {
var n1 = parseInt(string[1])
var n2 = parseInt(string[2])
var n3 = parseInt(string[3])
var n4 = parseInt(string[4])
setblock(n1, n2, n3, n4)
}
if(string[0] === "SPHERE") {
oy = 3;
ox = 2;
oz = 2;
for(var x = 0; x < 64; x++){
for(var y = 0; y < 64; y++){
for(var z = 0; z < 64; z++){
setblock(x,y,z,0)
}
}
}
for(var x = -32; x < 32; x++){
for(var y = -32; y < 32; y++){
for(var z = -32; z < 32; z++){
var c = x*x + y*y + z*z;
if(c <= 32*32) setblock(x+32,y+32,z+32, 3)
}
}
}
}
if(string[0] === "INVPYRAMID") {
for(var x = 0; x < 64; x++){
for(var y = 0; y < 64; y++){
for(var z = 0; z < 64; z++){
setblock(x,y,z,0)
}
}
}
for(var x = 0; x < 64; x++){
for(var y = 0; y < 32; y++){
for(var z = 0; z < 64; z++){
setblock(x,y,z,3)
}
}
}
var sd = 1;
for(var y = 31; y > 0; y--){
for(var x = sd; x < 64 - sd; x++){
for(var z = sd; z < 64 - sd; z++){
setblock(x,y,z,0)
}
}
sd++
}
}
if(string[0] === "CONVERTALL") {
var nbr = parseInt(string[1])
for(var x = 0; x < 64; x++){
for(var y = 0; y < 64; y++){
for(var z = 0; z < 64; z++){
var i = (63-z) << 12 | (63-y) << 6 | (63-x)
if(map[i] !== 0) setblock(x,y,z,nbr)
}
}
}
}
if(string[0] === "SPAWNPYRAMID") {
var rnd1 = 3 // ranges
var rnd2 = 19
var cl = (rnd2 - rnd1) // find range
var rnd = (Math.floor(Math.random()*cl)) // get random number between the ranges
if(rnd%2 === 0) rnd++ // if even number, make it odd
var yPos = (63-oy) | 0
var xPos = (63-ox) | 0 // positions of player
var zPos = (63-oz) | 0
var height = Math.ceil(rnd/2) // height of pyramid
var adj = 0 // difference of each level of pyramid
for(var y = 0; y < height; y++){
for(var x = adj; x < rnd - adj; x++){
for(var z = adj; z < rnd - adj; z++){
setblock(x + xPos+3,y+yPos+1,z+zPos+3,3) // add the block
}
}
adj++
}
}
if(string[0] === "HUGEPYRAMID") {
oy = 3
for(var x = 0; x < 64; x++){
for(var y = 0; y < 64; y++){
for(var z = 0; z < 64; z++){
setblock(x,y,z,0)
}
}
}
var sd = 0;
for(var y = 0; y < 32; y++){
for(var x = sd; x < 63 - sd; x++){
for(var z = sd; z < 63 - sd; z++){
setblock(x,y,z,3)
}
}
sd++
}
}
if(string[0] === "TELEPORT") {
var x = string[1]
var y = string[2]
var z = string[3]
var x_upd = 0;
var y_upd = 0;
var z_upd = 0;
if(x.charAt(0) === "~") {
x = x.substr(1);
if(x != "") {
x = ox - parseFloat(x)
} else {
x = ox;
}
x_upd = 1;
}
if(y.charAt(0) === "~") {
y = y.substr(1);
if(y != "") {
y = oy - parseFloat(y)
} else {
y = oy;
}
y_upd = 1;
}
if(z.charAt(0) === "~") {
z = z.substr(1);
if(z != "") {
z = oz - parseFloat(z)
} else {
z = oz;
}
z_upd = 1;
}
if(!x_upd) {
x = 63.5-parseFloat(x)
}
if(!y_upd) {
y = 63.5-parseFloat(y)
}
if(!z_upd) {
z = 63.5-parseFloat(z)
}
ox = x
oy = y
oz = z
}
if(string[0] === "NIGHT") {
Night = true;
}
if(string[0] === "DAY") {
Night = false;
}
if(string[0] === "RESET") {
for (x = 0; x < 64; x++) { // default map (grass and dirt flat-land)
for (y = 0; y < 64; y++) {
for ( var z = 0; z < 64; z++) {
i = z << 12 | y << 6 | x; // convert XYZ into index
var block = 0
if(y === 45) block = 1
if(y > 45) block = 2
map[i] = block
}
}
}
ox = 32
oy = 22
oz = 32
ox = (63.5 - ox)
oy = (63.5 - oy)
oz = (63.5 - oz)
}
if(string[0] === "MAPDEMO") {
for (x = 0; x < 64; x++) {
for (y = 0; y < 64; y++) {
for ( var z = 0; z < 64; z++) {
i = z << 12 | y << 6 | x;
var block = 0
//default map:
if(y == 34 || y == 29) {
block = Math.trunc(Math.random() * 8) + 1
}
if(((x == 0 || x == 63 || z == 0 || z == 63) && (y <= 34 && y >= 29))) {
block = 3
}
if(y == 34) block = 4
if(z == 32 && x >= 12 && x <= 34 && y <= 34 && y >= 29) block = 5
if((x % 6 === 0 && z % 6 === 0) && (y <= 34 && y >= 29)) {
block = 7
}
map[i] = block
}
}
}
ox = 32.5
oy = 31.5
oz = 42
ox = (63.5 - ox)
oy = (63.5 - oy)
oz = (63.5 - oz)
}
if(string[0] === "FILL") {
if(string.length == 8) {
var n1 = parseInt(string[1]) // x1
var n2 = parseInt(string[2]) // y1
var n3 = parseInt(string[3]) // z1
var n4 = parseInt(string[4]) // x2
var n5 = parseInt(string[5]) // y2
var n6 = parseInt(string[6]) // z2
var n7 = parseInt(string[7]) // block ID
var lenX = Math.abs(n1 - n4)
var XPOS = n1;
var lenY = Math.abs(n2 - n5)
var YPOS = n2;
var lenZ = Math.abs(n3 - n6)
var ZPOS = n3;
var XDone = 0;
var YDone = 0;
var ZDone = 0;
var startX = XPOS;
var startY = YPOS;
var startZ = ZPOS;
for(var x = 0; x <= lenX; x++){
for(var y = 0; y <= lenY; y++){
for(var z = 0; z <= lenZ; z++){
setblock(XPOS, YPOS, ZPOS, n7)
if(n3 > n6) ZPOS--
if(n3 < n6) ZPOS++
ZDone++
if(ZDone > lenZ) {
ZDone = 0;
ZPOS = startZ
}
}
if(n2 > n5) YPOS--
if(n2 < n5) YPOS++
YDone++
if(YDone > lenY) {
YDone = 0;
YPOS = startY
}
}
if(n1 > n4) XPOS--
if(n1 < n4) XPOS++
XDone++
if(XDone > lenX) {
XDone = 0;
XPOS = startX
}
}
}
}
}
}
function incCursor() {
CursorPosition++;
var relativeCurPos = CursorPosition - ChatOffset;
if(relativeCurPos > ChatWidth) {
ChatOffset++;
}
}
function decCursor() {
CursorPosition--;
var relativeCurPos = CursorPosition - ChatOffset;
if(relativeCurPos < 0) {
ChatOffset--;
}
}
function chatInsertChar(code){
var ar = [];
if(ChatBarBuffer.length > 0) {
if(CursorPosition == 0) ar.push(code)
for(var i = 0; i < ChatBarBuffer.length; i++){
ar.push(ChatBarBuffer[i])
if(i === CursorPosition - 1) ar.push(code)
}
} else {
ar = [code]
}
ChatBarBuffer = ar;
}
function deleteChatChar() {
var ar = [];
var CharRemoved = false;
for(var i = 0; i < ChatBarBuffer.length; i++){
if(i !== CursorPosition - 1) {
ar.push(ChatBarBuffer[i])
} else {
CharRemoved = true
}
}
if(CharRemoved) {
decCursor()
if(ChatOffset > 0) {
ChatOffset--;
}
}
ChatBarBuffer = ar;
}
function chatWriteText(txt) {
for(var i = 0; i < txt.length; i++){
var letter = 0
for(var g = 0; g < ChatFontLetters.length; g++){
if(ChatFontLetters.charAt(g) === txt.charAt(i)) {
letter = g;
break;
}
}
if(ChatBarBuffer.length < MaxChatLen) {
chatInsertChar(letter)
incCursor()
} else {