braingdx
braingdx copied to clipboard
Make game object loading configurable
This ticket is a WIP
Motivation
Diving in to developing a game, when I want to create a new entity in the game, I have to create a model to represent it, set up listeners to make sure it is instantiated properly, manually set it to the physics manager etc... Realistically, I should be able to define a class which implements a Model interface, and then be able to create objects in TMX with the same type, and it should appear.
For example:
interface GameObjectModel<T> {
void initialize(ModelConfig<T> someMap){ default imp }; // This would be injected from the values provided in tiled, and the method would have default behaviour for nulls.
}
Also, behaviour resolution between two objects should be handled without having to know about game objects. Something like:
interface BehaviourStrategy<SubjectType> {
BiConsumer<SubjectType,Object> getBehaviourStrategy(Class anyClass){
// returns the correct method for resolving collision
}
}
Ideally, I feel like we don't need to ever handle game objects. This means we can build entire Java models, and everything else is abstracted away
I like the idea! I have reworded the ticket since we can make this very generic, however then use this e.g. in the TiledMapManager
to load game objects based on a given configuration.
Currently, I am facing the same issue, where I manually need to decorate/initialise objects based on type (not very nice):
// AFTER tiledmap has been loaded
for (GameObject object : gameWorld.getObjects()) {
if ("PLAYER".equals(object.getType()) {
// initialise player here
}
}
This approach is very cumbersome, error-prone and inflexible, since we have to do always changes in multiple places, check for types etc.
Instead, we can do the following:
- implement a set of rules how game objects should be initialised
- define objects and attributes e.g. in tiled
- objects get automatically loaded and assigned to their e.g. behaviors etc.