Generating enemies with the evolutionary algorithm
So far, we have created topological algorithms, so it's time to explore a different kind of content, such as enemies.
In this recipe, we will make use of the evolutionary algorithm to create waves of enemies based on the ones that are difficult to tackle for the player.
Getting ready
We need to define the template for the enemies to focus the next section on how to implement the main evolutionary algorithm. In this case, we will use a serializable class named EvolEnemy
:
using UnityEngine; using UnityEngine.UI; [System.Serializable] public class EvolEnemy { public Sprite sprite; public int healthInit; public int healthMax; public int healthVariance; }
How to do it...
We will work on two classes: the enemy generator containing the evolutionary algorithm and the enemy controller for handling the real-time instances from the enemy templates created in the previous section. We'll also use some game logic.
We need to define the controller for...