Sign in to follow this  

Q. on Design Patterns

This topic is 3316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In most games that I have made there are 1 or more player, and many NPCs. Usually I try to make a class like "Enemy" and then just use inheritance for all the variations. Then I make a "Boss" class or something and inherit from that. Recently I found that the inheritance is likely a poor choice since in 99% of the child classes I am always modifying the same parts. Example: moving algorithms, aiming algorithms, shooting algorithms etc... I guess this could be called "behavior". note: I am using c# / c++ mostly. So my question is 2 parts really, like this: Do I make enemies (and bosses) using... 1 - inheritance and polymorphism 2 - A single class "Enemy" with an abstract factory (I think thats what its called) to generate various different types of enemies (IE: just changing Enemy variables) 3 - Something else and also for the behaviours.... 1 - Create a Class (tree) for each type of behavior ie: class AimMethod ie: class ClosestHumanPlayer : AimMethod 2 - Use Function pointers c++, or delegates c#, 3 - Use behavior classes and drop them in the enemy 4 - Something else I'm sure some games will work better with some patterns then others, but in general many games use a player vs NPC with NPC behaviors, so I figure this kind of thing would really be thought about a lot, and hopefully mastered Thanks for your thoughts

Share this post


Link to post
Share on other sites
If you find yourself writing the same thing several times, refactor it. So, if two objects have the same movement algorithm, move that algorithm to its own function or class and use it from the two objects. Depending on the repeated code, the refactoring strategy varies.

You can use mix-ins to add similar members to many objects. For instance, look at the bottom of this article.

Share this post


Link to post
Share on other sites

This topic is 3316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this