- Viewing Profile: Posts: JDCAce
Community Stats
- Group Members
- Active Posts 12
- Profile Views 730
- Member Title Member
- Age 25 years old
- Birthday December 6, 1987
-
Gender
Male
User Tools
Contacts
JDCAce hasn't added any contacts yet.
Posts I've Made
In Topic: Still confused about "static"
07 October 2012 - 12:51 AM
In Topic: Pong Hit Detection
01 October 2012 - 02:49 PM
This project really has turned out to be a valuable learning experience, and I can't thank all of you enough!
private void checkHit()
{
float intersectY = ball.location.Y;
float relativeIntersectY;
float normalizedRelativeIntersectY;
double bounceAngle;
if(leftPaddle.rectangle.Intersects(ball.rectangle))
{
relativeIntersectY = (leftPaddle.location.Y + (leftPaddle.Height / 2)) - intersectY;
normalizedRelativeIntersectY = (relativeIntersectY / (leftPaddle.Height / 2));
bounceAngle = (normalizedRelativeIntersectY * (Math.PI / 4));
ball.velocity.X = (float)(10 * Math.Cos(bounceAngle));
ball.velocity.Y = (float)(5 * -Math.Sin(bounceAngle));
}
else if(rightPaddle.rectangle.Intersects(ball.rectangle))
{
relativeIntersectY = (rightPaddle.location.Y + (rightPaddle.Height / 2)) - intersectY;
normalizedRelativeIntersectY = (relativeIntersectY / (rightPaddle.Height / 2));
bounceAngle = (normalizedRelativeIntersectY * (Math.PI / 4));
ball.velocity.X = (float)(10 * Math.Cos(bounceAngle));
ball.velocity.Y = (float)(5 * -Math.Sin(bounceAngle));
ball.velocity.X = -ball.velocity.X;
}
}
In Topic: Pong Hit Detection
30 September 2012 - 08:00 PM
UPDATE: It works! Using some math I found elsewhere, I got my program to run flawlessly! Now for my next project: Randomly-dropped power-ups!
In Topic: Pong Hit Detection
29 September 2012 - 06:59 PM
- The ball has a velocity(X,Y) and a position(X,Y) as type: double or float. Each update you do m_Position += m_Velocity; So the ball moves depending on his velocity.
- Create 1 Hitregion(Rectangle) for 1 paddle
- When the hitregion of the paddle and the ball return true...
- Calculate a vector from the center of the paddle and the center of the ball.
- Merge that vector and the velocity of the ball.
- (This depends on how the vector is calculated) you might need to reverse the X-value of the new velocity so the ball goes the other way.
... I don't know what a vector is. (I know what a vector in physics is, but I don't know anything about them in gaming/programming terms.) I'll go look it up and try out your suggestion! However, what do you mean "merge the vectors?" Is merging something I'll learn about when looking up vectors?
Also, in response to Pyrodrgn, I do have a Paddle class and a Ball class. I'm still getting used to making my own objects like this, and I'm still not very good at deciding what each class should be in charge of.
In Topic: Starting Puzzle With Solution
23 September 2012 - 10:05 AM
- Home
- » Viewing Profile: Posts: JDCAce

Find content