Book Image

iOS Game Programming Cookbook

Book Image

iOS Game Programming Cookbook

Overview of this book

Table of Contents (19 chapters)
iOS Game Programming Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing evade


Evade is similar to flee. The only difference between flee and evade is that in evade, the player will stop after fleeing to a safe location from the target location selected for evade. However, in flee, it just runs out of the screen from the target location and never comes back.

Getting ready

Technically, evade is to flee from the target to the safe location. The evade behavior will remain the same as the flee behavior, the only difference is that it will not run away infinitely from the target.

In this approach, when the target location is inside the safe range of the player, then the player will flee till the target location is not outside its safe range. So, in our case, we will make the player flee till the player is far from the target, and then its velocity will be ramped down to zero.

How to do it

Perform the following steps to implement the evade behavior:

  1. Open the Player.m file and add the following line of code in the end of the file:

    - (void) evade:(CGPoint )target...