import java.awt.*;
import java.awt.event.*;

public class Dragon extends AnimatedSprite
{
  //
  // Define the states of the Dragon object
  private static final int FLYING = 0;
 
  //
  // Define the different tracks of the Dragon object
  private static final int[] FR_TRACK = {0, 1, 2, 3, 4, 5};
  private static final int[] FL_TRACK = {6, 7, 8, 9, 10, 11};

  //
  // Define aliases for the Dragon's different tracks
  private static final int FR = 0;
  private static final int FL = 1;

  //
  // Define defaults
  private static final int DEFAULT_STATE     = FLYING;
  private static final int DEFAULT_TRACK     = FL;
  private static final int DEFAULT_VELOCITY  = 15;
  private static final int DEFAULT_DIRECTION = Ps1Defs.LEFT;

  /*
   * Class constructor.  Takes a 12-image strip, 
   * and converts it to an animated dragon
   */
  public Dragon(Image dragonImage)
  {
    super(dragonImage, 12);

    // Add tracks to this Dragon
    addTrack(FR_TRACK);
    addTrack(FL_TRACK);
    
    // Initialize the Dragon's state to default values
    setState(DEFAULT_STATE);
    setTrack(DEFAULT_TRACK);        
    setVelocity(DEFAULT_VELOCITY);
    setDirection(DEFAULT_DIRECTION);
  }

  /*
   * Updates the state of this Dragon object
   */
  public void updateState(Raster raster)
  {
    int velocity;
    int x;
    
    velocity = getVelocity();  // The velocity of the Dragon
    x        = getX();         // The x-position of the Dragon

    switch (getDirection())
      {
      case Ps1Defs.RIGHT: setX(x + velocity); break;
      case Ps1Defs.LEFT: setX(x - velocity); break;
      }
    
    x = getX();
    if (x < 100) 
      {
	setDirection(Ps1Defs.RIGHT);
	setTrack(FR);
      }
    if (x > getPlayfield().getWidth() - 100)
      {
	setDirection(Ps1Defs.LEFT);
	setTrack(FL);
      }
  }
  
  /*
   * Draws this Dragon object to the specified Raster
   */ 
  public void draw(Raster raster)
  {
    updateState(raster);
    super.draw(raster);
  }

  /*********************************************************
   *                                                       *
   *                    EVENT HANDLERS                     *
   *                                                       *
   ********************************************************/
  
  public void keyPressed(KeyEvent e)      {}
  public void keyReleased(KeyEvent e)     {}
  public void keyTyped(KeyEvent e)        {}
  public void mouseClicked(MouseEvent e)  {}
  public void mousePressed(MouseEvent e)  {}
  public void mouseReleased(MouseEvent e) {}
  public void mouseEntered(MouseEvent e)  {}
  public void mouseExited(MouseEvent e)   {}
	  
}


