So if you followed my previous posts you may know i have got my bullets implemented thanks to you guys and did some work to optimize it a bit. I added an ammo variable and changed the container for the bulletclass from a vector to an fixed size array. And using a for loop that will put every bullets' "active" boolean to false if it's of the screen. So there are only 12 bullets (because of the use of an array) but since every bullet that's off the screen gets put to non active i can use it again when needed, see my code below
spawning a bullet
for (//loop through bullets)
if ( bullets[i].active == false )
bullets[i].active = true;
bullets[i].x = (player.x + player.rad - bullets[i].rad); //Middle of player bubble
bullets[i].y = (player.y + player.rad - bullets[i].rad); //
checking if it's of the screen
for ( //loop through all bullets)
if (//bullets[i].x or bullets[i].y out of screen)
bullets[i].active = false;
if (bullets[i].active == true)
bullets[i].draw( m_Screen );
After reading a tutorials on this site which involved working with the mouse i used that so it draws a line between the middle of my player bubble to the mouse x and y coordinates (blue line in screenshot).
Currently the bullets are just travelling downwards to face the upcomping horde of bubbles, but now i want to be able to shoot the bullets towards the end of the line and keep them moving towards that point even if the mouse has moved. I tried to do so with slope values and such but i can't get my head around the maths that is needed here.
If i click, it spawns a bullet at my player's x and y coordinates. I have added a variable which can hold the direction for every bullet object but i don't know how to get that direction and how to keep a bubble moving towards the point that i defined with the cursor when i clicked.