braingdx icon indicating copy to clipboard operation
braingdx copied to clipboard

Make game object loading configurable

Open punchcafe opened this issue 4 years ago • 1 comments

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

punchcafe avatar Apr 04 '20 01:04 punchcafe

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:

  1. implement a set of rules how game objects should be initialised
  2. define objects and attributes e.g. in tiled
  3. objects get automatically loaded and assigned to their e.g. behaviors etc.

bitbrain avatar Apr 11 '20 01:04 bitbrain