Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Johannes Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Johannes Stein

Overview of this book

Table of Contents (20 chapters)
Sparrow iOS Game Framework Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Afterword
Index

Collision detection


Before we implement collision detection, let's take a look at different types of collision detections:

  • Bounding box collision: We check the bounds of the entities (which is a rectangle). If these rectangles intersect, we have a collision.

  • Bounding sphere collision: We calculate the distance between two entities. If the distance is smaller than the radius of both entities combined, these entities are colliding.

  • Pixel collision: We check if all the pixels of one entity intersect with the pixels of another entity. While this is definitely the most detailed and comprehensive collision check, it is also the most CPU-intensive one.

Now that our pirate ship is actually shooting cannonballs, let's implement the functionality that can hit and sink the enemy ship. We use the bounding box collision because this is one of the easiest collision detection types to implement.