Hey Guys,
I'm building an asteroids-like game and I'm needing to be able to apply the same operation too all of the different "aliens" on the screen. When I had two aliens on the screen I performed all of the functions manually but that is bad program design. I created a vector and all of the sudden my aliens stopped performing the functions that were called when I looped through the vector.
Here's the working code:
alien1.moveTowardsPlayer(player1.getX(),player1.getY());
alien1.accelerate();
alien1.move();
alien1.boundaryCheck();
Here's the bad code:
std::vector<Alien> aliens;
Alien alien1;
Alien alien2(100,200,30,30,1,172);
aliens.push_back(alien1);
aliens.push_back(alien2);
//game loop has started
for(int i = 0; i< size; i++)
{
alienList[i].moveTowardsPlayer(player1.getX(),player1.getY());
alienList[i].accelerate();
alienList[i].move();
alienList[i].boundaryCheck();
}
//game loops
I created a static array just to see if it was a vector problem and alas I cannot get it to work with a static array either. I'm thinking that I may be needing to setup some sort of copy constructor that isn't currently setup or maybe I'm creating the vector or array incorrectly. Is the solution to this problem simple?
Thanks!