I've been putting together a 2D side-scolling game using the Allegro 5 library. However, I've hit a wall with this, as I've suddenly realised I'm not really too sure how I would implement AI opponents that have the same behaviour, but behave differently under different conditions.
For example, say I wanted 5 AI opponents shooting at my character in one part of the level. How would I go about creating one section of code and using it to control the behaviour of each of these AI characters?
Create a class for handling an opponent. You can then create an instance of the class for each opponent you want. Store the objects in a container so that you can easily loop through the opponents.
std::vector<ENEMY_CLASS*> EnemyArray;
for(int i = 0; i < NUMBER_OF_ENEMYS; ++i)
{
ENEMY_CLASS* Enemy = new ENEMY_CLASS();
EnemyArray.push_back(Enemy);
}
Obviously if your constructor took any arguments you would pass them in on Line 5. Also note that this is a vector or pointers to objects, so you will need to de-reference them when you use them.
I've never used a vector before, so this is probably going to sound really stupid, but how would I access and use the instances of the enemy class once they have been created?