This commit is contained in:
Jeremiah Billmann
2013-07-14 11:31:58 -04:00
parent 0f7e2ddcee
commit f9409434bf
3 changed files with 10 additions and 7 deletions
+4 -3
View File
@@ -7,6 +7,7 @@ function Game (sockets) {
this.physicsInterval = 15;
this.physicsDelta = this.physicsInterval / 1000;
this.physicsIntervalId = 0;
this.worldState = { height: 400, width: 800 };
this.server = garageServer.createGarageServer(sockets,
{
@@ -14,7 +15,7 @@ function Game (sockets) {
interpolation: true,
clientSidePrediction: true,
smoothingFactor: this.physicsDelta * 20,
worldState: { height: '400px', width: '800px' }
worldState: this.worldState
});
}
@@ -30,12 +31,12 @@ Game.prototype.update = function () {
self = this;
players.forEach(function (player) {
var newState = gamePhysics.getNewPlayerState(player.state, player.inputs, self.physicsDelta);
var newState = gamePhysics.getNewPlayerState(player.state, player.inputs, self.physicsDelta, self.server);
self.server.updatePlayerState(player.id, newState);
});
entities.forEach(function (entity) {
var newState = gamePhysics.getNewPlayerState(entity.state, self.physicsDelta);
var newState = gamePhysics.getNewEntityState(entity.state, self.physicsDelta);
self.server.updateEntityState(entity.id, newState);
});
};
+2 -2
View File
@@ -9,8 +9,8 @@ $(function () {
onUpdatePlayerPhysics: GamePhysics.getNewPlayerState,
onInterpolation: GamePhysics.getInterpolatedState,
onWorldState: function (state) {
document.getElementById('gameCanvas').style.width = state.width;
document.getElementById('gameCanvas').style.height = state.height;
document.getElementById('gameCanvas').style.width = state.width + 'px';
document.getElementById('gameCanvas').style.height = state.height + 'px';
}
});
GarageServerIO.setState({ x: 0, y: 0 });
+4 -2
View File
@@ -1,6 +1,6 @@
(function(exports){
exports.getNewPlayerState = function (state, inputs, deltaTime) {
exports.getNewPlayerState = function (state, inputs, deltaTime, garageServer) {
var i = 0;
if (!state.x && !state.y) {
@@ -17,7 +17,9 @@
} else if (inputs[i].input === 'up') {
state.y -= (50 * deltaTime);
} else if (inputs[i].input === 'space') {
if (garageServer) {
//garageServer.addEntity(new guid());
}
}
}
return state;