Take my Ninja game for example, I've got a super class called Enemy, and then the Ninja class, Archer class, and Shaman class inherit from Enemy.
GreenNinja and RedNinja inherit the Ninja class.
So then I can have a bunch of different behaviors for different enemy groups. Like RedNinja and GreenNinja are very ordinary enemies, and they have two hurt animations while everybody else has only one, so they're under the Ninja class. And instead of making Green Ninjas and Red Ninjas just use the Ninja class, I made them thier own classes because Green Ninjas are supposed to be dumber and have less health than Red Ninjas.
Archers and Shamans are obviously different from the Ninjas behavior-wise.
But they all do most of the same stuff, before they're "active" they follow a pattern given to them by whatever level thier on. It can look something like:
| Code: |
|
This tells the archer to start facing left, at position (474.5, 297.5) and walk back and forth, waiting 1 and 1/5 second before turning and walking the other way.
| Code: |
|
Every enemy knows how to follow these directions because all of the code for this is in the Enemy class, so if I want the enemy to follow behaviors then in its Update function I simply write:
FollowBehaviors();
An update function can be as simple as this:
| Code: |
|
This is from the Shaman class, he walks around until he's activated, and if he hasn't already summoned a beast, he'll do it. Then we have to make sure we're colliding with the enviroment, then we have to update our animation, and then make sure we're facing the right way.
CheckCollisions is a function from the Enemy class, and UpdateAnimation is overriden in the Shaman class to fit that specific enemy type.
What do you guys do?



.