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

Moving the Viewpoint

This chapter's KeyBehavior class is similar to the one described in Chapter 24, since both control the user's viewpoint. They both extend ViewPlatformBehavior, so they can access the ViewPlatform's TransformGroup. They both use the same key presses to trigger movement and rotation.

Movement can be forward, backward, left, right, up, or down, by one unit step, excluding jaunts through the walls or floor. Rotations are carried out in 90-degree turns left or right, which simplifies the implementation of the BirdsEye class. BirdsEye's main task is to calculate the position and orientation of an arrow drawn on top of the overview image when the viewpoint moves or rotates.

KeyBehavior is complicated by being involved in the manipulation of two cameras and the BirdsEye view. The movement/rotation of the cameras are done inside KeyBehavior by affecting their TransformGroups, but the BirdsEye object carries out its own changes. These additional responsibilities can be seen in standardMove() that calls the moveBy() and doRotateY() methods with extra arguments for the extra views:

    private void standardMove(int keycode)
    {
      if(keycode == forwardKey)
        moveBy(VFWD, FORWARD, VBACK);
      else if(keycode == backKey)
        moveBy(VBACK, BACK, VFWD);
      else if(keycode == leftKey)
        doRotateY(ROT_AMT, LEFT);
      else if(keycode == rightKey)
        doRotateY(-ROT_AMT, RIGHT);
    }

The arguments of moveBy() are constants related to the main camera, the bird's-eye view, and the back facing camera. When the main camera ...

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