Hello!
I'm currently developing a top-down RPG styled game with an Entity Component System architecture and, as the game grows in features, so does my game entities, that is, item models, enemy prototypes, etc. Those definitions are currently in JSON files but at the end of the day I still have long factory classes that read from those files and populate the entities with their respective components and properties in the most naive way.
Reading through a presentation about Techniques and Strategies for Data-driven design in Game Development (slides 80–93) (warning: big pdf file) there is this "prototyping approach" where you can build up each game entity from multiple prototypes. I find this really interesting, however, the presentation doesn't mention any implementation details and I'm totally in the dark. I don't know how powerful should this system be. By the way, I'm using Java and LibGDX's engine. My first idea is making a robust prototype-instancing factory where, given a JSON file, it will be able to return an entity populated with its corresponding components. For example:
Enemies.json
{
"skeleton" : {
"id" : 0,
"components" : {
"HealthComponent" : {
"totalHealth" : 100
}, "TextureComponent" : {
"pathToTexture" : "assets/skeleton.png"
}
}
}
}
If I wanted to instantiate a Skeleton entity, I would read it's prototype, iterate over it's components and somehow I would instantiate them correctly.
With this approach I have the following issues:
- It will most likely involve using Java Reflection to instance entities from a JSON file. This is a topic that I know little about and will probably end up in dark magic code.
- Some instances properties can't be prototyped and will have to be passed as parameters to the factory. For example, when creating an enemy entity, an (x, y) position will have to be provided. Suddenly creating instances is not so straight forward.
- How powerful should this system be? Should it have this "recursive" behavior where you can extend a prototype with an other and so on?
- This sounds a little bit like dependency injection. Am I reinventing the wheel? Is there anything done already I can make us of?
Even though it's still in it's infancy, here is a short demo (under one minute) of my game.
Thank you!