So I was just looking through an old game I had made for android, and was second guessing how I was sub-classing enemy for each particular enemy in my game. My enemy class had all kinds of properties, like sprite speed size and different bools that related to the state of the enemy...etc. But then for each enemy in the game I created a sub-class from enemy, and all I did was set all those properties to a specific value. Something like this:
public class Ninja extends Enemy
{
public Ninja(Vector2 pos)
{
super(pos);
this.speed = 10;
this.sprite = Content.Ninja;
this.size = spriteSize.Medium;
this.hitPoints = 200;
//..etc
}
}
That was basically the whole class. Looking back it seems like a waste of making a class at all, it left me with nothing else to change about that enemy, but just a convenient way to declare them. Is this common practice? I suppose it is nice to have all these stats grouped into 1 place, but it seems like a small amount of information to have for a whole class, maybe I'm just over-thinking this. Does anyone else ever do similar things in their games? Maybe it would be better to just make a static method somewhere that generates a Enemy with these stats called like CreateNinja
, and save myself the clutter of having a whole class for it. What do you guys think?