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
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Border-based collision detection methods


Border-based collision detection involves incrementally searching outward from Actor until either a collision is detected, or it is determined there are no obstacles in the way. The method finds the edge (or border) of the item collided with. This method is especially useful when objects need to bounce off each other or one object is landing on another and needs to remain on that object for a certain amount of time, for example, when a user-controlled Actor is jumping on a platform. We will introduce this method of collision detection in this chapter, as well as use it in upcoming chapters.

Detecting single-object collisions at an offset

The at offset versions of Greenfoot's collision detection methods are well suited to border-based collision detection. They allow us to check for a collision at a certain distance, or offset, from the center of the calling Actor. To demonstrate the use of this method, we will change the implementation of the canMarch...