From f9409434bf0fa6aa29bd14228f1953b74079ed0e Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Sun, 14 Jul 2013 11:31:58 -0400 Subject: [PATCH] Progress #3 --- example/game.js | 7 ++++--- example/public/javascripts/game.js | 4 ++-- example/shared/core.js | 6 ++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/example/game.js b/example/game.js index 12852ad..ef11c94 100644 --- a/example/game.js +++ b/example/game.js @@ -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); }); }; \ No newline at end of file diff --git a/example/public/javascripts/game.js b/example/public/javascripts/game.js index eb2efaf..a2be212 100644 --- a/example/public/javascripts/game.js +++ b/example/public/javascripts/game.js @@ -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 }); diff --git a/example/shared/core.js b/example/shared/core.js index 6b0c05c..20a00cb 100644 --- a/example/shared/core.js +++ b/example/shared/core.js @@ -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;