Progress: Client

This commit is contained in:
Jeremiah Billmann
2013-05-23 21:03:21 -04:00
parent 18cef256e1
commit 3f888c7935
3 changed files with 32 additions and 4 deletions
+30 -4
View File
@@ -11,11 +11,18 @@ window.GarageServerIO = (function (window, socketio) {
registerSocketEvents = function () {
io.on('update', function(data) {
if(garageServerGame.addPlayerInput) {
garageServerGame.addPlayerInput(data);
}
});
io.on('ping', function(data) {
});
io.on('removePlayer', function(id) {
if(garageServerGame.removePlayer) {
garageServerGame.removePlayer(id);
}
});
},
startGarageServerGame = function (options) {
@@ -23,15 +30,34 @@ window.GarageServerIO = (function (window, socketio) {
};
function GarageServerGame (options) {
this.players = [];
this.updates = [];
}
GarageServerGame.prototype.update = function () {
GarageServerGame.prototype.addPlayerInput = function (input) {
this.updates.push(input);
};
GarageServerGame.prototype.sendPlayerInput = function (input) {
};
GarageServerGame.prototype.removePlayer = function (id) {
for(var i = 0; i < this.players.length; i ++) {
if(this.players[i].id === id) {
this.players.splice(i, 1)[0];
return;
}
}
};
GarageServerGame.prototype.updatePlayers = function () {
};
return {
connectToGarageServer: connectToGarageServer
connectToGarageServer: connectToGarageServer,
startGarageServerGame: startGarageServerGame
};
}) (window, io);
+1
View File
@@ -39,6 +39,7 @@ GarageServer.prototype.onPlayerConnect = function (socket, options) {
GarageServer.prototype.onPlayerDisconnect = function (socket, options) {
this.game.removePlayer(socket);
socket.broadcast.emit('removePlayer', socket.id);
if(options.onPlayerDisconnect) {
options.onPlayerDisconnect(socket);
}
+1
View File
@@ -48,6 +48,7 @@ GarageServerGame.prototype.removePlayer = function (client) {
for(var i = 0; i < this.players.length; i ++) {
if(this.players[i].id === client.id) {
this.players.splice(i, 1)[0];
return;
}
}
};