i am still using the Dummy book and trying to make a Pong clone
out of the provided functions.
my problem is that whenever
1) the ball tried to hit the left paddle(redpaddle),
heading towards the left direction ( <- )
it moves through it. (which is wrong)
2) the ball tried to hit the left paddle(redpaddle),
heading towards the right direction ( -> ),
reflection occurs. (which is correct)
the code is as below>
void Move_Ball(void)
{
// this function sets the ball moving
Move_BOB(&ball);
//test for collision with redpaddle
//collision with front surface
if (ball.state == BALL_STATE_LEFT)
{
if (Collision_Test(ball.x, ball.y, ball.width, ball.height,
redpaddle.x, redpaddle.y, redpaddle.width, redpaddle.height))
{
ball.state = BALL_STATE_RIGHT;
Start_Ball(20);
}
}
//collision with back surface
if (ball.state == BALL_STATE_RIGHT)
{
if (Collision_Test(ball.x, ball.y, ball.width, ball.height,
redpaddle.x, redpaddle.y, redpaddle.width, redpaddle.height))
{
ball.state = BALL_STATE_LEFT;
Start_Ball(20);
}
}
}//end Move_Ball
and the ball starts towards the left direction ( <- ), using
this function>
void Start_Ball(int vel)
{
// this functions generates the ball and redpaddle starts first
if (ball.state == BALL_STATE_LEFT)
{ ball.xv = -vel;
}
if (ball.state == BALL_STATE_RIGHT)
{ ball.xv = vel;
}
} // end Start_Ball
the defines> #define BALL_STATE_LEFT 0
#define BALL_STATE_RIGHT 1
the initial state(in game_init()> ball.state = BALL_STATE_LEFT