Jump to content
  • Advertisement
Sign in to follow this  
Effron

Q. on Design Patterns

This topic is 3563 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!