Impact

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

9 years 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 (http://www.richardlord.net/blog/what-is-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.

entityController.js
https://gist.github.com/MadballNeek/95e8ad8a8b30561d6f0d

playerController.js
https://gist.github.com/MadballNeek/ef5ce88adc1952e24e9a

player.js
https://gist.github.com/MadballNeek/a3d755add6354723a749

enemyController.js
https://gist.github.com/MadballNeek/7576c1b52678b7346ff4

spike.js
https://gist.github.com/MadballNeek/22b172835620f18a680d

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!

9 years 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?

9 years 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.

9 years 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 »