You need to, at least conceptually, make a distinction between classes of enemies (grunts, bugs, ...) and enemy instances. The class defines the initial health/hitpoints of an enemy, while an instance represents an actually spawned enemy with individual stats and a position.
There are two options to model this.
Class/instance model
You create two classes: one for the class of enemy, and one for an instance of enemy. The EnemyClass
is a factory for Enemy
instances.
class EnemyClass
{
public string Name { get; }
public int InitialHealth { get; }
public Enemy Spawn();
}
class Enemy
{
public EnemyClass Class { get; }
public int CurrentHealth { get; }
public Vector2D Position { get; }
}
// define enemy classes
EnemyClass gruntClass = new EnemyClass(...);
EnemyClass bugClass = new EnemyClass(...);
// spawn an enemy
Enemy enemy = gruntClass.Spawn();
Prototype model
There is only one class, Enemy
. For each enemy class, there's a prototype of an enemy instance of that class. This prototype does not exist in game. To spawn an enemy, you make a clone of the prototype.
class Enemy
{
public string Name { get; }
public int InitialHealth { get; }
public int CurrentHealth { get; }
public Vector2D Position { get; }
public Enemy Clone();
}
// define enemy prototypes
Enemy gruntPrototype = new Enemy(...);
Enemy bugPrototype = new Enemy(...);
// spawn an enemy
Enemy enemy = gruntPrototype.Clone();