Taking human decisions
Our enemies should have a little Artificial Intelligence (AI) for them to decide when is the best moment to walk, search for the zombie, or attack him.
We're going to implement the enemies' AI by implementing a method that will be called constantly to take decisions every frame, so we will need to add the following lines at the end of the update
method in GameScene.m
:
// Take decisions for (Human *human in _arrayOfHumans) { // If the human is doing nothing if ((int)human.state == humanStateStill) { [self takeDecisionWithHuman:human]; } }
Each enemy will call to the method in which they will decide what action to take. Implement this method by adding the following code:
-(void) takeDecisionWithHuman:(Human *)human { float distance = ABS(human.humanSprite.position.x - _zombie.position.x); if ((distance > (human.contentSize.width / 2) && distance < _screenSize.width && !((int)human.state...