Book Image

Creative Greenfoot: RAW

By : Michael Haungs
Book Image

Creative Greenfoot: RAW

By: Michael Haungs

Overview of this book

Table of Contents (17 chapters)
Creative Greenfoot
About the Author
About the Reviewers

Chapter 3. Collision Detection


"Live as if you were to die tomorrow. Learn as if you were to live forever."

 --Mahatma Gandhi

Often, you will need to determine whether two or more objects are touching in Greenfoot. This is known as collision detection and it is necessary for most simulations and games. Detection algorithms range from simple bounding-box methods to very complex pixel color analysis. Greenfoot provides a wide variety of simple methods to accomplish collision detection; you were introduced to some of them in Chapter 1, Let's Dive Right in…, and Chapter 2, Animation. In this chapter, you will learn how to use Greenfoot's other built-in collision detection mechanisms and then learn more accurate methods to use them to do collision detection. While pixel-perfect collision detection is beyond the scope of this book, the border-based and hidden-sprite methods of collision detection will be sufficient for most Greenfoot applications. The topics that will be covered in this chapter...