where there is xx1, yy1, h1, and w1, those are my variables for my bullet's location which is set to the location of the player. The method is called in a loop, so when it draws the bullet to the screen, it increase the X (xx1) location by one, then repaints it in the new location which makes the bullet move.
BUT
I want it to keep creating new squares each time i call the function ( press SPACE).
thankyou
If you want a scrolling shoot 'em up, a good method for this would be creating a vector of bullets. Each time the player presses space, it will resize the vector; therefore creating a new bullet at the correct point. To avoid creating too large of a vector, erase the bullets that go off of the screen.
ooooo sweet. thankyou. i have no idea about that or how to do it so i guess ill jsut research it. could you maybe give me a briefing first though? please? :)
Then, to make the bullets fly to the right, loop through them like this:
1 2 3
for(int i = 0; i < bullets.size(); i++) {
bullets[i].x += 0.4;
}
After this, make sure the program isn't handling bullets that are off the screen, add to the for loop I coded above the following code:
1 2 3 4 5 6 7
for(int i = 0; i < bullets.size(); i++) {
bullets[i].x += 0.4;
if(bullets[i].x >= SCREEN_WIDTH) {
bullets.erase(bullets.begin() + i);
}
//I usually use 800 x 600 windows, this will vary for you though.
}
You might need to look up a few more vector functions, but that's the basic idea. :)