Thanks for your help I'm going to try it. Also do you know collision detection?
Yes, I know something about collision detection, too.
First it would be useful to know which collisions you would exactly want to detect and how would you want to react to them. You could start by telling what kind of game you are making.
It would also be useful to know how familiar you are with vectors and trigonometric functions. Vectors can sometimes provide really nice solutions.
In the Pong example the collision with the edges of the screen is very simple: when the ball reaches the edge of the screen, either the game ends or the ball's direction is negated. For example, this is the code what happens when the ball hits the top:
if (ball.GetPosition().y < 0.f) // This checks if the ball has reached the top
{
ballSound.Play(); // Play the sound
ballAngle = -ballAngle; // negate the ball's angle to make it appear as if it bounces off the wall
ball.SetY(0.1f); // I'm guessing this is needed to make sure that the ball can't get stuck outside the game area. I tested without it and it appeared to work without it (at least with this setup).
}
The collision between the paddle and the ball, on the other hand, is a simple box-to-box collision detection. You know the coordinates of the objects and you know their sizes so you can just compare the coordinates taking the sizes into account, and determine whether those objects are on top of each other. In semi-pseudo code it would be something like this (assuming that the images are drawn so that the coordinates are on the upper left corner):
If object1.x + object1.width > object2.x And object1.x < object2.x + object2.width And object1.y + object1.height > object2.y And object1.y < object2.y + object2.height Then
Objects_1_and_2_are_on_top_of_each_other
EndIf
So the detection is basically just comparing x and y coordinates taking the sizes of the objects into account.
I really can't help you more than that before you tell me what you actually want to do.