Here is my code for adding an enemy to the board.
void Level::addEnemies(int num)
{
int i = num;
while (i > 0)
{
int xpos = int(float(((rand() % width) + 1) - 1));
int ypos = int(float(((rand() % height) + 1) - 1));
if (level[xpos][ypos] != TILE_WALL)
{
Enemy *temp = new Enemy(this, drawArea, SPRITE_ENEMY, (float)xpos, (float)ypos);
temp->addGoal(player);
addNPC((sprite *)temp);
i--;
}
}
}
void Level::addNPC(sprite *spr)
{
npc.push_back(spr);
}
this is getting pushed on the stack which I iterate through.
So the problem is the code works well until I remove, possably the last on the stack? I am guessing that decrement of the last/first on the stack it throws up.