Ok... that's not helping at all. Can you just show me how I would make my code. I have a person class containing all functions for a zombie, what i want to do is create a vector, make a certain amount of zombies(person class) inside them according to a rand() function, initialize them all and then during my main loop to update them. I thought of this code, but it just makes my player go really laggy and no zombies appear:
Any help or other ideas? Also, can you also tell me how to do projectiles?
mypel,
I've given you a link to look directly at my source code (you can download the full source from my Old Blog), and you've been given the webpage that explains vectors. You need to do some work yourself.
Your code looks OK, but there's still some issues. You don't need to declare how big a vector is, it is dynamic, so you can just push_back zombie's as you need them. ALso, don't create a new player pointer for the zombies just push an instance of them onto th vector, like this:
for (int i = 0; i < 5; ++i) {
int xR = rand() % 1000 + 1;
int yR = rand() % 800 + 1;
// Your player class should have the cxonstructor define the x, y, and (whatever 50 is), not a separate call to initialize
// the constructor can probably do whatever loadContent does too
Player zombie(xR, yR, 50);
zombies.push_back(zombie);
}
Also, you're not looping through the zombies at all. Zombie0 is just the last zombie created in your loop. You need to be access the zombies form the vector. Again, the vector page will help, but here's what I would do:
for (int = 0; i < zombies.size(); ++i) {
zombies->tick(player, Window);
zombies->draw(Window);
}
And projectiles aren't much different than adding a zombie as far as adding them to a vector, and looping through them all to process them.