I'm new to dark gdk myself, but I'm a longtime darkbasic user, so I can at least give you some pointers on where to start, though you'll need to use the help files to get the appropriate commands.
To display the balls, I would recommend using sprites, as they are the easiest way to display 2D images that move around the screen (you can use Paste Image for better performance, but you have to manually redraw the screen each iteration). You will probably want the balls to be saved as a BMP file, then loaded in (dbLoadImage() would be a good way to do that). Load the image and create the sprites before the beginning of the main loop. Position them wherever you want, just not at the same spot (because that will be boring).
For each ball, you will need to store their velocity along each axis (x and y).
Each loop, position the sprite for the ball at it's current location + its velocity. I believe this would be the appropriate syntax:
dbPositionSprite(SpriteNum,dbSpriteX(SpriteNum)+velocityX,dbSpriteY(SpriteNum)+velocityY);
Again, double check in the help files to make sure I got the syntax correct.
So now you have a bunch of balls all moving, but they won't bounce around, so they will just go off the screen. Checking for collision is pretty simple. Use this kind of construct:
if(dbSpriteX(num)<=LeftBound || dbSpriteX(num)+dbSpriteWidth(num)>=RightBound){
spriteVelocityX*=-1;
}
if(dbSpriteY(num)<=TopBound || dbSpriteY(num)+dbSpriteHeight(num)>=BottomBound){
spriteVelocityY*=-1;
}
Breaking down what happens here:
LeftBound, RightBound,TopBound, and BottomBound are variables that represent where you want the "walls" to be. In general, TopBound=LeftBound=0, RightBound=Screen Width, and Bottom Bound=Screen Height.
spriteVelocityY is just a placeholder for however you store your velocities. For ease, I would recommend an array of doubles for each axis, like so:
double ballXVelocities[MaxBalls];
double ballYVelocities[MaxBalls];
but if you are more familiar with C++, you could use an array of std::pair<double,double>, std::vector 's, or even a class for each ball that stores the sprite number, and each velocity value. The choice is yours.
The if's check various points against the boundaries. Sprites are positioned by their top-left point. Effectively, the left-most point will be the sprite's position, so to see if the ball has hit the left side, you just check to see if the left most point (x position value) is less than or equal to your left bound. With the right bound, you have to take the position and add its width to get the right-most point of the ball.
Then, to get it to "bounce", you multiply the appropriate velocity component by -1. So if it hits the right side, that means it's x component was >0, thus now it is "flipped" and becomes <0, making the ball now start traveling to the left.
This logic is repeated for the y axis.
Hope this helps!
Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose