Hi everyone, I came up with a coding model for this small platformer I am making and wanted to check up with you what were your thoughts about it.
In this model, every object that the player can interact with is a children of the `Entity` class:
class Entity extends FlxSprite
{
public function new(x:Int, y:Int) {
super(x, y);
}
override public function update() {
super.update();
}
public function interact(player:Player) {
}
}
```
Entities are stored in a `_entities = new FlxTypedGroup<Entity>();` in the PlayState.
When the player collides with an entity, its `interact()` method is called:
```
FlxG.overlap(_player, _entities, interact);
function interact(player:Player, entity:Entity):Void
{
entity.interact(player);
}
```
The `interact()` method of course would be different for each entity, so we'd have a `class Coin extends Entity` where interact would kill the coin and raise the score, a `class Enemy extends Entity` which would kill the player and so on. This makes the whole thing pretty modular.
When I want to add a new entry, I recycle one from the group and cast the correct class on it:
```
var coin:Entity = Reg.PS.getEntities().recycle(Coin);
coin.reset(i.x, i.y - 16);
_entities.add(coin);
```
The thing makes sense to me, however in every example I saw people seems to make up specific typedGroup for different objects (coins, enemies, so on)
To the more seasoned programmers, what are your opinions about this? What could the downside be? Am I about to run into a performance disaser?