I was making a game (2D RPG) in java using libGDX. Started making classes Top Down aka Thing → Item → Animated Item → DirectionalAnimatedItem → Weapon → MeeleWeapon → MetalMeeleWeapon → Sword → FireSword → SuperFireSword → DeamonsSword. This quickely became a nightmare so I moved everything into nice packages and it became less of nightmare, but still a nightmare none the less. After much refractoring I realized that no class beyond MeeleWeapon was needed. So away they went. I replaced the damage methods with functional interfaces that one could extend and use to set the various methods for functionally of objects and what did when various things happened like collide or equip or swing. That seemed to good to me. But now after doing some good reading on ECS I am beginning to see some advantages to it. If I were create an ECS system in java I would have an entity with an id and hash maps of boolean , string, and numeric stats to hold the data and texture region to draw it. Corrrect? like this
public class Entity extends Actor {
Map < String, DoubleStat> numericStats= new HashMap<String, DoubleStat>();
Map < String, BooleanStat> booleanStats= new HashMap<String , StringStat>();
Map < String, StringStat> stringStats= new HashMap<String, StringStat>();
String id;
AtlasRegion region;
@Override
public void draw(Batch batch , float alpha){
}
}
then have base class called system that acts on entities like this and implements actual Systems by extending it.
public abstract class System{
abstract act(Entity entity);
}
then in the game loop method call and just loop through every system and entity having the system check whether or not the entity has any data to manipulate?
void gameLoop() {
for(int count=0; count<systems.size(); count++){
for(int count2=0; count2<entities.size(); count2++){
system.get(count).act(entities.get(count2);
}
This seems like you have to create a system for every action? Like move, explode on contact , kill enemies on contact , change to a tree on contact and it seems like you have the inverse problem of my first solution and you wind up with hundreds of systems/ components for every action you want to have in the game (but they are easily attached).
Is ECS really that great? or my current sorta mix of the two just as good? I like the fact any entity can be given any component but is seams now you're just creating as many Systems / components as my first solution though they can be resued. Although maybe I don't quite understand ECSs totally.