mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-04 17:20:40 +08:00
Completed #3
This commit is contained in:
+5
-3
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user