You are previewing Beginning Java SE 6 Game Programming, Third Edition.

Beginning Java SE 6 Game Programming, Third Edition

Cover of Beginning Java SE 6 Game Programming, Third Edition by Jonathan S. Harbour Published by Course Technology PTR
  1. Copyright
    1. Dedication
  2. Acknowledgments
  3. About the Author
  4. Introduction
    1. What Will You Learn in This Book?
    2. What about the Programming Language?
    3. What IDE Should You Use?
    4. Conventions Used in This Book
    5. Companion Web Site Downloads
  5. I. Java for Beginners
    1. 1. Getting Started with Java
      1. Java and the Web
      2. The Casual Games Market
      3. Installing and Configuring Java
      4. Your First Java Program
      5. What You Have Learned
      6. Review Questions
      7. On Your Own
    2. 2. Java Programming Essentials
      1. Java Applets and Applications
      2. The Java Language
      3. The Essence of Class
      4. What You Have Learned
      5. Review Questions
      6. On Your Own
    3. 3. Creating Your First Java Game
      1. About the Game Project
      2. Creating the Game
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
  6. II. Java Game Programming
    1. 4. Vector-Based Graphics
      1. Programming Vector Graphics
      2. What You Have Learned
      3. Review Questions
      4. On Your Own
    2. 5. Bitmap-Based Graphics
      1. Programming Bitmapped Graphics
      2. Transparency
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
    3. 6. Simple Sprites
      1. Programming Simple Sprites
      2. Creating a Reusable Sprite Class
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
    4. 7. Sprite Animation
      1. Sprite Animation
      2. What You Have Learned
      3. Review Questions
      4. On Your Own
    5. 8. Keyboard and Mouse Input
      1. Listening to the User
      2. Keyboard Input
      3. Mouse Input
      4. What You Have Learned
      5. Review Questions
      6. On Your Own
    6. 9. Sound Effects and Music
      1. Playing Digital Sample Files
      2. Playing MIDI Sequence Files
      3. Reusable Classes
      4. What You Have Learned
      5. Review Questions
      6. On Your Own
    7. 10. Timing and the Game Loop
      1. The Potency of a Game Loop
      2. Stepping Up to Threads
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
  7. III. The Galactic War Project
    1. 11. Galactic War: From Vectors to Bitmaps
      1. Improving the Game
      2. What You Have Learned
      3. Review Questions
      4. On Your Own
    2. 12. Galactic War: Sprites and Collision Boxes
      1. Creating the Project
      2. What You Have Learned
      3. Review Questions
      4. On Your Own
    3. 13. Galactic War: Squashed by Space Rocks
      1. Being Civilized about Collisions
      2. What You Have Learned
      3. Review Questions
      4. On Your Own
    4. 14. Galactic War: Entity Management
      1. Adjusting to Event-Driven Programming
      2. Enhancing Galactic War
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
    5. 15. Galactic War: Finishing the Game
      1. Let’s Talk about Power-Ups
      2. Enhancing Galactic War
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
    6. 16. Galactic War: Web Deployment
      1. Packaging an Applet in a Java Archive (JAR)
      2. Creating an HTML Host File for Your Applet
      3. What You Have Learned
      4. Review Questions
      5. Epilogue
  8. Chapter Quiz Answers
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
    13. Chapter 13
    14. Chapter 14
    15. Chapter 15
    16. Chapter 16
O'Reilly logo

Chapter 13. Galactic War: Squashed by Space Rocks

We’ll make a minor enhancement to Galactic War in this chapter by adding support for an animated explosion. To facilitate this, we’ll have to write some new code to handle the timing and state properties for each sprite. The goal in this chapter is to add a handler for responding to ship-asteroid collisions. When a collision occurs, the game should animate an explosion over the ship, and then put the ship into a temporary invulnerability mode so the player can get the heck out of the way before another collision occurs.

Here are the key topics we’ll cover in this chapter:

  • Examining possible interactions among the game entities

  • Adding collision detection between the player’s ship and the asteroids ...

The best content for your career. Discover unlimited learning on demand for around $1/day.