package MissileCommand;





public class GoodExplosion extends GP.Animator implements MCConstants  {


  private GP.Graphics.FilledOval _radius;
  private GP.Graphics.Line _line;
  private int _size;
  private Holder _holder;


  public GoodExplosion(GP.Container frame, Holder holder, GP.Graphics.Line line, double x, double y) {

    super(frame);

    _line=line;
    _holder=holder;

    _size=10;

    // we'll make our blast radius a circle, and grow it through use of an animator
    _radius=new GP.Graphics.FilledOval(frame);
    _radius.SetColor(new GP.Attributes.Colors.Green());
    _radius.SetSize(new GP.Attributes.Size(_size,_size));
    _radius.SetPosition(new GP.Attributes.Position(x,y));

    _holder.addExplosion(_radius);
    

  }



  public void Action() {
    
    _size +=10;

    _radius.SetSize(new GP.Attributes.Size(_size,_size));
    
    /** This bit here is just a snazzy color cycling routine to make the
      * explosions easier to pick up onscreen.  It picks 3 random numbers
      * between 3 and 240, one each for red, green, and blue.  It then sets
      * the color of _radius, the circle indicating the blast radius of the
      * explosion, to those values.  Since Action for this class gets called
      * roughly 8 times, the color changes roughly 8 times.
      */
    int r=cs015.SP.RandomNumberFactory.RandomNumber(3,240);
    int g=cs015.SP.RandomNumberFactory.RandomNumber(3,240);
    int b=cs015.SP.RandomNumberFactory.RandomNumber(3,240);
    _radius.SetColor(new GP.Attributes.Color(r,g,b));
    
  
    if (_size > BLAST_RADIUS) {
      _radius.Hide();
      _line.Hide();
      this.Stop();
      _holder.removeExplosion(_radius);
    }
    
  }




}
