Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 12. Game Worlds: Driving and Exp... > Checking for Trash and Trashcan Coll...

Checking for Trash and Trashcan Collisions

The checkCollisions function needs to look for two different types of collisions. It starts by looking at all the trashObjects. It will use the Point.distance function to see whether the location of the car and the location of the TrashObject are closer than the pickupDistance constant:

public function checkCollisions() {


    // loop through trash cans
    for(var i:int=trashObjects.length-1;i>=0;i--) {

        // see if close enough to get trash objects
        if (Point.distance(new Point(gamesprite.car.x,gamesprite.car.y),
          new Point(trashObjects[i].x, trashObjects[i].y)) < pickupDistance) {

					  


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint