Create a program that is a ball that moves across the screen until it reaches an edge of the screen, then have it change direction “bouncing” backward like this:
Hint: Create variables x & y to keep track of your position on the screen. Create variables xDirection and yDirection to keep track of how much to move left/right or up/down each loop:
x += xDirection;
y += yDirection;
when you hit a wall, change direction:
if (x> width)
{
xDirection = xDirection * -1;
}