import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

// This class represents a flying bird
public class FlyingBird {

	// Here are the class variables
	public static int	NUM_FRAMES = 8;
	public static int	WIDTH = 78;

	// Here are the instance variables
	private Point   currentLocation;  // the bird's coordinate on the screen
    private Image[] images;           // the frames of the bird (we will have 8)
    private int     currentFrame;    // the frame currently being displayed

	// Here is a default constructor
    public FlyingBird() {
		currentFrame = 4;
		currentLocation = new Point(100,100);
		images = new Image[FlyingBird.NUM_FRAMES];
		for (int i=0; i<NUM_FRAMES; i++) {
		    images[i] = Toolkit.getDefaultToolkit().getImage("birdx" + (i+1) + ".gif");
		}
	}

	// Here are the get methods
	public int getCurrentFrame() { return currentFrame; }
	public Point getCurrentLocation() { return currentLocation; }
          
	// This method allows the frames to advance as well as move the bird
	public void advance() {
		// Move the bird forward
		currentLocation.translate(10,0);

		//Make gravity pull the bird down, unless its wings are flapping
		if (currentFrame > 3)
			currentLocation.translate(0,-5);
		else 
			currentLocation.translate(0,5);

		if (currentFrame != 3)
			currentFrame = (currentFrame + 1) % 8;
    }

	// Set the frame to show the bird starting to flap its wings
	public void flapWings() {
		currentFrame = 4;
	}

	// Return the image representing the bird's current appearance
	public Image appearance() {
		return (images[currentFrame]);
	}
}