Making a Maze Plan


Chapter 25. A 3D Maze

The main contributions of the first-person shooter (FPS) in Chapter 24 were a moving viewpoint (controlled by key presses), the use of a 2D image to simulate a gun hand, and the ability to shoot multiple laser beams at once, generating multiple explosions. Though the user could move about, there wasn't any scenery (except the robot target).

This chapter continues the FPS theme but concentrates on letting the user navigate through a complex, realistic looking scene (a 3D maze) without walking through walls or getting too lost:


Key-based navigation

I'll be reusing (with a few changes) the KeyBehavior class from Chapter 24, so the navigation is again controlled from the keyboard. The user can move forward, backward, slide left or right, float up or down but can't walk through walls or descend through the floor. Rotations are limited to 90-degree turns to the left or right, which simplifies the application's position calculations.


A realistic scene

The scene is a 3D maze made from textured, colored blocks and cylinders. The floor is tiled with a texture to make it look more detailed. The background is a textured sphere, which means that the sky looks different when viewed from different locations in the scene. The lighting is deliberately gloomy (there's no ambient light), but a Java 3D Spotlight node is attached to the viewpoint, so the user appears to be carrying a spotlight.


Multiple views to aid navigation

The application offers three views of the maze. The main application panel shows the user's forward facing view (I call this the main camera), a smaller panel displays the view directly behind the user (the back facing camera), and a third panel offers a schematic overview of the entire maze with the user represented by an arrow pointing in the current forward direction (the bird's-eye view). Multiple views are essential in gaming, especially an overview of the entire scene.


Viewpoint adjustments

The viewpoint's field of view (FOV) is widened, so the user can see more of the scene. I adjust the viewpoint's forward and back clip distances, so the player can move close to the maze's blocks and cylinders and still see them.


Using a maze plan

The maze plan is generated by a separate application, which stores it as an ASCII file. The file is read in by the Maze3D application at startup time to generate the 3D structures, create the schematic overview, and use the plan in collision detection code. The utilization of a separate plan allows the maze to be changed quickly and easily.

Figure 25-1shows a screenshot of the application, Maze3D, which consists of three JPanels. The lefthand side shows the main camera, the top-right panel is the back facing camera, and the bottom-right panel is the bird's-eye view.

Figure 25-1. Navigating the 3D maze




Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net