The Bird's-Eye View

The BirdsEye object displays a static image representing the maze as seen from above, and it draws an arrow on top of it to show the user's current position. As the user moves and turns, so does the arrow. If the user hits a wall, then the message "BANG!" appears (see Figure 25-12).

The bird's-eye view pane

Figure 25-12. The bird's-eye view pane

The arrow switches between four different images, shown in Figure 25-13.

Arrows as a clock

Figure 25-13. Arrows as a clock

Figure 25-13 shows the arrows laid out in a circle, labeled with their filenames and numbers (e.g., the down arrow is in arrowFwd.gif and is assigned number 0). The numbering scheme is used to quickly switch between the different arrows when the viewpoint is rotated.

These images are loaded into arrowIms[] at start time, indexed by the numbers shown in Figure 25-13. For instance, arrowIms[0] contains the image from arrowFwd.gif:

 private static final int NUM_DIRS = 4; private static final int FORWARD = 0; private static final int LEFT = 1; private static final int BACK = 2; private static final int RIGHT = 3; Image[] arrowIms = new Image[NUM_DIRS]; arrowIms[FORWARD] = new ImageIcon("images/arrowFwd.gif").getImage(); arrowIms[LEFT] = new ImageIcon("images/arrowLeft.gif").getImage(); arrowIms[BACK] = new ImageIcon("images/arrowBack.gif").getImage(); ...

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.