Double input workaround
This commit is contained in:
parent
ea18058098
commit
f701b32c45
2 changed files with 11 additions and 22 deletions
24
index.html
24
index.html
|
@ -53,6 +53,8 @@
|
||||||
leftColor = 'red',
|
leftColor = 'red',
|
||||||
rightColor = 'blue',
|
rightColor = 'blue',
|
||||||
score = [0,0],
|
score = [0,0],
|
||||||
|
pressedkeys = [],
|
||||||
|
loggedkeys = [38, 40, 83, 87],
|
||||||
gameState = 0; // 0 == Waiting for Players, 1 == Countdown, 2 == inGame, 3 == ??Win??
|
gameState = 0; // 0 == Waiting for Players, 1 == Countdown, 2 == inGame, 3 == ??Win??
|
||||||
|
|
||||||
/** Initalize Socketio **/
|
/** Initalize Socketio **/
|
||||||
|
@ -294,6 +296,8 @@
|
||||||
case 68 : if(ball_owner != 2) break; shootBall(); break;
|
case 68 : if(ball_owner != 2) break; shootBall(); break;
|
||||||
}
|
}
|
||||||
} else if(pid == 1 || pid == 2){
|
} else if(pid == 1 || pid == 2){
|
||||||
|
if(loggedkeys.indexOf(e.keyCode) > -1 && pressedkeys.indexOf(e.keyCode) < 0)
|
||||||
|
pressedkeys.push(e.keyCode);
|
||||||
switch(e.keyCode) {
|
switch(e.keyCode) {
|
||||||
case 38 :
|
case 38 :
|
||||||
case 87 : if(pid == 1){
|
case 87 : if(pid == 1){
|
||||||
|
@ -326,21 +330,11 @@
|
||||||
case 83 : setV(2, 0); break;
|
case 83 : setV(2, 0); break;
|
||||||
}
|
}
|
||||||
}else if(pid == 1 || pid == 2){
|
}else if(pid == 1 || pid == 2){
|
||||||
switch(e.keyCode) {
|
if(loggedkeys.indexOf(e.keyCode) > -1 && pressedkeys.indexOf(e.keyCode) > -1){
|
||||||
case 38 :
|
pressedkeys.splice(pressedkeys.indexOf(e.keyCode), 1);
|
||||||
case 87 : if(pid == 1){
|
console.log(pressedkeys.length);
|
||||||
setV(1, 0);
|
if(pressedkeys.length == 0) // Only send v=0 if all keys are up
|
||||||
} else if(pid == 2) {
|
setV(pid, 0);
|
||||||
setV(2, 0);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 40 :
|
|
||||||
case 83 : if(pid == 1){
|
|
||||||
setV(1, 0);
|
|
||||||
} else if(pid == 2){
|
|
||||||
setV(2, 0);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
9
index.js
9
index.js
|
@ -82,12 +82,10 @@ if(gameState > 0) socket.emit('size', width, height);
|
||||||
/** Paddel V-Change **/
|
/** Paddel V-Change **/
|
||||||
/** ############## **/
|
/** ############## **/
|
||||||
socket.on('vchange', function(pos, val, y, timestamp){
|
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...');
|
// console.log('INTERPOLATING...');
|
||||||
|
|
||||||
// var diff = ((players[pos-1].speed/tickrate)*timediff);
|
// var diff = ((players[pos-1].speed/tickrate)*timediff);
|
||||||
// if(players[pos-1].vY == 0){ // Lag from Sender (accel)
|
// if(players[pos-1].vY == 0){ // Lag from Sender (accel)
|
||||||
// if(val > 0)
|
// if(val > 0)
|
||||||
|
@ -103,9 +101,6 @@ if(gameState > 0) socket.emit('size', width, height);
|
||||||
// if(val == 0)
|
// if(val == 0)
|
||||||
// players[pos-1].y -= diff;
|
// players[pos-1].y -= diff;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
players[pos-1].vY = val;
|
|
||||||
|
|
||||||
// console.log('Diff:' + diff);
|
// console.log('Diff:' + diff);
|
||||||
// console.log('Got: ' + y + ' @ ' + timestamp);
|
// console.log('Got: ' + y + ' @ ' + timestamp);
|
||||||
// console.log('Expected:' + players[pos-1].y + ' @ ' + Date.now());
|
// console.log('Expected:' + players[pos-1].y + ' @ ' + Date.now());
|
||||||
|
|
Reference in a new issue