From fbbc072f6f726128ecb62a8209dd0572d6902924 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Sun, 14 Jul 2013 16:45:09 -0400 Subject: [PATCH] Completed #3 --- example/game.js | 8 +++++--- src/server/garageserver.io.js | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/example/game.js b/example/game.js index ea22e47..a1909e0 100644 --- a/example/game.js +++ b/example/game.js @@ -35,13 +35,15 @@ Game.prototype.update = function () { self.server.updatePlayerState(player.id, newState); }); - entities.forEach(function (entity) { - var newState = gamePhysics.getNewEntityState(entity.state, self.physicsDelta); + for (var i = entities.length - 1; i >= 0; i--) { + var entity = entities[i], + newState = gamePhysics.getNewEntityState(entity.state, self.physicsDelta); + if (newState.x < 0 - self.worldState.playerSize || newState.y < 0 - self.worldState.playerSize || newState.x > self.worldState.width || newState.y > self.worldState.height) { self.server.removeEntity(entity.id); } else { self.server.updateEntityState(entity.id, newState); } - }); + } }; \ No newline at end of file diff --git a/src/server/garageserver.io.js b/src/server/garageserver.io.js index c81db35..64e656c 100644 --- a/src/server/garageserver.io.js +++ b/src/server/garageserver.io.js @@ -18,6 +18,7 @@ options = { */ function GarageServer(socketio, options) { + this.socketPath = '/garageserver.io'; this.io = socketio; this.game = new garageServerGame(options); this.registerSocketEvents(options); @@ -26,7 +27,7 @@ function GarageServer(socketio, options) { GarageServer.prototype.registerSocketEvents = function (options) { var self = this; - self.io.of('/garageserver.io').on('connection', function (socket) { + self.io.of(self.socketPath).on('connection', function (socket) { if (options.logging) { console.log('garageserver.io:: socket ' + socket.id + ' connection'); } @@ -122,7 +123,7 @@ GarageServer.prototype.addEntity = function (id) { }; GarageServer.prototype.removeEntity = function (id) { - this.io.sockets.emit('removeEntity', id); + this.io.of(this.socketPath).emit('removeEntity', id); this.game.removeEntity(id); };