This commit is contained in:
Jeremiah Billmann
2013-07-14 16:45:09 -04:00
parent b8b9869522
commit fbbc072f6f
2 changed files with 8 additions and 5 deletions
+5 -3
View File
@@ -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);
}
});
}
};
+3 -2
View File
@@ -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);
};