Skip to Main Content
Killer Game Programming in Java
book

Killer Game Programming in Java

by Andrew Davison
May 2005
Intermediate to advanced content levelIntermediate to advanced
998 pages
26h
English
O'Reilly Media, Inc.
Content preview from Killer Game Programming in Java

Scene Creation

WrapFlocking3D is like previous Wrap classes in that it creates a 3D scene inside a JPanel, made up of a checkerboard floor, blue sky, lighting, and an OrbitBehavior node to allow the user to adjust the viewpoint.

The additions are the obstacles and the two flocks, both created in addFlockingBoids():

    private void addFlockingBoids(int numPreds, int numPrey, int numObs)
    { // create obstacles
      Obstacles obs = new Obstacles(numObs);
      sceneBG.addChild( obs.getObsBG() );  // add obstacles to scene
   
      // make the predator manager
      PredatorBehavior predBeh = new PredatorBehavior(numPreds, obs);
      predBeh.setSchedulingBounds(bounds);
      sceneBG.addChild( predBeh.getBoidsBG() );  // add preds to scene
   
      // make the prey manager
      PreyBehavior preyBeh = new PreyBehavior(numPrey, obs);
      preyBeh.setSchedulingBounds(bounds);
      sceneBG.addChild( preyBeh.getBoidsBG() );  // add prey to scene
   
      // tell behaviors about each other
      predBeh.setPreyBeh( preyBeh );
      preyBeh.setPredBeh( predBeh );
   
    } // end of addFlockingBoids()

The number of predators, prey, and obstacles are read from the command line in Flocking3D or are assigned default values. The behaviors are passed references to each other so their steering rules can consider neighboring boids of the other type. Here's a typical call to Flocking3D:

    java Flocking3D 10 200 15

This will make addFlockingBoids() create 10 predators, 200 prey, and 15 obstacles.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Game Development with LibGDX: From Beginner to Professional

Java Game Development with LibGDX: From Beginner to Professional

Lee Stemkoski

Publisher Resources

ISBN: 0596007302Supplemental ContentErrata Page