Game Development Reference
In-Depth Information
update.setId(bullet.getId());
update.setPosition(bullet.getWorldPosition());
update.setAlive(bullet.isAlive());
server.broadcast(update);
if(!bullet.isAlive()){
bullets.remove(bullet);
nrOfBullets--;
i--;
}
}
5. In a for loop, we first update the bullet, and then create a new BulletUp-
dateMessage , which is sent to all players. If the bullet is out of range, it is re-
moved from the list. This is implemented as follows:
if (m instanceof BulletUpdateMessage){
BulletUpdateMessage update = (BulletUpdateMessage)
m;
ClientBullet bullet =
gameClient.getBullet(update.getId());
if(bullet == null){
bullet = gameClient.createBullet(update.getId());
}
bullet.setPosition(update.getPosition());
if(!update.isAlive()){
gameClient.removeBullet(update.getId(),
bullet.getSpatial());
}
}
6. On the client side, we write a new method that creates a new bullet, once it re-
ceives information from the server:
public ClientBullet createBullet(int id){
final ClientBullet bulletControl = new
ClientBullet();
final Spatial g = assetManager.loadModel("Models/
Banana/banana.j3o");
g.rotate(FastMath.nextRandomFloat(),
FastMath.nextRandomFloat(),
Search WWH ::




Custom Search