
Go backward to The Right Wall
Go up to Bouncing
The Other Walls
At this point, depending on the speeds
you picked for your ball initially, it is either
falling off the bottom or going through the left wall.
What you should do now is add an if statement to
make the ball bounce off whatever wall it currently
disappears through. Then, run your applet again,
see where it disappears next and fix then add
an if statement for that wall.
In that way, you will add one if statement
at a time until you have one for each wall. They
will all be similar, but:
- The condition to check will depend on the wall.
For the right wall, you checked to
see if the x coordinate was greater than 200.
For the bottom you will need to see if the
y coordinate is greater than 200. For the
top and left walls you will need to see if
the appropriate coordinate is less than 1.
- The assignment statement placed within the if
statement for the right wall reversed the direction
of horizontal motion. You want to do exactly
the same thing for the left wall. For the top
and bottom you want to reverse the direction
of vertical motion by negating the yspeed
variable.
When all the if statements are in place, the ball should
bounce from wall to wall until you select quit from the file
menu.
