From d676f72e19c85e67a47e5d432ecddd4f1bc78f76 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Sat, 1 Jun 2013 14:57:04 -0400 Subject: [PATCH] Progress: Client Updates --- client/garageserver.io.js | 8 +++----- example/public/javascripts/game.js | 2 -- lib/server/garageservergame.js | 6 +++--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/client/garageserver.io.js b/client/garageserver.io.js index 9f6b482..830ba3c 100644 --- a/client/garageserver.io.js +++ b/client/garageserver.io.js @@ -8,8 +8,6 @@ window.GarageServerIO = (function (window, socketio) { players = [], - inputs = [], - updates = [], // TODO: DONE CALLBACK @@ -36,11 +34,11 @@ window.GarageServerIO = (function (window, socketio) { addPlayerInput = function (input) { sequenceNumber += 1; - inputs.push({ input: input, seq: sequenceNumber }); + sendPlayerInput(input); }, - sendPlayerInput = function () { - + sendPlayerInput = function (input) { + socket.emit('input', { input: input, seq: sequenceNumber }); }, removePlayer = function (id) { diff --git a/example/public/javascripts/game.js b/example/public/javascripts/game.js index 8623df0..316f202 100644 --- a/example/public/javascripts/game.js +++ b/example/public/javascripts/game.js @@ -30,8 +30,6 @@ $(function () { y -= 1; GarageServerIO.addPlayerInput('up'); } - - GarageServerIO.sendPlayerInput(); }, update = function () { diff --git a/lib/server/garageservergame.js b/lib/server/garageservergame.js index 19dce3d..0971bcc 100644 --- a/lib/server/garageservergame.js +++ b/lib/server/garageservergame.js @@ -29,7 +29,7 @@ GarageServerGame.prototype.updatePhysics = function (options) { GarageServerGame.prototype.addPlayer = function (client) { for(var i = 0; i < this.players.length; i ++) { - if(this.players[i].id === client.id) { + if(this.players[i].client.id === client.id) { return; } } @@ -46,7 +46,7 @@ GarageServerGame.prototype.addPlayer = function (client) { GarageServerGame.prototype.removePlayer = function (client) { for(var i = 0; i < this.players.length; i ++) { - if(this.players[i].id === client.id) { + if(this.players[i].client.id === client.id) { this.players.splice(i, 1)[0]; return; } @@ -55,7 +55,7 @@ GarageServerGame.prototype.removePlayer = function (client) { GarageServerGame.prototype.addPlayerInput = function (client, input) { for(var i = 0; i < this.players.length; i ++) { - if(this.players[i].id === client.id) { + if(this.players[i].client.id === client.id) { this.players[i].inputs.push(input); return; }