This commit is contained in:
Jeremiah Billmann
2013-07-05 23:36:56 -04:00
parent a50d759c25
commit e321124aa0
+22 -12
View File
@@ -13,25 +13,35 @@ function GarageServerGame(options) {
}
GarageServerGame.prototype.updateState = function (options) {
var currentTime = new Date().getTime() - this.startTime;
this.updatePlayers(currentTime, options);
this.updateEntities(currentTime, options);
};
var currentTime = new Date().getTime() - this.startTime,
state = { time: currentTime, playerStates: [], entityStates: [] };
GarageServerGame.prototype.updatePlayers = function (currentTime, options) {
var state = { time: currentTime, playerStates: [], entityStates: [] };
this.players.forEach(function (player) {
state.playerStates.push([ player.client.id, player.state, player.sequence ]);
});
state.playerStates = this.updatePlayers();
state.entityStates = this.updateEntities();
this.players.forEach(function (player) {
player.client.emit('update', state);
});
};
GarageServerGame.prototype.updateEntities = function (currentTime, options) {
GarageServerGame.prototype.updatePlayers = function () {
var states = [];
this.players.forEach(function (player) {
states.push([ player.client.id, player.state, player.sequence ]);
});
return states;
};
GarageServerGame.prototype.updateEntities = function () {
var states = [];
this.entities.forEach(function (entity) {
states.push([ entity.id, entity.state, entity.sequence ]);
});
return states;
};
GarageServerGame.prototype.updatePhysics = function (options) {