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 ...