Managing the Maze

MazeManager reads in a maze plan and generates two maze representations: a 3D subgraph added to the scene by WrapMaze3D and a 2D image employed by BirdsEye as the background for its moving arrow. The primary aim of MazeManager is to hide the processing of the maze plan from the rest of the application. In addition to serving up 3D and 2D mazes, MazeManager contains the coordinates of the user's starting point and deals with collision detection between the player and the maze walls. MazeManager's readFile() initializes maze[][] by reading in the ASCII maze plan, and buildMazeReps() creates the on-screen mazes.

When buildMazeReps() creates the 3D maze, it has to translate the indices in maze[][] into (x, y, z) coordinates for the blocks and cylinders. The first assumption is that every block and cylinder is standing on the floor, so their y-coordinates are 0. Then, the row's indices of maze[][] are treated as z-axis values and the columns as x-axis values. For example, if maze[3][5] contains a b, then a block will be placed at (5, 0, 3) in the scene.

This approach means that the top-left corner of the maze is located at (0, 0, 0) in the scene, and the rest of the maze extends over the positive XZ quadrant.

When buildMazeReps() generates the 2D image, it continues to treat the columns of maze[][] as x-axis numbers, but the rows are viewed as y-axis values. For example, if maze[3][5] contains a b, then a blue square will be drawn at the coordinate (5, 3) in the image. ...

Get Killer Game Programming in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.