Game Development Reference
In-Depth Information
PlayerJoinMessage joinMessage = (PlayerJoinMessage) m;
int playerId = joinMessage.getPlayerId();
if(joinMessage.isLeaving()){
gameClient.removePlayer((ClientPlayerControl)
game.getPlayer(playerId));
game.removePlayer(playerId);
} else if(game.getPlayer(playerId) == null){
ClientPlayerControl p =
gameClient.createPlayer(joinMessage.getPlayerId());
game.addPlayer(p);
}
5. When the PlayerUpdateMessage is received, we first find the corresponding
ClientPlayerControl class and pass on the message to it, as follows:
} else if (m instanceof PlayerUpdateMessage){
PlayerUpdateMessage updateMessage =
(PlayerUpdateMessage) m;
int playerId = updateMessage.getPlayerId();
ClientPlayerControl p = (ClientPlayerControl)
game.getPlayer(playerId);
if(p != null){
p.onMessageReceived(updateMessage);
}
Search WWH ::




Custom Search