Could you be a little more descriptive? I am having trouble understanding completely, but here is my suggestion from what I can tell...
Code:
typedef struct
{
int xPos, yPos;
int xStep, int yStep;
int radius;
} Ball; // Each ball has its own velocity, so I added it to the struct.
// Checks to see if the ball *bounceMe intersects line
// *bounceOffMe and changes the velocity of bounceMe
// appropriately if it does. Returns whether *bounceMe actually
// hit *bounceOffMe
int bounceBall (Ball * bounceMe, lineT const * bounceOffMe)
{
int bounce = 0;
int A, B, C, X, Y;
int xStepNew;
int yStepNew;
if (ballIntersectsLine (bounceMe, bounceOffMe) {
bounce = 1;
X = bounceOffMe -> x2 - bounceOffMe -> x1;
Y = bounceOffMe -> y2 - bounceOffMe -> y1;
A = X * Y;
B = X * X - Y * Y;
C = X * X + Y * Y;
xStepNew = (2 * bounceMe -> yStep * A + bounceMe -> xStep * B) / C;
yStepNew = (2 * bounceMe -> xStep * A - bounceMe -> yStep * B) / C;
bounceMe -> xStep = xStepNew;
bounceMe -> yStep = yStepNew;
}
return bounce;
}
As you can see, the formula for a bounce is something of a monster (it is possible I got the formula wrong even, but I'm pretty sure this is it).