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

WrapShooter3D's createSceneGraph() calls makeGun() to initialize various elements:

    private void makeGun(Canvas3D canvas3D)
    { // starting vector for the gun cone and beam
      Vector3d startVec = new Vector3d(0, 2, 0);
   
      // the gun
      GunTurret gun = new GunTurret(startVec);
      sceneBG.addChild( gun.getGunBG() );
   
      // explosion and sound
      PointSound explPS = initSound("Explo1.wav");
      ExplosionsClip expl = new ExplosionsClip( startVec, explPS);
      sceneBG.addChild( expl.getExplBG() );
   
      // laser beam and sound
      PointSound beamPS = initSound("laser2.wav");
      LaserBeam laser = new LaserBeam( startVec, beamPS);
      sceneBG.addChild( laser.getBeamBG() );
   
      // the behavior that controls the shooting
      ShootingBehaviour shootBeh =
          new ShootingBehaviour(canvas3D, sceneBG, bounds,
                        new Point3d(0,2,0), expl, laser, gun );
      sceneBG.addChild(shootBeh);
    } // end of makeGun()

The position vector of the gun cone is hardwired to be (0, 2, 0). The same vector is used to place the laser beam (a red cylinder) inside the cone. The hardwiring makes the coding easier and highlights a major simplification of this example: the base of the gun doesn't move.

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