import objectdraw.*;
import java.applet.*;
import java.awt.*;

public class FallingCow extends FallingObject
{

  private static final int COW_HEIGHT = 70;
  private static final int COW_WIDTH = 100;
  private static final int COW_PAUSE = 30;
  private static final int COW_WALK_SPEED = -3;
  private static final int COW_FALL_SPEED = 4;


  private DrawingCanvas canvas;

  // image for walking cow
  private Image cow;

  // be sure to import java.applet.awt
  private AudioClip moo;

  // Creates a falling purple cow
  public FallingCow(DrawingCanvas aCanvas,
             Image upsideDownCow,
             Image normalCow,
             AudioClip aMoo,
             double x, int groundHeight) {
    // Create a generic falling object
    super (groundHeight - COW_HEIGHT, COW_FALL_SPEED);

    canvas = aCanvas;
    cow = normalCow;
    moo = aMoo;

    // Specialize it to be an upside down cow.
    object = new VisibleImage(upsideDownCow, x,
                              -COW_HEIGHT, canvas);

    // Start it falling
    this.start();
  }

  protected void hitBottom() {
    // play moooing noise
    moo.play();

    object.removeFromCanvas();

    // make cow walk back to the left
    VisibleImage walkingCow =
        new VisibleImage(cow, object.getLocation(), canvas);

    while (walkingCow.getX() + COW_WIDTH > 0) {
      pause(COW_PAUSE);
      walkingCow.move(COW_WALK_SPEED, 0);
    }

    walkingCow.removeFromCanvas();
  }
}
