Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Need suggestions for.. Creating enemies..

Author
Message
Justin AnyhowStep
13
Years of Service
User Offline
Joined: 17th Jul 2011
Location: Use of uninitialized variable
Posted: 17th Sep 2011 03:59
All right, I'll try to explain my predicament as best as I can.
In my game, I'll have a lot of different enemies that differ in their AI, actions, graphics, stats, etc.

Anyway, the frame-work for all this is already in place with my abstract class called "Unit".

All other Enemy classes inherit from "Unit" and overload the following methods:


Which is why I'll need to have enemies inherit from "Unit" instead of using "Unit" as a generic class for instanciating other enemies.

My problem is this:
Different stages of the game will spawn different kinds of enemies.
However, the only ideas I have are:

'switch' statements


My other idea is funtion pointers to a function template


But those two ideas are a little.. hack-ish.
Is there a better way out there?

First year student of a game-programming course
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 21st Sep 2011 14:25 Edited at: 21st Sep 2011 14:33
Take a gander into Component-based Entities. Be warned, it could require a significant amount of framework refactoring, with the long-term goal of the code being more agile and flexible.

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 21st Sep 2011 15:41
Your first method is actually pretty common. It's called a class factory. I would avoid it at this high level of abstraction though.

Instead, I would opt for either the strategy pattern and have various ai strategies and action strategies. Alternatively you can check out techlords suggestion of component based programming which is really an extension of the strategy pattern.

Either option would work including your current approach.

Good luck and happy coding!

JTK

Login to post a reply

Server time is: 2024-11-19 07:26:38
Your offset time is: 2024-11-19 07:26:38