*** My doubt is in the "Void Principal" part of the program! [take a look, please]They want us to have a blue ball moved by the mouse cursor [ok, i did that]... and at the same time they want red balls coming from the TOP of the screen [ONE by ONE] going to different directions! The program will finish when we hit the blue ball in one of the red balls... that's when my doubt starts! I created a FOR command for the red ball... but this For command never stops, so, the next red ball never comes! I'd like a help of you to make the next balls come from the top of the screen... and if u also could take a look at what I did in the IF command I opened to make the program finishes when the red ball is hit by the blue one! I think it's not right at all! Please, help me!!!

This is the code in question. It is called your "main loop". If you look at what's happening, it's not at all what you need to be happening.

The while part is good. You want your code to run until the escape key is pressed. In other words, while the escape key is not pressed. That's fine. Inside the loop, You need to separate your code into logic and drawing.

First, make a list of what you need to keep track of. In this case, it's the ball's position. Store these variables outside of the loop:

Then, in the logic section, move the ball by changing ball_x and ball_y. Also check if the player has moved the mouse over the ball in this section. And finally, in the drawing section, draw the player's ball using mouse_x and mouse_y and draw the ball using the stored ball_x and ball_y.

I hope that all makes sense. Don't worry if the ball zooms off-screen faster than you can hover over it. You'll need to get into timers to fix that issue.

When the red ball disappears of the screen, it must appear a new one! But this for command seems never stop, so, when i create another for command for another red ball, it doesn't work, cos the 1st FOR is still running... so the next ball never comes... that's the problem! what do i do? is there a way to do these balls coming one by one without using FOR?!

Doesn't work Paul!Actually, there's no error... but this code just makes the same ball coming always in the same direction... and the right thing should be the ball coming in a direction... when it disappears of the screen, another ball comes in another direction... and it goes till we hit one of them with the blue ball [which is the mouse cursor]

But this command will only work if the mouse cursor hits EXACTLY the center of the red ball (coordinates i,j), which is not pretty good! the best thing to do is to finish the program if the blue ball hits ANY part of the red ball, not exactly the center, cos it makes more difficult to hit it!

That's just stupid. Why would you use bounding box collision detection for detecting collisions between circles?

Box collision is easier to understand than circle/cirlcle collision, that's why I showed him the b. box collision function. Also, I think he does not need so much precision in his program.However, Miran's code is the best way to solve this problem, obviously.

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

No, it's me too. Even when you go into bouncing reaction, the circle-circle thing is not very difficult. You can define a line from one circle to the other (middle points), you can find out the collision point on this line, you can define the tangential line through this point. Now you have an imaginary wall that both circles collide against. And so on.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

My thought exactly.Break the problem down into sub-problems until you reach something you can't divide any further. If you can solve it, do so. If you can't, come back here.

Here are a few things to google / forum-search:- main loop- collision detection- separate logic and drawingand more generally:- game programming

Set up a main loop. This should do logic and drawing.Logic needs to:- update player position- update ball position- check if ball hits player -> end game- check if ball is outside screen -> reset ball coordinates and speedDrawing is just drawing.