Okay, so for making the other balls move you need to say "dbSprite" every loop. (Or you could use "dbCircle" So if you want to have a bunch of balls, I'd make a vector of classes or structures called balls.
Here's some code. Just so you know, for this to work you need to have #include <vector> at the top of your code. You should also have "using namespace std;" after the includes(that or you could just say std:: before most stuff in iostream and stuff since I think most of that is under the std namespace).
class BallClass
{
public:
float x;
float y;
float xspeed;
float yspeed;
};
vector <BallClass> Ball(5);
Anyway now you can create random x, y, xspeed, and yspeed's for each one. (this should all be outside your loop)
for this you need to include Time.h at the top.
srand(time(NULL));//seeds the random thing with the time
for (counter = 0; counter < Ball.size(); counter++) //goes through each ball and assigns random values
{
Ball[counter].x = rand()%dbScreenWidth();
Ball[counter].y = rand()%dbScreenHeight();
Ball[counter].xspeed = rand()%5;
Ball[counter].yspeed = rand()%5;
}
Now in the loop...
This will draw each circle.
dbInk (dbRGB (255, 0, 0), 0);
for (counter = 0; counter < Ball.size(); counter++)
{
dbCircle (Ball[counter].x, Ball[counter].y, Ball[counter].radius.);
}
Now you have to update each ball's x and y position, so that the ball's will move. I've also added code so the balls should bounce off the walls
for (counter = 0; counter < Ball.size(); counter++)
{
Ball[counter].x += Ball[counter].xspeed;
Ball[counter].y += Ball[counter].yspeed;
if (Ball[counter].x + Ball[counter].radius > dbScreenWidth())
Ball[counter].xspeed = Ball[counter].xspeed * -1.1;
if (Ball[counter].x - Ball[counter].radius < 0)
Ball[counter].xspeed = Ball[counter].xspeed * -1.1;
if (Ball[counter].y + Ball[counter].radius > dbScreenHeight())
Ball[counter].yspeed = Ball[counter].yspeed * -1.1;
if (Ball[counter].y - Ball[counter].radius < 0)
Ball[counter].yspeed = Ball[counter].yspeed * -1.1;
}
As for collision you'll want something like this...
for (counter = 0; counter < Ball.size(); counter++)
{
if (Player.x > Ball[counter].x - Ball[counter].radius && Player.x < Ball[counter].x + Ball[counter].radius)
{
if (Player.y > Ball[counter].y - Ball[counter].radius && Player.y < Ball[counter].y + Ball[counter].radius)
{
}
}
}
Sorry about indentation, the forum seems to mess it up.
BTW: You should go into the properties of your project > c/c++ > code generation and instead of Multithreaded debugging (MTd), set it to MT. This fixes a few weird errors I always get when using vectors. I have no idea why.
EDIT: I haven't tried this so if it doesnt work, I made some stupid error like forgetting a semi colon or bracket