Book Image

Cocos2d-x by Example: Beginner's Guide

By : Roger Engelbert
Book Image

Cocos2d-x by Example: Beginner's Guide

By: Roger Engelbert

Overview of this book

Table of Contents (19 chapters)
Cocos2d-x by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Platform collision logic


We have in place all the information we need to check for collision through the inline methods found in Player and Block.

In this game, we'll need to check collision between the _player object's bottom side and the block object's top side, and between the _player object's right side and the Block class' left side. And we'll do that by checking the _player object's current position and its next position. We are looking for these conditions:

The diagram represents the conditions for bottom side collision, but the same idea applies to right side collision.

In the current position, the _player object must be above the top of the block or touching it. In the next position, the _player object must be either touching the top of the block or already overlapping it (or has moved past it altogether). This would mean a collision has occurred.