
import java.awt.*;
import java.util.*;



public class Creature
    {
      private int x,y;    //  pixel coordinates of upper left corner of
                          //   creature
      private int centerX, centerY;  //  coord.s of center of creature
      private int health;     //
      private int age;        // Not used yet
      private int stepsize;   //  Creatures moves 0..stepsize pixels
                              //   alnong both x,y axes, EACH time step
      private int xdirection;  // Either 1 or -1
      private int ydirection;
      private int diameter;
      private Color current_color;



      public Creature(int input_x, int input_y)
         {
          x = input_x;
          y = input_y;
          diameter = 4;
          age = 0;
          stepsize = 5;
          health = 50;
          current_color = Color.blue;

          if(World.rand_generator.nextBoolean())
             xdirection = 1;
             else xdirection = -1;;
          if(World.rand_generator.nextBoolean())
             ydirection = 1;
             else ydirection = -1;
          }

      public int getX()
          {  return centerX; }
      public int getY()
          {  return centerY; }

      public void move()
         {


           centerX = (int) (x + diameter/2);
           centerY = (int) (y + diameter/2);

           if( x+diameter > World.east)  //  If hit east wall,
                xdirection = -1;         //     then go west
              else if( x < World.west)   //    else if hit west wall,
                xdirection = 1;          //       then go east

		   if(y+diameter > World.south)   //  If hit south wall,
	            ydirection = -1;          //    then go north
              else if(y < World.north)    //    else if hit north wall,
                ydirection = 1;           //       then go south.

           x = x + xdirection * (int) (stepsize *Math.random());
           y = y + ydirection *(int) (stepsize * Math.random());

           if(health>100)    //  up to a max of 100
              health=100;
           if(health > 5)
              health--;              //  it always costs to move.
          }

      public void get_older(int amount)
          {
             age += amount;
           }

      public int get_health()
         {
            return health;
          }

      public void explode(Graphics g_obj)
         {
          Color tempColor = g_obj.getColor();
          int size = 3;
		  g_obj.setColor(current_color);
		  int center_x = x+diameter/2;
		  int center_y = y+diameter/2;
		  for(int i=0; i<10; i++)
		     {
		       for(int j=0; j< 400;j++)
		       g_obj.clearRect(center_x-i,center_y-i,2*i,2*i);
               g_obj.fillOval(center_x+i,center_y+i,size,size);
               g_obj.fillOval(center_x+i,center_y-i,size,size);
               g_obj.fillOval(center_x-i,center_y+i,size,size);
               g_obj.fillOval(center_x-i,center_y-i,size,size);
               g_obj.fillOval(center_x+i,center_y,size,size);
               g_obj.fillOval(center_x,center_y+i,size,size);
               g_obj.fillOval(center_x-i,center_y,size,size);
               g_obj.fillOval(center_x,center_y-i,size,size);
		     }
		  g_obj.clearRect(center_x-3,center_y-3,26,26);
          g_obj.setColor(tempColor);
         }

      public void paint(Graphics g_obj)
        {
         Color tempColor = g_obj.getColor();

         g_obj.setColor(current_color);
         g_obj.fillOval(x,y,diameter,diameter);

         g_obj.setColor(tempColor);
        }
  }
