diff --git a/index.html b/index.html index 23aedd6..a3c946b 100644 --- a/index.html +++ b/index.html @@ -53,6 +53,8 @@ leftColor = 'red', rightColor = 'blue', score = [0,0], + pressedkeys = [], + loggedkeys = [38, 40, 83, 87], gameState = 0; // 0 == Waiting for Players, 1 == Countdown, 2 == inGame, 3 == ??Win?? /** Initalize Socketio **/ @@ -294,6 +296,8 @@ case 68 : if(ball_owner != 2) break; shootBall(); break; } } else if(pid == 1 || pid == 2){ + if(loggedkeys.indexOf(e.keyCode) > -1 && pressedkeys.indexOf(e.keyCode) < 0) + pressedkeys.push(e.keyCode); switch(e.keyCode) { case 38 : case 87 : if(pid == 1){ @@ -326,21 +330,11 @@ case 83 : setV(2, 0); break; } }else if(pid == 1 || pid == 2){ - switch(e.keyCode) { - case 38 : - case 87 : if(pid == 1){ - setV(1, 0); - } else if(pid == 2) { - setV(2, 0); - } - break; - case 40 : - case 83 : if(pid == 1){ - setV(1, 0); - } else if(pid == 2){ - setV(2, 0); - } - break; + if(loggedkeys.indexOf(e.keyCode) > -1 && pressedkeys.indexOf(e.keyCode) > -1){ + pressedkeys.splice(pressedkeys.indexOf(e.keyCode), 1); + console.log(pressedkeys.length); + if(pressedkeys.length == 0) // Only send v=0 if all keys are up + setV(pid, 0); } } }); diff --git a/index.js b/index.js index 3592279..433e9c1 100644 --- a/index.js +++ b/index.js @@ -82,12 +82,10 @@ if(gameState > 0) socket.emit('size', width, height); /** Paddel V-Change **/ /** ############## **/ socket.on('vchange', function(pos, val, y, timestamp){ - var timediff = Date.now()-timestamp; - - + players[pos-1].vY = val; + // NOTE Interpolation not needed // console.log('INTERPOLATING...'); - // var diff = ((players[pos-1].speed/tickrate)*timediff); // if(players[pos-1].vY == 0){ // Lag from Sender (accel) // if(val > 0) @@ -103,9 +101,6 @@ if(gameState > 0) socket.emit('size', width, height); // if(val == 0) // players[pos-1].y -= diff; // } - - players[pos-1].vY = val; - // console.log('Diff:' + diff); // console.log('Got: ' + y + ' @ ' + timestamp); // console.log('Expected:' + players[pos-1].y + ' @ ' + Date.now());