Progress: Server loops & player input;

This commit is contained in:
Jeremiah Billmann
2013-05-21 20:19:27 -04:00
parent 8516041c8b
commit a5b072955f
2 changed files with 15 additions and 4 deletions
+6 -4
View File
@@ -27,26 +27,28 @@ GarageServer.prototype.registerSocketEvents = function (options) {
console.log('garageserver.io:: socket ping');
self.onPlayerInput(socket, options);
});
});
};
GarageServer.prototype.onPlayerConnect = function (socket, options) {
this.game.addPlayer(socket);
if(options.onPlayerConnect) {
options(socket);
options.onPlayerConnect(socket);
}
};
GarageServer.prototype.onPlayerDisconnect = function (socket, options) {
this.game.removePlayer(socket);
if(options.onPlayerDisconnect) {
options(socket);
options.onPlayerDisconnect(socket);
}
};
GarageServer.prototype.onPlayerInput = function (socket, input, options) {
this.game.addPlayerInput(socket, input);
if(options.onPlayerInput) {
options.onPlayerInput(socket, input);
}
};
GarageServer.prototype.onPing = function(socket, options) {
+9
View File
@@ -36,6 +36,15 @@ 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) {
this.players[i].inputs.push(input);
return;
}
}
};
exports.createGame = function (options){
return new GarageServerGame(options);
};