Refactoring client side prediction for players to make for consistent API calls with client side prediction for entities (#20)

This commit is contained in:
Jeremiah Billmann
2015-05-20 00:59:05 +00:00
parent bd341f5f0c
commit e96adda2c2
4 changed files with 31 additions and 16 deletions
+9 -8
View File
@@ -52,19 +52,20 @@ GarageServerIO.initializeGarageServer('http://insertmygameserverurlhere.com', {
onReady: function () {
// Call your game loop
},
onUpdatePlayerPrediction: function (state, inputs, deltaTime) {
onUpdateClientPredictionReady: function (playerId, playerCurrentState, inputs, deltaTime) {
var newState = {};
if (!player.state.x) {
player.state.x = 0;
if (!playerCurrentState.x) {
playerCurrentState.x = 0;
}
for (i = 0; i < player.inputs.length; i ++) {
if (player.inputs[i].input === 'left') {
newState.x = player.state.x - (50 * deltaTime);
for (i = 0; i < inputs.length; i ++) {
if (inputs[i].input === 'left') {
newState.x = playerCurrentState.x - (50 * deltaTime);
} else if (inputs[i].input === 'right') {
newState.x = player.state.x + (50 * deltaTime);
newState.x = playerCurrentState.x + (50 * deltaTime);
}
}
return newState;
GarageServerIO.updatePlayerState(playerid, newState);
},
onInterpolation: function (previousState, targetState, amount) {
return { x: (previousState.x + amount * (targetState.x - previousState.x)) };