-
Book Overview & Buying
-
Table Of Contents
Cocos2d Cross-Platform Game Development Cookbook - Second Edition - Second Edition
By :
In patrol enemy behavior, the enemy AI will move between two or more points. When the player comes close to the enemy, the enemy will attack the player, and if the player moves beyond the zone of the enemy or dies, then the enemy will continue to go on with their patrol duty.
To create an AI, we will create a class called PatrolAI, along with a bullet class. In the PatrolAI class, we will add the movement behavior, which will check the distance between the player and enemy. If the player comes close to the enemy, the enemy is required to turn around and start shooting at the player.
In the bullet class, we will add a movement function and delete the functionality for it.
Make sure to import the enemy and hero images as we will need them for this project. For this chapter, I will create a new project, so if you want to do the same, make sure you change the settings of your project accordingly.
First, let's create the PatrolAI class.
In the interface...
Change the font size
Change margin width
Change background colour