Skip to content
Browse files

Working on visualising new players

  • Loading branch information...
1 parent 20225fc commit b5353aeb509d0d2aa62478ffbce11c1a3c21f28f @robhawkes robhawkes committed Jun 4, 2011
Showing with 14 additions and 1 deletion.
  1. +6 −0 public/js/game/client.js
  2. +1 −0 public/js/game/kaboom.player.js
  3. +3 −0 public/js/game/kaboom.socket.js
  4. +4 −1 server.js
View
6 public/js/game/client.js
@@ -115,6 +115,12 @@ KaboomClient.prototype = {
if (player) {
player.copyStateFrom(playerState);
};
+ },
+
+ playerJoined : function(playerState) {
+ console.log(playerState);
+ window.game.addPlayer(new KaboomPlayer().copyStateFrom(playerState));
+ console.log(window.game.players);
}
};
View
1 public/js/game/kaboom.player.js
@@ -53,6 +53,7 @@ KaboomPlayer.prototype = {
this.name = that.name;
this.position = new Position(that.position.x, that.position.y);
this.velocity = new Velocity(that.velocity.dx, that.velocity.dy);
+ return this;
}
};
View
3 public/js/game/kaboom.socket.js
@@ -51,6 +51,9 @@ KaboomSocket.prototype = {
case "player_changed_velocity":
this.client.playerChangedVelocity(msg.playerState);
break;
+ case "player_joined":
+ this.client.playerJoined(msg.playerState);
+ break;
};
};
},
View
5 server.js
@@ -59,12 +59,15 @@ function setSocketHandlers() {
//console.log(client.sessionId);
var output = JSON.stringify({type: "welcome", gameState: runningGame, playerState: player});
client.send(output);
+
+ var playerJoinedMessage = JSON.stringify({type: "player_joined", playerState: player});
+ client.broadcast(playerJoinedMessage);
+
break;
case "player_changed_velocity":
if (msg.player )
{
- console.log(msg);
runningGame.playerChangedVelocity(msg.player);
var output = JSON.stringify({type: "player_changed_velocity", playerState: msg.player });

0 comments on commit b5353ae

Please sign in to comment.
Something went wrong with that request. Please try again.