I'll probably rewrite the ball moving section of the game when I can actually get the ball moving, lol. For some reason I'm having problems getting the ball moving much. I probably screwed up on my math, today wasn't a good day to be doing the math for the ball, I wasn't thinking very mathematically. Here's the code I'm using the move the ball. ball_x is the ball's x position, ball_y is the ball's y position, brd_x is the player's board's x position, cmp_brd_x is the computer's board's x position, ball_move_x is how much to move the ball's x position, ball_move_y is how much to move the ball's y position, and g_score is the player's score. The game field is: upper left: (9, 80), upper right: (600, 80), lower left: (9, 440), lower right: (600, 440). I would really appreciate any help anyone could post about this. Here's the code:
** beginning of code **
void move_ball(int ball_x, int ball_y)
{
// check to see if the ball hits a side barrier
// if so bounce ball
if (ball_x > 600)
{
ball_move_x = - 10;
sound(1000);
}
else if (ball_x < 9)
{
ball_move_x + 10;
sound(1000);
}
// check to see if the ball has passed a paddle
// if so add or subtract points, and change round
else if ((ball_x > brd_x + 63 | | ball_x < brd_x) && ball_y > 440)
g_score[0] = g_score[0] - 20;
else if ((ball_x < cmp_brd_x + 63 | | ball_x < cmp_brd_x) && ball_y < 80)
g_score[0] = g_score[0] + 50;
// do paddle bouncing
// Player 1
// Left 22.5 degree
else if (ball_x > brd_x && ball_x < (brd_x + 9)
&& ball_y < 442)
{
ball_move_x = - 2.5;
ball_move_y = - 1;
sound(800);
}
// Left 45 degree
else if (ball_x > (brd_x + 9) && ball_x < (brd_x + 18)
&& ball_y < 442)
{
ball_move_x = -1;
ball_move_y = -1;
sound(800);
}
// Left 67.5 degree
else if (ball_x > (brd_x + 18) && ball_x < (brd_x + 27)
&& ball_y < 442)
{
ball_move_x = -.4;
ball_move_y = -1;
sound(800);
}
// Center 90 degree
else if (ball_x > (brd_x + 27) && ball_x < (brd_x + 34)
&& ball_y < 442)
{
ball_move_x = 0;
ball_move_y = -1;
sound(800);
}
// Right 67.5 degree
else if (ball_x > (brd_x + 34) && ball_x < (brd_x + 45)
&& ball_y < 442)
{
ball_move_x = .4;
ball_move_y = -1;
sound(800);
}
// Right 45 degree
else if (ball_x > (brd_x + 45) && ball_x < (brd_x + 54)
&& ball_y < 442)
{
ball_move_x = 1;
ball_move_y = -1;
sound(800);
}
// Right 22.5 degree
else if (ball_x > (brd_x + 54) && ball_x < (brd_x + 63)
&& ball_y < 442)
{
ball_move_x = 2.5;
ball_move_y = -1;
sound(800);
}
// Computer
// Left 22.5 degree
else if (ball_x > cmp_brd_x && ball_x < (cmp_brd_x + 9)
&& ball_y < 82)
{
ball_move_x = -2.5;
ball_move_y = 1;
sound(400);
}
// Left 45 degree
else if (ball_x > (cmp_brd_x + 9) && ball_x < (cmp_brd_x + 18) && ball_y < 82)
{
ball_move_x = -1;
ball_move_y = 1;
sound(400);
}
// Left 67.5 degree
else if (ball_x > (cmp_brd_x + 18) && ball_x < (cmp_brd_x + 27) && ball_y < 82)
{
ball_move_x = -.4;
ball_move_y = 1;
sound(400);
}
// Center 90 degree
else if (ball_x > (cmp_brd_x + 27) && ball_x < (cmp_brd_x + 34) && ball_y < 82)
{
ball_move_x = 0;
ball_move_y = 1;
sound(400);
}
// Right 67.5 degree
else if (ball_x > (cmp_brd_x + 34) && ball_x < (cmp_brd_x + 45) && ball_y < 82)
{
ball_move_x = .4;
ball_move_y = 1;
sound(400);
}
// Right 45 degree
else if (ball_x > (cmp_brd_x + 45) && ball_x < (cmp_brd_x + 54) && ball_y < 82)
{
ball_move_x = 1;
ball_move_y = 1;
sound(400);
}
// Right 22.5 degree
else if (ball_x > (cmp_brd_x + 54) && ball_x < (cmp_brd_x + 63) && ball_y < 82)
{
ball_move_x = 2.5;
ball_move_y = 1;
sound(400);
}
else
{
ball_x = ball_x + ball_move_x;
ball_y = ball_y + ball_move_y;
}
// Show score
outtextxy(61, 0, &score[0]);
// Stop bounce sound
nosound();
// Move ball
ball_x = ball_x + ball_move_x;
ball_y = ball_y + ball_move_y;
circle(ball_x, ball_y, ball_radius);
}
** end of code **
Thanx for any help.