Book Image

Cocos2d-X Game Development Blueprints

By : Karan Sequeira
Book Image

Cocos2d-X Game Development Blueprints

By: Karan Sequeira

Overview of this book

Table of Contents (17 chapters)
Cocos2d-x Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Collisions with moving platforms and enemies


If you think about implementing moving platforms, it might seem a bit tricky at first—considering how characters standing right on top of them are supposed to move along with them. We don't have a concept of friction here since there is no physics engine. Also, moving platforms cannot be represented simply by tiles since they have to move smoothly across the screen. If they were represented by tiles, they would jump from one column to the next while moving horizontally. Thus, we will represent a moving platform simply as an axis aligned bounding box.

One thing worth observing is in the UpdateSpeed function of class Hero. Right after we've added gravity, we check whether the hero is standing on a platform and act accordingly. It is imperative that this happens before we add any subsequent forces based on user input. Failing to do so will cause the hero to be stuck on the platform irrespective of user input as we are manually setting the AABB's position...