This forum is read only and just serves as an archive. If you have any questions, please post them on

1 decade ago by Neeko

I want to avoid deep class hierarchies while I DRY up and share similar behavior code throughout my entities. I've started following an entity framework (, though I admit so far what I've done isn't the canonical definition of an entity framework, but similar.

Here's how I've broken out behavioral code and how each specific entity composes that behavior. Note that some of the classes are abbreviated.






I would just like to get any comments and criticisms on what I've done so far. One improvement I can see is passing just the data that the controllers need instead of a reference to the entire entity. I'd also like to avoid having to extend the EntityController class completely, but I think it's necessary due to the specific behavior required by both the player (direct input) and enemy (AI) entities.

Thanks for looking!

1 decade ago by Joncom

I like how you just have one selectAnimation function that handles all possible animations, keeping your update logic nice and clean. :)

I'm not sure why you have all these controller classes. I usually handle the player controls within player. Your way may be fine, or even better, I'm not sure... I've just never done it that way. How come you did it that way?

1 decade ago by Neeko

Thanks for the comments!

The main purpose of breaking out the behavior like this is because other entities will share the same behavior, thus reducing duplicate code.

For example, the code to move a player and enemy is virtually the same (EntityController), with the small caveat of the player accepting direct input and the enemy being driven by an AI function chain.

This also will allow me to change the behavior of an entity in a very modular way.

1 decade ago by Joncom

Sounds good in theory. Would be interested to see your code once you have a complete game :P
Page 1 of 1
« first « previous next › last »