Hi guys,
I know there’s something wrong my code and I need some help with it. The ball bounces off the top wall and makes its way straight out of the screen. Anyone care to help?
TY
The ball is square and its center is ball_x_pos.
void move_ball ()
{
ball_x_pos += BALL_STEP * x_direction;
ball_y_pos += BALL_STEP * y_direction;
if (ball_x_pos + 2.5 >= RIGHT_MARGIN);
{
int paddle2_top;
int paddle2_bottom;
int right_goal_scored=0;
paddle2_bottom = paddle2_y_position;
paddle2_top = paddle2_bottom + 20;
if ((ball_y_pos+2.5 > paddle2_bottom)&&(ball_y_pos-2.5 < paddle2_top))
x_direction = -1;
else
right_goal_scored++;
/* RIGHT_GOAL = right_goal_scored;*/
}
if (ball_x_pos - 2.5 <= LEFT_MARGIN);
{
int paddle_top;
int paddle_bottom;
int left_goal_scored=0;
paddle_bottom = paddle_y_position;
paddle_top = paddle_bottom + 20;
if ((ball_y_pos+2.5 > paddle_bottom)&&(ball_y_pos-2.5 < paddle_top ))
x_direction = -1;
else
left_goal_scored++;
/* LEFT_GOAL=left_goal_scored;*/
}
if (ball_y_pos+2.5 >= TOP_MARGIN| | ball_y_pos-2.5 <= BOTTOM_MARGIN)
{
y_direction = -1;
}
glutTimerFunc(50, move_ball, 1);
glutPostRedisplay();
}