Game Development Reference
In-Depth Information
rotate(-floatValue);
}
17. In the overridden controlUpdate method, we then modify the position and
rotation of the spatial based on the input, just like we did in the Creating a reus-
able character control recipe of Chapter 2 , Cameras and Game Controls .
The client is simple in many ways, since it basically only does two things. It takes a play-
er's input, sends it to the server, receives updates from the server, and applies them as fol-
lows:
1. We begin by creating a new class called FPSClient extending SimpleAp-
plication .
2. In the constructor, we read the network properties file and connect to the server,
as follows:
Properties prop = new Properties();
prop.load(getClass().getClassLoader().getResourceAsStream("network/
resources/network.properties"));
client =
Network.connectToServer(prop.getProperty("server.name"),
Integer.parseInt(prop.getProperty("server.version")),
prop.getProperty("server.address"),
Integer.parseInt(prop.getProperty("server.port")));
3. Just as with the server, we register all the message classes before launching the
application.
4. The application should have a reference to a Node class called playerModel ,
which will be the visual representation of the players in the game. There should
also be a ClientPlayerControl class called thisPlayer .
5. In the simpleInitApp method, we attach InputAppState . This has the
same functionality as the one in the Creating an input AppState object recipe of
Chapter 2 , Cameras and Game Controls . The only difference is it will benefit
from having a direct way of reaching the client to send messages:
public void simpleInitApp() {
InputAppState inputAppState = new InputAppState();
inputAppState.setClient(this);
stateManager.attach(inputAppState);
Search WWH ::




Custom Search