Enhanced syncing...
This commit is contained in:
parent
e07ee28d18
commit
0f344b7b63
2 changed files with 18 additions and 10 deletions
22
index.html
22
index.html
|
@ -39,8 +39,10 @@
|
||||||
gameState = state;
|
gameState = state;
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('shootball', function(){
|
socket.on('shootball', function(y){
|
||||||
shootBall();
|
if(ball_owner == 1) leftY = y;
|
||||||
|
if(ball_owner == 2) rightY = y;
|
||||||
|
shootBall(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Make Countdown serversided No cheating possible **/
|
/** Make Countdown serversided No cheating possible **/
|
||||||
|
@ -117,7 +119,7 @@
|
||||||
ball_maxAngle = 5*Math.PI/12;
|
ball_maxAngle = 5*Math.PI/12;
|
||||||
|
|
||||||
|
|
||||||
/** Messaure Ping and show **/
|
/** Meassure Ping and show **/
|
||||||
setInterval(function(){
|
setInterval(function(){
|
||||||
var connTime = Date.now();
|
var connTime = Date.now();
|
||||||
socket.emit('appping', function(data){
|
socket.emit('appping', function(data){
|
||||||
|
@ -297,7 +299,7 @@
|
||||||
case 37 :
|
case 37 :
|
||||||
case 39 :
|
case 39 :
|
||||||
case 65 :
|
case 65 :
|
||||||
case 68 : if(ball_owner != pid)break; socket.emit('ballshoot'); shootBall(); break;
|
case 68 : if(ball_owner != pid)break; shootBall(); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -354,12 +356,18 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function shootBall() {
|
function shootBall(sync = true) {
|
||||||
/** TODO Tewak and Add MAX_Speed **/
|
/** TODO Tewak and Add MAX_Speed **/
|
||||||
if(ball_owner == 1)
|
if(ball_owner == 1){
|
||||||
ball_VX = ball_speed;
|
ball_VX = ball_speed;
|
||||||
else if(ball_owner == 2)
|
if(!localcoop && sync)
|
||||||
|
socket.emit('ballshoot', leftY);
|
||||||
|
}
|
||||||
|
else if(ball_owner == 2){
|
||||||
ball_VX = -ball_speed;
|
ball_VX = -ball_speed;
|
||||||
|
if(!localcoop && sync)
|
||||||
|
socket.emit('ballshoot', rightY);
|
||||||
|
}
|
||||||
ball_owner = 0;
|
ball_owner = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
index.js
6
index.js
|
@ -44,10 +44,10 @@ if(gameState > 0) socket.emit('size', width, height);
|
||||||
});
|
});
|
||||||
|
|
||||||
/** #### **/
|
/** #### **/
|
||||||
/** Ping **/
|
/** Ballshoot **/
|
||||||
/** ### **/
|
/** ### **/
|
||||||
socket.on('ballshoot', function(){
|
socket.on('ballshoot', function(y){
|
||||||
socket.broadcast.emit('shootball');
|
socket.broadcast.emit('shootball', y);
|
||||||
});
|
});
|
||||||
|
|
||||||
/** ################ **/
|
/** ################ **/
|
||||||
|
|
Reference in a new issue