New course! Every coder should learn Generative AI!
Try a free lesson+ 4
If it is only the motion of a ball bouncing to a straight wall like in pong, you could do it easy by separate x direction and y direction of the ball and just multiply on of these by -1.
short example(not tested only for explanation):
int [2] ballpos = {12, 24};
int [2] ballvelo = {-1, -3};
void updateBallPos(&ballpos[2], &ballvelo[2]){
ballpos[0] += ballvelo[0];
ballpos[1] += ballvelo[1];
}
void reflectBallX( &ballvelo[2]){
ballvelo[0] *= - 1;
}
void reflectBallY( &ballvelo[2]){
ballvelo[1] *= - 1;
}
In main you can call updateBallPos periodically (every 20 ms e.g.). If an collision with a wall accured you just have to call the right reflect function. Hopefully that helps you.