Game Development Reference
In-Depth Information
game.getPlayer(message.getPlayerId());
p.onMessageReceived(message);
}
}
13. For the server-side implementation of the NetworkedPlayerControl class,
we extend it to a new class called ServerPlayerControl .
14. Similar to the GameCharacterControl class from Chapter 2 , Cameras and
Game Controls , we will use a set of Booleans to keep track of the input, as fol-
lows:
boolean forward = false, backward = false, leftRotate
= false, rightRotate = false, leftStrafe = false,
rightStrafe = false;
15. In the implemented onMessageReceived method, listen for PlayerMes-
sages . We don't know if it will contain Boolean or float values, so we look for
both, as follows:
public void onMessageReceived(PlayerMessage message) {
if(message instanceof PlayerActionMessage){
String action = ((PlayerActionMessage)
message).getAction();
boolean value = ((PlayerActionMessage)
message).isPressed();
float floatValue = ((PlayerActionMessage)
message).getFloatValue();
16. Then, we apply the values as shown in the following code snippet:
if (action.equals("StrafeLeft")) {
leftStrafe = value;
} else if (action.equals("StrafeRight")) {
rightStrafe = value;
}
...
else if (action.equals("RotateLeft")) {
rotate(floatValue);
} else if (action.equals("RotateRight")) {
Search WWH ::




Custom Search