A new problem i have at the moment is sometimes when the ball is bouncing around the screen, it may all of a sudden get stuck colliding with a rectangle, so it may hit a spot between the rectangle and the side of the screen. This sometimes results in either: a) the ball looks like it's shaking or something, which i am assuming as it's still colliding with the rectangle, it's velocity (as i have defined it) is constantly inversing... but it's still stuck... (that's what i cant solve... lol :( ), or b) when the ball collides with the rectangle, it starts to move along the edge of the rectangle and goes back and forth but it continues to do this... (so it's basically stuck moving just along the edge).
I have uploaded a video to youtube showing this in action (btw... the ball gets stuck and goes up and down the right side of the screen and then starts going along the top edge of the white rectangle and then eventually bounces off into oblivion... well basically frees itself, which is kind of ok but then if you wait 5 more seconds, it repeats this process)
http://www.youtube.com/watch?v=3qfpgtoWbIU&feature=youtu.be
the code i am using for collision detection with the rectangle is:
if (theBall.GetRectangle.Bottom >= cornerSquare.GetRectangle.Top && theBall.GetRectangle.Bottom <= cornerSquare.GetRectangle.Bottom)
{
theBall.pVelocity.Y = -theBall.pVelocity.Y;
}
thats for detection if the ball hit's the top of the rectangle.
detection with the right side of the screen is:
if (pPosition.X + pTexture.Width >= screenWidth)
{
pVelocity.X = -pVelocity.X;
}
I hope someone has a simple and effective solution to this as i just want to 'be done' with all this collision detection nonsense lol... as it's taking up most of my time whilst i could be alot more productive doing other parts of the game.
Thanks for reading, taking the time to read, taking the time to help.... ETC.... :D