From 223cf154c88b1d7c505c3e378fa56c6f0f30efd1 Mon Sep 17 00:00:00 2001 From: "LAPTOP-NN6DMM7E\\Jim" Date: Sat, 7 Jul 2018 01:24:55 +1000 Subject: [PATCH 01/14] nomouse.html --- index.html | 74 +++++++++++++++++++++ nomouse.html | 180 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 254 insertions(+) create mode 100644 index.html create mode 100644 nomouse.html diff --git a/index.html b/index.html new file mode 100644 index 00000000..609a1006 --- /dev/null +++ b/index.html @@ -0,0 +1,74 @@ + + + + WebCraft + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/nomouse.html b/nomouse.html new file mode 100644 index 00000000..18eacdd4 --- /dev/null +++ b/nomouse.html @@ -0,0 +1,180 @@ + + + + WebCraft + + + + + + + + + + + + + + + + + + + + + +
+ fdgfdshgfdgfdgfdsgdg +
+ Click to play +
+ (W, A, S, D = Move, SPACE = Jump, MOUSE = Look around) +
+
+ + + + + + + + +
+ + + + + \ No newline at end of file From fae0470a512b148100f1e024d939f0aadebdca23 Mon Sep 17 00:00:00 2001 From: "LAPTOP-NN6DMM7E\\Jim" Date: Sat, 7 Jul 2018 20:14:41 +1000 Subject: [PATCH 02/14] hide cursor --- js/player.js | 53 ++++++++++++---- js/setting.json | 4 ++ js/sight.js | 165 ++++++++++++++++++++++++++++++++++++++++++++++++ nomouse.html | 95 ++-------------------------- 4 files changed, 214 insertions(+), 103 deletions(-) create mode 100644 js/setting.json create mode 100644 js/sight.js diff --git a/js/player.js b/js/player.js index 90144b62..8e946f46 100644 --- a/js/player.js +++ b/js/player.js @@ -33,6 +33,8 @@ Player.prototype.setWorld = function( world ) this.keys = {}; this.buildMaterial = BLOCK.DIRT; this.eventHandlers = {}; + this.targetPitch = 0; + this.targetYaw = 0; } // setClient( client ) @@ -57,9 +59,13 @@ Player.prototype.setInputCanvas = function( id ) document.onkeyup = function( e ) { if ( e.target.tagName != "INPUT" ) { t.onKeyEvent( e.keyCode, false ); return false; } } canvas.onmousedown = function( e ) { t.onMouseEvent( e.clientX, e.clientY, MOUSE.DOWN, e.which == 3 ); return false; } canvas.onmouseup = function( e ) { t.onMouseEvent( e.clientX, e.clientY, MOUSE.UP, e.which == 3 ); return false; } - canvas.onmousemove = function( e ) { t.onMouseEvent( e.clientX, e.clientY, MOUSE.MOVE, e.which == 3 ); return false; } + + //canvas.onmousemove = function (e) {t.onMouseEvent(e.clientX, e.clientY, MOUSE.MOVE, e.which == 3); return false;} + + // Hook mouse move events + document.addEventListener("mousemove", function (e) {t.onMouseEvent(e.movementX, e.movementY, MOUSE.MOVE, e.which == 3);return false;}, false); + document.addEventListener("click", function( e ) { t.onMouseEvent( window.innerWidth/2, window.innerHeight/2, MOUSE.UP, e.which == 3 ); }); } - // setMaterialSelector( id ) // // Sets the table with the material selectors. @@ -118,7 +124,8 @@ Player.prototype.onKeyEvent = function( keyCode, down ) this.keys[key] = down; this.keys[keyCode] = down; - if ( !down && key == "t" && this.eventHandlers["openChat"] ) this.eventHandlers.openChat(); + if (!down && key == "t" && this.eventHandlers["openChat"]) this.eventHandlers.openChat(); + } // onMouseEvent( x, y, type, rmb ) @@ -126,26 +133,41 @@ Player.prototype.onKeyEvent = function( keyCode, down ) // Hook for mouse input. Player.prototype.onMouseEvent = function( x, y, type, rmb ) -{ +{ console.log("click1 " + type); if ( type == MOUSE.DOWN ) { + this.dragStart = { x: x, y: y }; this.mouseDown = true; this.yawStart = this.targetYaw = this.angles[1]; this.pitchStart = this.targetPitch = this.angles[0]; } else if ( type == MOUSE.UP ) { - if ( Math.abs( this.dragStart.x - x ) + Math.abs( this.dragStart.y - y ) < 4 ) - this.doBlockAction( x, y, !rmb ); + + //if ( Math.abs( this.dragStart.0 - x ) + Math.abs( this.dragStart.y - y ) < 4 ) + this.doBlockAction( x, y, !rmb ); this.dragging = false; this.mouseDown = false; this.canvas.style.cursor = "default"; - } else if ( type == MOUSE.MOVE && this.mouseDown ) { - this.dragging = true; - this.targetPitch = this.pitchStart - ( y - this.dragStart.y ) / 200; - this.targetYaw = this.yawStart + ( x - this.dragStart.x ) / 200; - this.canvas.style.cursor = "move"; } + + if (type == MOUSE.MOVE) { + this.dragging = true; + + var result = this.targetPitch - y / 1000; + if(result < Math.PI/2 && result > -Math.PI/2) + { + this.targetPitch -= y / 1000; + } + + + this.targetYaw += x / 1000; + //console.log(this.targetPitch + " " + ); + + this.canvas.style.cursor = "move"; + } + + } // doBlockAction( x, y ) @@ -154,17 +176,22 @@ Player.prototype.onMouseEvent = function( x, y, type, rmb ) Player.prototype.doBlockAction = function( x, y, destroy ) { + var bPos = new Vector( Math.floor( this.pos.x ), Math.floor( this.pos.y ), Math.floor( this.pos.z ) ); var block = this.canvas.renderer.pickAt( new Vector( bPos.x - 4, bPos.y - 4, bPos.z - 4 ), new Vector( bPos.x + 4, bPos.y + 4, bPos.z + 4 ), x, y ); - + if ( block != false ) { + var obj = this.client ? this.client : this.world; if ( destroy ) + { + console.log("setBlock" +" "+ block.x +" "+ block.y +" "+ block.z); obj.setBlock( block.x, block.y, block.z, BLOCK.AIR ); - else + }else{ obj.setBlock( block.x + block.n.x, block.y + block.n.y, block.z + block.n.z, this.buildMaterial ); + } } } diff --git a/js/setting.json b/js/setting.json new file mode 100644 index 00000000..a2dcb27d --- /dev/null +++ b/js/setting.json @@ -0,0 +1,4 @@ +{ + "isMouse": false, + +} \ No newline at end of file diff --git a/js/sight.js b/js/sight.js new file mode 100644 index 00000000..f91a98c3 --- /dev/null +++ b/js/sight.js @@ -0,0 +1,165 @@ +function Sight() +{ +} + +Sight.prototype.init = function() +{ + var a =` + + + + + + +
+ +
+ Click to play +
+ (W, A, S, D = Move, left click to destroy block, right click to place block) +
+ +
+ +
+
+ + `; + //wirte the html code above + document.write(a); + + //get the html element + var blocker = document.getElementById( 'blocker' ); + var instructions = document.getElementById( 'instructions' ); + + //this two div element is the front sight on the center of screen + var sight1 = document.getElementById( 'sight1' ); + var sight2 = document.getElementById( 'sight2' ); + blocker.style.display = 'block'; + sight1.style.display = 'none'; + sight2.style.display = 'none'; + // http://www.html5rocks.com/en/tutorials/pointerlock/intro/ + + var havePointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document; + + if ( !havePointerLock ) + { + instructions.innerHTML = 'Your browser doesn\'t seem to support Pointer Lock API'; + return null; + } + + var element = document.body; + + var pointerlockchange = function ( event ) { + + if ( document.pointerLockElement === element || document.mozPointerLockElement === element || document.webkitPointerLockElement === element ) { + + blocker.style.display = 'none'; + sight1.style.display = 'block'; + sight2.style.display = 'block'; + + } else { + + blocker.style.display = 'block'; + sight1.style.display = 'none'; + sight2.style.display = 'none'; + instructions.style.display = ''; + + } + + }; + + var pointerlockerror = function ( event ) { + + instructions.style.display = ''; + + }; + + // Hook pointer lock state change events + document.addEventListener( 'pointerlockchange', pointerlockchange, false ); + document.addEventListener( 'mozpointerlockchange', pointerlockchange, false ); + document.addEventListener( 'webkitpointerlockchange', pointerlockchange, false ); + + document.addEventListener( 'pointerlockerror', pointerlockerror, false ); + document.addEventListener( 'mozpointerlockerror', pointerlockerror, false ); + document.addEventListener( 'webkitpointerlockerror', pointerlockerror, false ); + + instructions.addEventListener( 'click', function ( event ) + { + + instructions.style.display = 'none'; + + // Ask the browser to lock the pointer + element.requestPointerLock = element.requestPointerLock || element.mozRequestPointerLock || element.webkitRequestPointerLock; + element.requestPointerLock(); + + }, false ); +} \ No newline at end of file diff --git a/nomouse.html b/nomouse.html index 18eacdd4..344a0408 100644 --- a/nomouse.html +++ b/nomouse.html @@ -17,6 +17,7 @@ + @@ -34,96 +35,7 @@ overflow: hidden; font-family: arial; } - - #blocker { - position: absolute; - width: 100%; - height: 100%; - background-color: rgba(0,0,0,0.5); - z-index : 3; - } - - #instructions { - width: 100%; - height: 100%; - display: -webkit-box; - display: -moz-box; - display: box; - -webkit-box-orient: horizontal; - -moz-box-orient: horizontal; - box-orient: horizontal; - -webkit-box-pack: center; - -moz-box-pack: center; - box-pack: center; - -webkit-box-align: center; - -moz-box-align: center; - box-align: center; - color: #ffffff; - text-align: center; - cursor: pointer; - } - -
- fdgfdshgfdgfdgfdsgdg -
- Click to play -
- (W, A, S, D = Move, SPACE = Jump, MOUSE = Look around) -
-
- - + @@ -135,6 +47,9 @@ - - - - - - - - - - - - - - - -
- - - - - \ No newline at end of file diff --git a/js/player.js b/js/player.js index 915ed557..36345e10 100644 --- a/js/player.js +++ b/js/player.js @@ -56,8 +56,8 @@ Player.prototype.setInputCanvas = function( id ) var t = this; - //document.onkeydown = function( e ) { if ( e.target.tagName != "INPUT" ) { t.onKeyEvent( e.keyCode, true ); return false; } } - //document.onkeyup = function( e ) { if ( e.target.tagName != "INPUT" ) { t.onKeyEvent( e.keyCode, false ); return false; } } + document.onkeydown = function( e ) { if ( e.target.tagName != "INPUT" ) { t.onKeyEvent( e.keyCode, true ); return false; } } + document.onkeyup = function( e ) { if ( e.target.tagName != "INPUT" ) { t.onKeyEvent( e.keyCode, false ); return false; } } //canvas.onmousedown = function( e ) { t.onMouseEvent( e.clientX, e.clientY, MOUSE.DOWN, e.which == 3 ); return false; } //canvas.onmouseup = function( e ) { t.onMouseEvent( e.clientX, e.clientY, MOUSE.UP, e.which == 3 ); return false; } //canvas.onmousemove = function (e) {t.onMouseEvent(e.clientX, e.clientY, MOUSE.MOVE, e.which == 3); return false;} diff --git a/nomouse.html b/nomouse.html deleted file mode 100644 index d05c9290..00000000 --- a/nomouse.html +++ /dev/null @@ -1,95 +0,0 @@ - - - - WebCraft - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - \ No newline at end of file diff --git a/singleplayer.html b/singleplayer.html index 609a1006..7ca88602 100644 --- a/singleplayer.html +++ b/singleplayer.html @@ -17,6 +17,7 @@ + @@ -29,7 +30,11 @@ - + @@ -32,6 +33,9 @@ - @@ -33,9 +32,6 @@ + @@ -32,6 +33,9 @@