In this program, you write some code to animate a hang glider flying above the Manhattan skyline. The graphics window is like quadrant IV in math class, except that the y-coordinates are positive. As an object moves to the right, its x-coordinate increases. As an object moves down, its y-coordinate increases. You can adjust the speed of the animation by changing 'DELAY' in Board.java. Below are 4 challenges.
1. Get the hang glider to move
In Glider.java, write the contents of the move method. You can increase the x and y coordinates of the glider by a small amount each time the method is called. Since the move method is called many times, this will get the glider to move across the NYC skyline.
2. Get the hang glider to stop
Add code to move() so that the hang glider stops near the bottom of the NYC image.
3. Get the hang glider to go back up
After the hang glider reaches the bottom of the NYC image, create and call a Glider method move2 that causes the hang glider to fly back up into the NYC skyline. (Alternatively, this code can be written entirely in move().) The hang glider does not have to stop when it reaches a given elevation; it can simply sail off the screen. One way to do this involves creating a boolean 'down' that keeps track of whether the hang glider is going down or up.
4. Try the code below in move() and see what it does
You'll need to declare the variables 'angle' and 'i'.
angle = i/150.0;
x = (int)(350+100*Math.cos(angle));
y = (int)(5+100*Math.sin(angle)+0.00005*i*i);
Get the hand glider to move in a different way than 1-4 above, and not in a straight line. For example, you could have the hang glider follow a parabolic path.
You can download
to use as starting points for this program.
You can also download these 2 image files: