Killer Game Programming in Java

Book description

Although the number of commercial Java games is still small compared to those written in C or C++, the market is expanding rapidly. Recent updates to Java make it faster and easier to create powerful gaming applications-particularly Java 3D-is fueling an explosive growth in Java games. Java games like Puzzle Pirates, Chrome, Star Wars Galaxies, Runescape, Alien Flux, Kingdom of Wars, Law and Order II, Roboforge, Tom Clancy's Politika, and scores of others have earned awards and become bestsellers.Java developers new to graphics and game programming, as well as game developers new to Java 3D, will find Killer Game Programming in Java invaluable. This new book is a practical introduction to the latest Java graphics and game programming technologies and techniques. It is the first book to thoroughly cover Java's 3D capabilities for all types of graphics and game development projects.Killer Game Programming in Java is a comprehensive guide to everything you need to know to program cool, testosterone-drenched Java games. It will give you reusable techniques to create everything from fast, full-screen action games to multiplayer 3D games. In addition to the most thorough coverage of Java 3D available, Killer Game Programming in Java also clearly details the older, better-known 2D APIs, 3D sprites, animated 3D sprites, first-person shooter programming, sound, fractals, and networked games. Killer Game Programming in Java is a must-have for anyone who wants to create adrenaline-fueled games in Java.

Publisher resources

View/Submit Errata

Table of contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. Who Are You?
    2. What This Book Is About
    3. This Book (and More) Is Online
    4. What This Book Is Not About
    5. A Graphical View of This Book
      1. 2D Programming
      2. 3D Programming
      3. Network Programming
      4. The Appendixes
    6. Conventions Used in This Book
    7. Using Code Examples
    8. Comments and Questions
    9. Safari Enabled
    10. Acknowledgments
  3. 1. Why Java for Games Programming?
    1. 1.1. Java Is Too Slow for Games Programming
      1. 1.1.1. Swing Is Slow
      2. 1.1.2. My Program Is Slow Because of Java
    2. 1.2. Java Has Memory Leaks
    3. 1.3. Java Is Too High-level
    4. 1.4. Java Application Installation Is a Nightmare
    5. 1.5. Java Isn’t Supported on Games Consoles
    6. 1.6. No One Uses Java to Write Real Games
      1. 1.6.1. Freeware/Shareware Games
    7. 1.7. Sun Microsystems Isn’t Interested in Supporting Java Gaming
  4. 2. An Animation Framework
    1. 2.1. Animation as a Threaded Canvas
      1. 2.1.1. Synchronization Concerns
      2. 2.1.2. Application and Game Termination
      3. 2.1.3. Why Use Volatile?
      4. 2.1.4. Why Sleep?
      5. 2.1.5. Double Buffering Drawing
      6. 2.1.6. Adding User Interaction
    2. 2.3. Converting to Active Rendering
    3. 2.4. FPS and Sleeping for Varying Times
      1. 2.4.1. Timer Resolution
      2. 2.4.2. Am I Done Yet? (Nope)
      3. 2.4.3. Improved J2SE Timers
      4. 2.4.4. Using Non-J2SE Timers
      5. 2.4.5. Measuring Timer Resolution
      6. 2.4.6. Java 3D Timer Bug Alert
    4. 2.5. Sleeping Better
      1. 2.5.1. Handling Sleep Inaccuracies
    5. 2.6. FPS and UPS
      1. 2.6.1. Separating Updates from Rendering
    6. 2.7. Pausing and Resuming
    7. 2.8. Other Animation Approaches
      1. 2.8.1. Swing Timer Animation
      2. 2.8.2. The Utility Timer
  5. 3. Worms in Windows and Applets
    1. 3.1. Preliminary Considerations
      1. 3.1.1. The Choice of Timer
      2. 3.1.2. Class Reuse
      3. 3.1.3. Testing for Speed
    2. 3.2. Class Diagrams for the WormChase Application
    3. 3.3. The Worm-Chasing Application
    4. 3.4. The Game Panel
      1. 3.4.1. User Input
      2. 3.4.2. The Animation Loop
      3. 3.4.3. Statistics Gathering
      4. 3.4.4. Drawing the Canvas
    5. 3.5. Storing Worm Information
      1. 3.5.1. Growing a Worm
      2. 3.5.2. Calculating a New Head Point
      3. 3.5.3. Choosing a Bearing
      4. 3.5.4. Dealing with Obstacles
      5. 3.5.5. Moving the Worm
      6. 3.5.6. Drawing the Worm
      7. 3.5.7. Testing the Worm
    6. 3.6. Worm Obstacles
    7. 3.7. Application Timing Results
      1. 3.7.1. Timing Results Using currentTimeMillis()
    8. 3.8. WormChase as an Applet
      1. 3.8.1. The WormChaseApplet Class
      2. 3.8.2. The WormPanel Class
      3. 3.8.3. Timing Results
    9. 3.9. Compilation in J2SE 5.0
      1. 3.9.1. What Is a Type-Safe Collection?
      2. 3.9.2. Dealing with Raw Types in J2SE 5.0
  6. 4. Full-Screen Worms
    1. 4.1. An Almost Full-Screen (AFS) Worm
      1. 4.1.1. The AFS WormChase Class
      2. 4.1.2. Stopping Window Movement
      3. 4.1.3. Timings for AFS
    2. 4.2. An Undecorated Full-Screen (UFS) Worm
      1. 4.2.1. The UFS WormChase Class
      2. 4.2.2. The Game Panel
      3. 4.2.3. Button Behavior
      4. 4.2.4. Drawing the Game Canvas
      5. 4.2.5. Exiting the Game
      6. 4.2.6. Timings for UFS
    3. 4.3. A Full-Screen Exclusive Mode (FSEM) Worm
      1. 4.3.1. The FSEM WormChase Class
      2. 4.3.2. Setting Up Full-Screen Exclusive Mode
      3. 4.3.3. Double Buffering, Page Flipping, and More
      4. 4.3.4. Rendering the Game
      5. 4.3.5. Finishing Off
      6. 4.3.6. Displaying the Display Mode
      7. 4.3.7. Changing the Display Mode
      8. 4.3.8. Timings for FSEM
    4. 4.4. Timings at 80 to 85 FPS
  7. 5. An Introduction to Java Imaging
    1. 5.1. Image Formats
    2. 5.2. The AWT Imaging Model
      1. 5.1.1. The MediaTracker Class
      2. 5.1.2. ImageIcon
      3. 5.1.3. The Rise of JARs
      4. 5.1.4. AWT Image Processing
    3. 5.3. An Overview of Java 2D
      1. 5.2.1. The Graphics2D Class
      2. 5.2.2. Java 2D and Active Rendering
    4. 5.4. Buffering an Image
      1. 5.4.1. From Image to BufferedImage
      2. 5.4.2. The Internals of BufferedImage
      3. 5.4.3. BufferedImageOp Operations
    5. 5.5. Managed Images
    6. 5.6. VolatileImage
    7. 5.7. Java 2D Speed
    8. 5.8. Portability and Java 2D
    9. 5.9. JAI
  8. 6. Image Loading, Visual Effects, and Animation
    1. 6.1.  
      1. 6.1.1. Class Diagrams for the Application
    2. 6.2. Loading Images
      1. 6.2.1. Internal Data Structures
      2. 6.2.2. Getting an Image
      3. 6.2.3. Using ImagesLoader
      4. 6.2.4. Implementation Details
      5. 6.2.5. Image Loading
      6. 6.2.6. Loading Strip File Images
    3. 6.3. Applying Image Effects
      1. 6.3.1. Starting ImagesTests
      2. 6.3.2. Initializing Images
      3. 6.3.3. Updating the Images
      4. 6.3.4. Painting the Images
      5. 6.3.5. Information on Accelerated Memory
    4. 6.4. Displaying Image Sequences
      1. 6.4.1. Implementation Details
    5. 6.5. Visual Effects for ‘o’ Images
      1. 6.5.1. Precalculation Is Faster
      2. 6.5.2. drawImage()-Based Processing
      3. 6.5.3. Alpha Compositing
      4. 6.5.4. Affine Transforms
      5. 6.5.5. ConvolveOp Processing
      6. 6.5.6. LookupOp Processing
      7. 6.5.7. RescaleOp Processing
        1. 6.5.7.1. Brightening the image
        2. 6.5.7.2. Negating the image
      8. 6.5.8. BandCombineOp Processing
      9. 6.5.9. Pixel Effects
        1. 6.5.8.1. Teleporting an image
        2. 6.5.8.2. Zapping an image
    6. 6.6. Packaging the Application as a JAR
  9. 7. Introducing Java Sound
    1. 7.1. Applet Playing
    2. 7.2. The AudioClip Class
    3. 7.3. The Sound Player
    4. 7.4. The Java Sound API
    5. 7.5. Sampled Audio
      1. 7.5.1. The Mixer
      2. 7.5.2. Playing a Clip
      3. 7.5.3. Short Sound Bug in J2SE 5.0
      4. 7.5.4. Playing a Buffered Sample
    6. 7.6. MIDI
      1. 7.6.1. A MIDI Sequence
      2. 7.6.2. Playing a MIDI Sequence
    7. 7.7. Java Sound API Compared with JMF and JOAL
    8. 7.8. Java Sound API Resources
    9. 7.9. Audio Resources
  10. 8. Loading and Playing Sounds
    1. 8.1. Loader Design and Implementation Issues
    2. 8.2. Testing the Loaders
      1. 8.2.1. Watching the Loaders
      2. 8.2.2. Termination
      3. 8.2.3. The Listener Methods
    3. 8.3. The Sounds Panel
    4. 8.4. The Clips Loader
      1. 8.4.1. Playing Clips
    5. 8.5. Storing Clip Information
      1. 8.5.1. Stopping Clips
      2. 8.5.2. Pausing and Resuming Clips
      3. 8.5.3. Handing Line Events
    6. 8.6. The Midi Sequences Loader
      1. 8.6.1. Playing Sequences
      2. 8.6.2. Pausing and Resuming Sequences
      3. 8.6.3. Stopping Sequences
      4. 8.6.4. Closing Sequences
    7. 8.7. Storing Midi Information
      1. 8.7.1. Stopping Sequences
      2. 8.7.2. Pausing and Resuming Sequences
    8. 8.8. LoadersTests as a JAR File
  11. 9. Audio Effects
    1. 9.1. Audio Effects on Sampled Audio
      1. 9.1.1. Precalculation
      2. 9.1.2. Byte Array Manipulation
        1. 9.1.2.1. Making a sound clip echo
        2. 9.1.2.2. Playing
      3. 9.1.3. Utilizing Mixer Controls
        1. 9.1.3.1. Adjusting a clip’s volume and pan values
        2. 9.1.3.2. What controls are available?
        3. 9.1.3.3. Java audio controls
        4. 9.1.3.4. Setting the volume in PlaceClip
        5. 9.1.3.5. Panning between the speakers in PlaceClip
    2. 9.2. Audio Effects on MIDI Sequences
      1. 9.2.1. Precalculation
      2. 9.2.2. Sequence Manipulation
        1. 9.2.2.1. Doubling the sequence volume
      3. 9.2.3. MIDI Channel Controllers
        1. 9.2.3.1. Making a sequence fade away
        2. 9.2.3.2. Getting and setting the volume
        3. 9.2.3.3. Changing the volume
        4. 9.2.3.4. The MIDI volume bug
        5. 9.2.3.5. Panning the sequence
        6. 9.2.3.6. Changing the pan value
      4. 9.2.4. Sequencer Methods
  12. 10. Audio Synthesis
    1. 10.1. Sampled Audio Synthesis
      1. 10.1.1. Note Names
      2. 10.1.2. Playing a Note
      3. 10.1.3. Synthesizing Notes
        1. 10.1.3.1. Creating samples
        2. 10.1.3.2. Extending NotesSynth
    2. 10.2. MIDI Synthesis
      1. 10.2.1. Sending Note-Playing Message to a MIDI Channel
      2. 10.2.2. Sending MIDI Messages to the Synthesizer’s Receiver Port
        1. 10.2.2.1. Control change messages
      3. 10.2.3. Creating a Sequence
        1. 10.2.3.1. Instruments and soundbanks
        2. 10.2.3.2. Listing instruments
        3. 10.2.3.3. Making a sequence
        4. 10.2.3.4. Playing the sequence
        5. 10.2.3.5. The add() methods
        6. 10.2.3.6. Changing an instrument
        7. 10.2.3.7. Program and bank change
        8. 10.2.3.8. From note name to MIDI number
        9. 10.2.3.9. Extending SeqSynth
    3. 10.3. Audio Synthesis Libraries
  13. 11. Sprites
    1. 11.1. Bats, Balls, and Sprites
    2. 11.2. Class Diagrams for BugRunner
    3. 11.3. The Bug Starts Running
    4. 11.4. The Animation Framework
      1. 11.4.1. User Interaction
      2. 11.4.2. The Animation Loop
      3. 11.4.3. Finishing the Game
    5. 11.5. Defining a Sprite
    6. 11.6. Coding a Sprite
      1. 11.6.1. The Sprite Constructor
      2. 11.6.2. A Sprite’s Image
      3. 11.6.3. A Sprite’s Bounding Box
      4. 11.6.4. Updating a Sprite
      5. 11.6.5. Drawing a Sprite
    7. 11.7. Specifying a Sprite with a Statechart
      1. 11.7.1. Translating a Statechart to Code
    8. 11.8. The Ball Sprite
      1. 11.8.1. Textual Specification
      2. 11.8.2. Statechart Specification
      3. 11.8.3. Translating the Statechart
        1. 11.8.3.1. Updating the sprite
        2. 11.8.3.2. Hitting a wall
        3. 11.8.3.3. Leaving the screen
        4. 11.8.3.4. Drawing the sprite
    9. 11.9. Defining the Bat
      1. 11.9.1. Textual Specification
      2. 11.9.2. Statechart Specification
      3. 11.9.3. Translating the Statechart
        1. 11.9.3.1. User-based reactions
        2. 11.9.3.2. Mouse responses
        3. 11.9.3.3. Time-based reactions
        4. 11.9.3.4. Concurrently shared data
  14. 12. A Side-Scroller
    1. 12.1. JumpingJack in Layers
    2. 12.2. Class Diagrams for JumpingJack
    3. 12.3. Start Jack Jumping
    4. 12.4. The Animation Framework
      1. 12.4.1. Dealing with Input
      2. 12.4.2. Multiple Key Presses/Actions
      3. 12.4.3. The Animation Loop
        1. 12.4.3.1. Rendering order
      4. 12.4.4. Handling an Explosion
    5. 12.5. Managing the Ribbons
    6. 12.6. Wraparound Ribbons
      1. 12.6.1. Drawing the Ribbon’s Image
        1. 12.6.1.1. Case 1: Draw the image at JPanel (0,0)
        2. 12.6.1.2. Case 2: Image moving right, where xImHead is less than pWidth
        3. 12.6.1.3. Case 3: Image moving right, where xImHead is greater than or equal to pWidth
        4. 12.6.1.4. Case 4: Image moving left, where xImHead is greater than or equal to (pWidth-width)
        5. 12.6.1.5. Case 5. Image moving left, where xImHead is less than (pWidth-width)
    7. 12.7. Managing the Bricks
      1. 12.7.1. Loading Bricks Information
      2. 12.7.2. Initializing the Bricks Data Structures
      3. 12.7.3. Moving the Bricks Map
      4. 12.7.4. Drawing the Bricks
        1. 12.7.4.1. Case 1. Bricks map moving right and bCoord is less than pWidth
        2. 12.7.4.2. Case 2. Bricks map moving right and bCoord is greater than pWidth
        3. 12.7.4.3. Case 3. Bricks map moving left and bCoord is greater than (pWidth-width+imWidth)
        4. 12.7.4.4. Case 4. Bricks map moving left and bCoord is less than (pWidth-width+ imWidth)
        5. 12.7.4.5. The drawBricks() method
      5. 12.7.5. JumperSprite-Related Methods
        1. 12.7.5.1. Finding the floor
        2. 12.7.5.2. Testing for brick collision
        3. 12.7.5.3. Jumping and hitting your head
        4. 12.7.5.4. Falling and sinking into the ground
    8. 12.8. Storing Brick Information
    9. 12.9. The Fireball
      1. 12.9.1. Statechart Specification
    10. 12.10. The Jumping Sprite
      1. 12.10.1. Statechart Specification
      2. 12.10.2. Representing the States
      3. 12.10.3. Initialization
      4. 12.10.4. Key Event Processing
      5. 12.10.5. JackPanel Collision Testing
      6. 12.10.6. Updating the Sprite
        1. 12.10.6.1. Falling?
      7. 12.10.7. Vertical Movement
    11. 12.11. Other Side-Scroller Examples
    12. 12.12. Tiling Software
  15. 13. An Isometric Tile Game
    1. 13.1. Isometric Tiles
      1. 13.1.1. Movement
      2. 13.1.2. Placing a Sprite/Object
      3. 13.1.3. The Tile Map Surface
      4. 13.1.4. The Aliens
    2. 13.2. Class Diagrams for AlienTiles
    3. 13.3. The Animation Framework
      1. 13.3.1. Managing the Game World
      2. 13.3.2. Dealing with Input
      3. 13.3.3. The Animation Loop
      4. 13.3.4. Ending the Game
    4. 13.4. Managing the World
      1. 13.4.1. Loading Floor Information
        1. 13.4.1.1. Storing floor data
        2. 13.4.1.2. Creating obstacles
      2. 13.4.2. Loading World Entity Information
      3. 13.4.3. Pickup Methods
      4. 13.4.4. Player Methods
      5. 13.4.5. Drawing the World
    5. 13.5. Managing WorldItems
      1. 13.5.1. Adding an Entity
      2. 13.5.2. Drawing Entities
      3. 13.5.3. Pickup Methods
    6. 13.6. The Tile Occupier
      1. 13.6.1. Additional Sprite Information
      2. 13.6.2. Drawing a Tile Occupier
    7. 13.7. A Sprite on a Tile
      1. 13.7.1. Moving to Another Tile
    8. 13.8. The Player Sprite
      1. 13.8.1. Moving (and Standing Still)
      2. 13.8.2. Drawing the Player
      3. 13.8.3. Being Hit by an Alien
      4. 13.8.4. Trying to Pick Up a Pickup
    9. 13.9. The Alien Sprite
      1. 13.9.1. Updating the AlienSprite
    10. 13.10. The Quadrant-Based Alien Sprite
      1. 13.10.1. Planning a Move
      2. 13.10.2. Moving the AlienQuadSprite
    11. 13.11. The A*-Based Alien Sprite
      1. 13.11.1. Planning a Move
      2. 13.11.2. The A* Algorithm
      3. 13.11.3. Moving the AlienAStarSprite
    12. 13.12. Storing Tile Details
      1. 13.12.1. Calculating the Cost to the Goal
    13. 13.13. Further Reading
      1. 13.13.1. A* Information
  16. 14. Introducing Java 3D
    1. 14.1. Java 3D
      1. 14.1.1. DirectX or OpenGL?
      2. 14.1.2. The Scene Graph
        1. 14.1.2.1. Some Java 3D scene graph nodes
        2. 14.1.2.2. The HelloUniverse scene graph
    2. 14.2. Java 3D Strengths
      1. 14.2.1. The Scene Graph
      2. 14.2.2. Performance
      3. 14.2.3. Unique Features
      4. 14.2.4. Java Integration
      5. 14.2.5. Documentation and Examples
    3. 14.3. Criticisms of Java 3D for Games Programming
      1. 14.3.1. Java 3D Is Too Slow for Games
        1. 14.3.1.1. Java 3D is slow because Java is slow
      2. 14.3.2. Java 3D Is Too High-Level
      3. 14.3.3. Lack of Console Support
      4. 14.3.4. No Real Java 3D Games
        1. 14.3.4.1. Java 3D loaders for games
        2. 14.3.4.2. Add-ons for gaming
      5. 14.3.5. Sun Doesn’t Support Java 3D
        1. 14.3.5.1. Roadmaps for the future
    4. 14.4. Alternatives to Java 3D
      1. 14.4.1. Java Bindings to OpenGL
        1. 14.4.1.1. GL4Java
        2. 14.4.1.2. Lightweight Java Game Library (LWJGL)
        3. 14.4.1.3. JOGL
      2. 14.4.2. Scene Graph APIs
        1. 14.4.2.1. Xith3D
        2. 14.4.2.2. OpenMind
        3. 14.4.2.3. jME graphics engine
        4. 14.4.2.4. Jist3D
        5. 14.4.2.5. JiD
        6. 14.4.2.6. Aviatrix3D
        7. 14.4.2.7. Kahlua
        8. 14.4.2.8. jFree-D2
      3. 14.4.3. Game Engine Bindings
        1. 14.4.3.1. Auriga3D
        2. 14.4.3.2. Jake2
        3. 14.4.3.3. Ogre4J
        4. 14.4.3.4. Jirr
        5. 14.4.3.5. Odejava
  17. 15. A 3D Checkerboard: Checkers3D
    1. 15.1. Class Diagrams for Checkers3D
    2. 15.2. Integrating Java 3D and Swing
    3. 15.3. Scene Graph Creation
      1. 15.3.1. Lighting the Scene
      2. 15.3.2. The Scene’s Background
    4. 15.4. Floating Spheres
      1. 15.4.1. Coloring the Spheres
      2. 15.4.2. Positioning the Spheres
    5. 15.5. The Floor
      1. 15.5.1. The Colored Tiles
      2. 15.5.2. The Floor’s Axis Labels
    6. 15.6. Viewer Positioning
    7. 15.7. Viewer Movement
    8. 15.8. Viewing the Scene Graph
  18. 16. Loading and Manipulating External Models
    1. 16.1. An Overview of LoaderInfo3D
    2. 16.2. Loaders in Java 3D
      1. 16.2.1. Using NCSA Portfolio Loaders
    3. 16.3. Displaying a Model
      1. 16.3.1. Scaling the Model
    4. 16.4. Examining a Model’s Scene Graph
      1. 16.4.1. Graph Traversal Output
    5. 16.5. Adjusting a Model’s Shape Attributes
      1. 16.5.1. Turning the Shape Blue
      2. 16.5.2. Drawing a Shape in Outline
      3. 16.5.3. Making a Shape Almost Transparent
      4. 16.5.4. Adding a Texture to a Shape
        1. 16.5.4.1. Texture coordinates
        2. 16.5.4.2. A tendency to strip
        3. 16.5.4.3. Applying the texture to the shape
    6. 16.6. An Overview of Loader3D
    7. 16.7. Using Loader3D
    8. 16.8. Creating the Scene
    9. 16.9. Managing the Model
    10. 16.10. Building the Model’s Scene Graph
      1. 16.10.1. Loading the Model
      2. 16.10.2. Loading and Applying the Coords Data
      3. 16.10.3. Handling Rotation
        1. 16.10.3.1. Applying the rotation
      4. 16.10.4. Making the Model Available
      5. 16.10.5. Modifying the Model’s Configuration at Runtime
  19. 17. Using a Lathe to Make Shapes
    1. 17.1. Class Diagrams for Lathe3D
    2. 17.2. Creating the Scene
      1. 17.2.1. Shapes with Curves and Lines
      2. 17.2.2. Shapes with Colors
      3. 17.2.3. Different Curve Rotations
    3. 17.3. The Lathe Curve
      1. 17.3.1. Specifying Curve Segments
      2. 17.3.2. Implementation
      3. 17.3.3. Calculating the Tangents
      4. 17.3.4. Building the Entire Curve
    4. 17.4. The Lathe Shape
      1. 17.4.1. Creating the Geometry
      2. 17.4.2. You Say You Want a Revolution
      3. 17.4.3. Creating Texture Coordinates
      4. 17.4.4. A Thin Problem
      5. 17.4.5. Making an Appearance
    5. 17.5. Subclassing the Lathe Shape
      1. 17.5.1. An Elliptical Shape
      2. 17.5.2. A Rhodonea Shape
  20. 18. 3D Sprites
    1. 18.1. Class Diagrams for Tour3D
    2. 18.2. Creating the Scene
      1. 18.2.1. Adding a Background Image
      2. 18.2.2. Full-Screen Display
      3. 18.2.3. Adding Scenery and Obstacles
      4. 18.2.4. Obstacles
    3. 18.3. The Basic 3D Sprite
      1. 18.3.1. Visibility
      2. 18.3.2. Movement and Rotation
      3. 18.3.3. Obstacle and Boundary Detection
      4. 18.3.4. Updating the Sprite
    4. 18.4. The User’s Touring Sprite
    5. 18.5. The Alien Sprite
    6. 18.6. Behaviors in Java 3D
    7. 18.7. Controlling the Touring Sprite
      1. 18.7.1. What’s a Third-Person Camera?
      2. 18.7.2. Setting Up TouristControls
      3. 18.7.3. Keys Understood by TouristControls
      4. 18.7.4. Viewpoint Initialization
      5. 18.7.5. Moving the Camera
      6. 18.7.6. Zooming the Camera
      7. 18.7.7. Rotating the Camera
    8. 18.8. Updating the Alien Sprite
  21. 19. Animated 3D Sprites
    1. 19.1.  
      1. 19.1.1. Keyframe Animation in This Chapter
    2. 19.2. Class Diagrams for AnimTour3D
    3. 19.3. Creating the Scene
    4. 19.4. The Animated 3D Sprite
      1. 19.4.1. Loading the Poses
      2. 19.4.2. Where Did These Models Come From?
      3. 19.4.3. Setting a Pose
      4. 19.4.4. Sprite Activity
      5. 19.4.5. Floor Boundary Detection
    5. 19.5. Controlling the Sprite
    6. 19.6. Animating the Sprite
      1. 19.6.1. Adding an Animation Sequence
      2. 19.6.2. Processing an Animation Operation
      3. 19.6.3. Updating the User’s Viewpoint
    7. 19.7. Full-Screen Exclusive Mode (FSEM)
    8. 19.8. A Full-Screen Version of the Application
      1. 19.8.1. Creating the Full-Screen Scene
      2. 19.8.2. Changing the Display Mode
    9. 19.9. Pros and Cons of Keyframe Animation
  22. 20. An Articulated, Moveable Figure
    1. 20.1. The Articulated Figure Application
      1. 20.1.1. Building the Figure
    2. 20.2. Forward and Inverse Kinematics
      1. 20.2.1. Forward Kinematics in Mover3D
    3. 20.3. Class Diagrams for Mover3D
    4. 20.4. Creating the Scene
    5. 20.5. Processing User Input
    6. 20.6. The Commands Panel
      1. 20.6.1. Processing a Command
    7. 20.7. Making and Moving the Figure
      1. 20.7.1. Building the Figure
      2. 20.7.2. Orientating Limbs
      3. 20.7.3. Creating the Scene Graph
      4. 20.7.4. Processing Limb-Related Operations
      5. 20.7.5. Figure Movement
    8. 20.8. Modeling a Limb
      1. 20.8.1. Growing a Limb
      2. 20.8.2. Updating and Resetting
    9. 20.9. Moving a Limb
      1. 20.9.1. Moving an Elliptical Limb
    10. 20.10. Other Articulated Figures
    11. 20.11. Articulation and Mesh Deformation
    12. 20.12. Articulation and Skinning
    13. 20.13. Articulation and Morphing
  23. 21. Particle Systems
    1. 21.1. Particle Systems in Java 3D
      1. 21.1.1. Referring to Float Arrays
      2. 21.1.2. Synchronization Problems
      3. 21.1.3. The Inner Class Coding Style
    2. 21.2. Class Diagrams for Particles3D
    3. 21.3. Creating the Scene
    4. 21.4. A Fountain of Points
      1. 21.4.1. The Particle System’s Geometry and Appearance
      2. 21.4.2. Updating the Points
      3. 21.4.3. Updating Particles
      4. 21.4.4. Triggering an Update
    5. 21.5. A Fountain of Lines
      1. 21.5.1. Initializing the Particles
      2. 21.5.2. Particle Appearance
      3. 21.5.3. Updating the Particle System
    6. 21.6. A Fountain of Quads
      1. 21.6.1. Specifying the Geometry
      2. 21.6.2. Initializing Particle Movement
      3. 21.6.3. Initializing Particle Texture Coordinates
      4. 21.6.4. Initializing Particle Normals
      5. 21.6.5. Particle Appearance
      6. 21.6.6. Updating the Particles
    7. 21.7. Performance Results
    8. 21.8. More Particle Systems
    9. 21.9. Other Java 3D Approaches
    10. 21.10. Non-Java 3D Approaches
  24. 22. Flocking Boids
    1. 22.1. A Flocking Application
    2. 22.2. Scene Creation
    3. 22.3. Adding Obstacles
      1. 22.3.1. The boid shape
    4. 22.4. Types of Boids
      1. 22.4.1. Boid Movement
      2. 22.4.2. Animating the Boid
      3. 22.4.3. Velocity Rules
      4. 22.4.4. Obstacle Avoidance
      5. 22.4.5. Staying in Bounds
      6. 22.4.6. The Prey Boid
      7. 22.4.7. The Predator Boid
    5. 22.5. Grouping the Boids
    6. 22.6. Flock Behavior
      1. 22.6.1. Animate the Boids
      2. 22.6.2. Velocity Rules Again
      3. 22.6.3. The Prey’s Behavior
      4. 22.6.4. Velocity Rules and Other Flocks
      5. 22.6.5. Goodbye Prey
      6. 22.6.6. The Predator’s Behavior
      7. 22.6.7. Lunch Time
  25. 23. Shooting a Gun
    1. 23.1. Class Diagrams for Shooter3D
    2. 23.2. Scene Creation
    3. 23.3. The Sound of Shooting
    4. 23.4. Picking Scene Objects
      1. 23.4.1. What to Pick in Shooter3D?
    5. 23.5. Controlling the Gun
    6. 23.6. Preparing the Laser Beam
      1. 23.6.1. Shooting the Beam
    7. 23.7. Causing an Explosion
      1. 23.7.1. Rotating the Explosion
      2. 23.7.2. Displaying a Series of Images
    8. 23.8. Picking with a Mouse Click
      1. 23.8.1. From Mouse Click to Picked Object
      2. 23.8.2. Finding Intersections
    9. 23.9. Shooting Behavior
      1. 23.9.1. Debugging Picking
      2. 23.9.2. Rotating the Cone
      3. 23.9.3. Making the Explosion Face the Viewer
    10. 23.10. Firing the Beam
    11. 23.11. More on Picking
  26. 24. A First-Person Shooter
    1. 24.1. Class Diagrams for FPShooter3D
    2. 24.2. Setting Up the Target
    3. 24.3. Positioning and Moving the User’s Viewpoint
      1. 24.3.1. Viewpoint Behaviors
    4. 24.4. Initializing the User’s Viewpoint
    5. 24.5. Adding an Image to the Viewpoint
      1. 24.5.1. Why Use a GIF?
    6. 24.6. Managing the Ammunition
      1. 24.6.1. Shooting the Gun
    7. 24.7. Managing a Laser Beam
      1. 24.7.1. Firing a Beam
    8. 24.8. Moving the Viewpoint
  27. 25. A 3D Maze
    1. 25.1. Class Diagrams for Maze3D
    2. 25.2. Making a Maze Plan
      1. 25.2.1. Generating a Maze Using Software
    3. 25.3. The User Interface
    4. 25.4. Managing the Maze
      1. 25.4.1. Collision Detection
    5. 25.5. Scenery Creation
      1. 25.5.1. Making a Background
    6. 25.6. Tiling the Floor
      1. 25.6.1. The Textured Plane
    7. 25.7. Viewpoint Creation
      1. 25.7.1. The FOV
      2. 25.7.2. Clip Distances
      3. 25.7.3. Adding a Spotlight
      4. 25.7.4. Adding an Avatar
      5. 25.7.5. Positioning the Viewpoint
      6. 25.7.6. Keyboard Controls
    8. 25.8. The Back Facing Camera
      1. 25.8.1. Adding the Second View to the GUI
    9. 25.9. Moving the Viewpoint
    10. 25.10. The Bird’s-Eye View
      1. 25.10.1. Moving the Arrow
      2. 25.10.2. Rotating the Arrow
      3. 25.10.3. Why Not Use a Bird’s-Eye Camera?
    11. 25.11. Related Approaches to Scene Generation
  28. 26. Fractal Land
    1. 26.1. Class Diagrams for the Fractal Land
      1. 26.1.1. What Is Flatness?
    2. 26.2. Building the Fractal Land
      1. 26.2.1. Linear Fog
      2. 26.2.2. User Controls
    3. 26.3. Creating the Landscape
      1. 26.3.1. Creating Floors
      2. 26.3.2. Creating Walls
      3. 26.3.3. On the Floor
      4. 26.3.4. Picking a Height
      5. 26.3.5. Issues with Terrain Representation
    4. 26.4. Constructing the Ground
      1. 26.4.1. Stripification
      2. 26.4.2. Texture Minification
      3. 26.4.3. Multiple Textures
    5. 26.5. Generating a Fractal Landscape
      1. 26.5.1. Printing the Mesh
      2. 26.5.2. Fixing the Randomness
    6. 26.6. Responding to Key Presses
    7. 26.7. Terrain Following and Collision Avoidance
    8. 26.8. Placing Objects in the Scene
    9. 26.9. Other Fractal Landscapes
  29. 27. Terrain Generation with Terragen
    1. 27.1. Class Diagrams for Terra3D
    2. 27.2. Terragen
      1. 27.2.1. Using Terragen
      2. 27.2.2. Extracting a Terragen Texture
    3. 27.3. Scenery Creation
      1. 27.3.1. Setting Up the User’s Controls
    4. 27.4. Building the Landscape
      1. 27.4.1. Loading the Mesh
      2. 27.4.2. Placing the Terrain in the World
      3. 27.4.3. Adding Texture to the Terrain
    5. 27.5. Making 3D Scenery
      1. 27.5.1. Placing the Models
    6. 27.6. Adding Landscape Walls
      1. 27.6.1. A Wall as a Textured Plane
    7. 27.7. Creating Ground Cover
      1. 27.7.1. The Ground Cover
      2. 27.7.2. The Ground Shape
    8. 27.8. Moving over the Surface
      1. 27.8.1. Where Am I?
      2. 27.8.2. Strolling Around the Terrain
    9. 27.9. Finding the Surface Height
      1. 27.9.1. Picking in HeightFinder
    10. 27.10. Accelerating Terrain Following
      1. 27.10.1. More Threads?
      2. 27.10.2. Mesh Decomposition
    11. 27.11. More on Terrain Generation
      1. 27.11.1. DEM and Terrain Generation
      2. 27.11.2. ROAM
      3. 27.11.3. The CLOD Algorithm
      4. 27.11.4. Other Java 3D Projects
  30. 28. Trees That Grow
    1. 28.1. Class Diagrams for Trees3D
    2. 28.2. Creating the Scene
      1. 28.2.1. Loading Leaves
      2. 28.2.2. Depth-Sorting for Transparency
      3. 28.2.3. Getting Ready for Growth
    3. 28.3. Building a Tree Limb
      1. 28.3.1. Storing Tree Limb Information
      2. 28.3.2. Subgraph Creation
      3. 28.3.3. Scaling
      4. 28.3.4. Changing the Limb’s Color
      5. 28.3.5. Leaves on Trees
    4. 28.4. Executing the Rules
    5. 28.5. Displaying Leaves
    6. 28.6. Comparison with L-Systems
      1. 28.6.1. Java 3D and L-Systems
      2. 28.6.2. So Why Not Use L-Systems?
  31. 29. Networking Basics
    1. 29.1. The Elements of Network Communication
      1. 29.1.1. Topology
      2. 29.1.2. Bandwidth
      3. 29.1.3. Latency
      4. 29.1.4. Reliability
      5. 29.1.5. Protocol
    2. 29.2. The Client/Server Model
    3. 29.3. The Peer-to-Peer Model
    4. 29.4. Client/Server Programming in Java
      1. 29.4.1. TCP Client and Sequential Server
        1. 29.4.1.1. Class diagrams
        2. 29.4.1.2. The sequential score server
        3. 29.4.1.3. Processing a client
        4. 29.4.1.4. Maintaining the scores information
        5. 29.4.1.5. The scores client
        6. 29.4.1.6. A simple alternative client
      2. 29.4.2. TCP Client and Multithreaded Server
        1. 29.4.2.1. Maintaining scores information
      3. 29.4.3. TCP Client and Multiplexing Server
        1. 29.4.3.1. The multiplexing scores server
        2. 29.4.3.2. Having the server accept a new client
        3. 29.4.3.3. Having the server accept a request from an existing client
        4. 29.4.3.4. Storing client information
        5. 29.4.3.5. Reading a message
        6. 29.4.3.6. Sending a message
        7. 29.4.3.7. Waiting to send
        8. 29.4.3.8. The client
      4. 29.4.4. UDP Client and Server
        1. 29.4.4.1. The UDP-based scores server
        2. 29.4.4.2. The UDP-based scores client
    5. 29.5. P2P Programming in Java
      1. 29.5.1.  
        1. 29.5.1.1. The multicasting time server
        2. 29.5.1.2. The multicasting time client
    6. 29.6. Firewalls
      1. 29.6.1. Retrieving a Web Page
      2. 29.6.2. Proxy Authorization
      3. 29.6.3. A Web-Based Client and Server
        1. 29.6.3.1. A servlet that serves up time
        2. 29.6.3.2. The time client
      4. 29.6.4. Applets as Clients
    7. 29.7. Other Kinds of Java Networking
  32. 30. Network Chat
    1. 30.1. Threaded TCP Clients and Server
      1. 30.1.1. The Chat Client
      2. 30.1.2. Showing a Message and Threads
      3. 30.1.3. Waiting for Chat Messages
      4. 30.1.4. The Chat Server
      5. 30.1.5. The Threaded Chat Handler
      6. 30.1.6. Storing Chat Client Information
      7. 30.1.7. The Chatter Class
      8. 30.1.8. Discussion
    2. 30.2. UDP Multicasting Clients and a Name Server
      1. 30.2.1. The Name Server
      2. 30.2.2. Improving Client Login and Logout
      3. 30.2.3. Multicast Chatting
        1. 30.2.3.1. Having the client talk to the name server
        2. 30.2.3.2. Having the client talk to the multicast group
        3. 30.2.3.3. Hearing from the multicast group
      4. 30.2.4. How Invisible Are Invisible Messages?
      5. 30.2.5. Ways to Implement who
    3. 30.3. Clients Using a Servlet as a Server
      1. 30.3.1. The URL-Based Chat Client
        1. 30.3.1.1. Talking to the servlet
      2. 30.3.2. Polling for Chat Messages
      3. 30.3.3. The Chat Servlet
        1. 30.3.3.1. Dealing with a new client
        2. 30.3.3.2. Processing client messages
      4. 30.3.4. Storing Chat Group Information
        1. 30.3.4.1. Adding a new client to the group
        2. 30.3.4.2. Reading client messages
      5. 30.3.5. The Chatter Class
  33. 31. A Networked Two-Person Game
    1. 31.1. The Standalone Tic-Tac-Toe Game
      1. 31.1.1. The Origins of the Game
      2. 31.1.2. Building the Game Scene
      3. 31.1.3. Building the Game Markers
      4. 31.1.4. Picking and Dragging
        1. 31.1.4.1. Dragging the board
        2. 31.1.4.2. Picking a marker
        3. 31.1.4.3. Picking comparisons
      5. 31.1.5. The Game Representation
        1. 31.1.5.1. Processing a selected position
        2. 31.1.5.2. Storing the selected position
        3. 31.1.5.3. Reporting a winner
    2. 31.2. The Networked Tic-Tac-Toe Game
      1. 31.2.1. Two-Person Communication Protocols
        1. 31.2.1.1. Initialization
        2. 31.2.1.2. Termination
        3. 31.2.1.3. Game play
      2. 31.2.2. Playing the Game
      3. 31.2.3. The Top-Level Server
      4. 31.2.4. The Player Handlers
    3. 31.3. Comparing NetFourByFour and FourByFour
      1. 31.3.1. Game Initialization in the Client
      2. 31.3.2. Game Termination in the Client
        1. 31.3.2.1. The player has won
        2. 31.3.2.2. The close box was clicked
        3. 31.3.2.3. Too few players, and the game is full
        4. 31.3.2.4. The handler or other player has died
      3. 31.3.3. Game Play in the Client
        1. 31.3.3.1. Player 1’s client
        2. 31.3.3.2. Server-side processing
        3. 31.3.3.3. Player 2’s client
      4. 31.3.4. Writing on the Canvas
        1. 31.3.4.1. Mixed mode rendering
        2. 31.3.4.2. Drawing on the overlay canvas
  34. 32. A Networked Virtual Environment
    1. 32.1. Background on NVEs
      1. 32.1.1. The Elements of an NVE
        1. 32.1.1.1. Spaces
        2. 32.1.1.2. Users
        3. 32.1.1.3. Objects
        4. 32.1.1.4. Views
        5. 32.1.1.5. Consistency
        6. 32.1.1.6. Real-time
        7. 32.1.1.7. Dead reckoning
        8. 32.1.1.8. Security
        9. 32.1.1.9. Scalability
    2. 32.2. An Overview of NetTour3D
      1. 32.2.1. Class Diagrams for NetTour3D
      2. 32.2.2. NetTour3D as a Simple NVE
    3. 32.3. Scene Creation on the Client
    4. 32.4. Defining Sprites
    5. 32.5. Local Sprites
      1. 32.5.1. Creating a Local Sprite
      2. 32.5.2. Moving and Rotating a Local Sprite
      3. 32.5.3. The Departure of a Local Sprite
    6. 32.6. Watching the Server
      1. 32.6.1. Creating a Distributed Sprite
      2. 32.6.2. The Distributed Sprites Class
      3. 32.6.3. Moving and Rotating a Distributed Sprite
      4. 32.6.4. Responding to Sprite Detail Requests
      5. 32.6.5. Receiving Other Client’s Sprite Details
    7. 32.7. Server Activities
      1. 32.7.1. Broadcasting
      2. 32.7.2. Client-to-Client Message Passing
    8. 32.8. Other Java NVEs
      1. 32.8.1. The Sun Game Server
  35. A. Installation Using install4j
    1. A.1. install4j Versus JWS
    2. A.2. The Java 3D Components
      1. A.2.1. Java 3D Components for BugRunner
      2. A.2.2. j3dutils.jar on a Diet
    3. A.3. The BugRunner Application
      1. A.3.1. Preparing the JARs
      2. A.3.2. Testing
      3. A.3.3. Creating the BugRunner Installer
      4. A.3.4. Uninstallation
      5. A.3.5. The BugRunner Installer
    4. A.4. The Checkers3D Application
      1. A.4.1. Preparing the JARs
      2. A.4.2. Changes to Checkers3D.java
      3. A.4.3. Creating the Checkers3D Installer
      4. A.4.4. The Checkers3D Installer
  36. B. Installation Using Java Web Start
    1. B.1. JWS Benefits
    2. B.2. JWS Downsides
    3. B.3. The JNLP Deployment File
    4. B.4. Steps in Developing a JWS Application
    5. B.5. A JWS Installer for BugRunner
      1. B.5.1. Write the Application
      2. B.5.2. Modify the Application for Deployment
      3. B.5.3. Create a Public/Private Keypair for Signing the Application
      4. B.5.4. Sign Everything with the Private Key
      5. B.5.5. Create a Deployment File
        1. B.5.5.1. Deployment testing
      6. B.5.6. Place Everything on a Server
    6. B.6. A JWS Installer for Checkers3D
      1. B.6.1. Write the Application
      2. B.6.2. Modify the Application for Deployment
      3. B.6.3. Create a Public/Private Keypair for Signing the Application
      4. B.6.4. Sign Everything with the Private Key
      5. B.6.5. Create a Deployment File
      6. B.6.6. Place Everything on a Server
    7. B.7. Another Way to Install Checkers3D
    8. B.8. The JWS Portal Page
      1. B.8.1. Setting javawsInstalled in JavaScript
      2. B.8.2. The JavaScript Functions
      3. B.8.3. The VBScript Code
      4. B.8.4. More Information on Portal Pages
    9. B.9. Third-Party Certificates
      1. B.9.1. Extract a CSR
      2. B.9.2. Request a Certificate
      3. B.9.3. Import the Certificate into the Keystore
      4. B.9.4. Sign JARs with the Keypair
    10. B.10. More Information
      1. B.10.1. JWS and Java 3D
      2. B.10.2. JWS and Other Libraries
  37. Index
  38. Colophon
  39. Copyright

Product information

  • Title: Killer Game Programming in Java
  • Author(s): Andrew Davison
  • Release date: May 2005
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596007300