I'm trying to create a text clone pong and would like some help on creating the function for the ball. I've found some source code and tried to modify it for my use only for it to not work.
Code:
struct playerData {
int x,y,score;
int oldy;
};
struct ballData {
int x,y;
int oldy, oldx;
};
struct playerData player1 = {3,10}, player2 = {78,10};
struct ballData ball = {40,10};
void drawBall(void)
{
int xinc,yinc;
if(ball.x < 0)
player2.score++;
if(ball.x > 79)
player1.score++;
if(ball.x == 3)
xinc = 1;
if(ball.x == 23)
xinc= -1;
if(ball.y == 23)
xinc= -1;
if(player1.x <= 3 && 3 < player1.x && player1.y == 2)
yinc = 1;
if(player2.x <= 3 && 3 < player2.x && player2.y == 78)
yinc = -1;
gotoxy(ball.oldx,ball.oldy);
printf(" ",BALL);
gotoxy(ball.x,ball.y);
printf("%c",BALL);
ball.oldx = ball.x;
ball.oldy = ball.y;
ball.x += xinc;
ball.y += yinc;
}