Fang Decision Exercise - Move a ball back and forth in a line.
Make your blue ball a moving target that can only move in a certain path. It
should move in a single row, so its Y setting will never change. Do not make
it move to a random location for a collision.
Steps:
Add 2 new class variables:
- Need to keep track of Blue's x location, so add a blueX variable.
- Need to keep track of whether Blue is moving right or left, so add a blueDirection
integer variable.
- (note: Whenever you set the location of Blue, also set the blueX variable.)
Change MakeSprites:
- In the initial start of blueDot, be sure to set the blueX variable value.
- Set the initial blueDirection variable to 1.
Make a new method to moveBlue.
- If blueX >= .9, then the ball is on the right edge, and its blueDirection
should change to -1.
- If blueX<=.1, the ball is on the left edge, and its blueDirection should
change to 1.
- Always Move .1 * the blueDirection. (so Right is + .1 and Left is -.1)
Change AdvanceFrame:
- Add moveBlue to the advance method so blue moves every time the game advances.
An Extra: There are methods for OvalSprite that will set a facing direction
and let you move forward.
- public void setOrientationDegrees(double degrees)
- public void forward(double distance)
An Extra: When it is intersected, move to a random x location, but its Y will
stay the same.