An FPS wouldn't be a shooter unless there's actually some shooting possible. We'll look at an example with visible, non-instant bullets. For this, we'll be able to reuse some code from Chapter 2, Cameras and Game Controls. The recipe won't describe the actual collision as this is already described in that chapter.
Perform the following steps to fire over a network:
To start off, we create a new message, called
BulletUpdateMessage
to send updates on bullet positions. It only needs two fields: aVector3f
field for position and a Boolean field for whether it's alive or not.We'll add a check in the
messageReceived
method ofServerMessageHandler
to see whether a player is firing. Any action verification we want to do should happen prior to this:if(message.getAction().equals("Fire") && message.isPressed()){ server.onFire(p); }
We find out the direction the player is facing and create a new
ServerBullet
instance. It's assigned the next available object...