Original Post
I''m currently in the process of making a top-down 2D space shooter type game. (Anyone ever played Raptor: Call of the Shadows? I''m trying to make a clone of that game.) Basically, waves upon waves of aliens attack you until you kill them or they go off the bottom of the screen.
I created an Alien class, and now I''m going to make a bunch of classes that inherit from the Alien class for specific types of enemies. Each type will have different weaponry, graphics, armor, etc. Each of my levels will be stored in a file that records each alien that you fight, its type and some waypoints to describe its path through the game screen.
My problem is how to create new aliens of the correct type when I load levels from my file. I planned to have a vector full of Alien pointers that could point to any subclass of alien. However, to create new aliens of the right type, the best code I can think of is something vaguely like this:
cin >> type;
if (type==GREEN_CIRCULAR_THING)
Aliens[1] = new GreenRoundAlien;
if (type==SHINY_METAL_ALIEN)
Aliens[1] = new ShinyAlien;
if (type==BOSS1)
Aliens[1] = new Boss1;
and so on for a whole lot more alien types. I could do this, but I want to know if there is a better/simpler alternative. Also, any criticism about the way I am structuring everything is welcome; this is my first non-trivial game project and I want to know if I am doing everything at least semi-logically.
Things are not what they are.