Chapter 18. 3D Sprites
In this chapter, I'll develop a Sprite3D
class, which can be subclassed to create different kinds of sprites. The user's sprite (a robot) and a chasing sprite (a hand) are shown in action in Figure 18-1 sharing the checkerboard with some scenery (a palm tree and castle) and obstacles (the red poles).
Figure 18-1. 3D sprites in action
Features illustrated by the Tour3D
application include:
- Sprite behavior
The sprites are controlled by
Behavior
subclasses.- A third-person camera
A simple third-person camera automatically adjusts the user's viewpoint as the user's sprite moves around the scene. The camera can be zoomed in and out by keyboard controls.
- Obstacles
The scene contains obstacles that a sprite can't pass through. (They're represented by cylinders in Figure 18-1.) Sprites are prevented from moving off the checkered floor.
- Collision detection
Collision detection between a sprite and the obstacles is implemented by bounds checking.
- Scenery configuration
A "tour" text file loaded at start time contains obstacle and scenery information. The scenery models (e.g., the castle and the palm tree in this example) are loaded with
PropManager
objects.- A background image
The scene's background is drawn using a scaled JPEG.
- Full-screen display
The application is configured to be full-screen.
Class Diagrams for Tour3D
Figure 18-2 shows class diagrams for Tour3D
. Only class ...
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.