
 ////////////////////// advanced class operations
 ///////////////////////// derived class :> sprite_object

  class  csprite_object
      {
      private:
	int ButtonStatus;
	int ClassInteger;

      protected:

      public:

      typedef
      struct
	   {
	    int dx;
	    int dy;
	    int sdx;
	    int sdy;
	    int dxabs;
	    int dyabs;
	    int x,x1,x2;
	    int y,y1,y2;
	    int px;
	    int py;
	    int i;
	    int cursor;
	    int speed;
	   }Seek;

      // using the structure for a Homing Missle system
      Seek Homer;


	 csprite sprite;
	 csprite fire;
	 csprite HomingFire;


      // fire speed information
	int FireSpeed;
	int SpriteSpeed;
     // pointer to the object;
     typedef csprite_object *csprite_object_ptr;



  ///////////////////  combined advanced functions
  void csprite_object::HomeCall 	(void);
  void csprite_object::Home		(csprite_object *Target);
  void csprite_object::initialize 	(int xx, int yy);
  void csprite_object::MouseScanControl	(int xx, int yy);
  void csprite_object::MouseFeelControl	(void);
  int  csprite_object::OutOfBoundary 	(void);
  void csprite_object::InBoundary       (void);
  void csprite_object::KeyboardControl 	(void);
  void csprite_object::VerticalVibration(int yy);

       };

    void csprite_object::VerticalVibration(int yy)
    {
    if( (sprite.y <= yy) || (sprite.y > (Getmaxy-sprite.height-yy)))
    {
     ClassInteger*=(-1);
    }
    sprite.y += ClassInteger;
    }

    void csprite_object::InBoundary (void)

    {
	    if (/****/sprite.x < 0 )
		/****/sprite.x = 0;
	    else
	    if (/****/sprite.x > (Getmaxx - sprite.width))
		/****/sprite.x = (Getmaxx - sprite.width);

	   if (/****/sprite.y < 0 )
		/****/sprite.y = 0;
	    else
	    if (/****/sprite.y > (Getmaxy - sprite.height))
		/****/sprite.y = (Getmaxy - sprite.height);

     }




  void csprite_object:: KeyboardControl (void)

  {
	// cursor control
	if(key_up)	   {sprite.y -= SpriteSpeed;}
	else if (key_down) {sprite.y += SpriteSpeed;}

	if(key_left)       {sprite.x -= SpriteSpeed;}
	else if (key_right){sprite.x += SpriteSpeed;}


	//fire control
	if (key_Ctrl)
		{
	       ButtonStatus=2;
		}

  }

   void csprite_object::MouseScanControl(int xx, int yy)
     {
	 ScanMouse(&sprite.x,&sprite.y,&ButtonStatus);

	   sprite.x+=xx;
	   sprite.y+=yy;

	    if (/****/sprite.x < 0 )
		/****/sprite.x = 0;
	    else
	    if (/****/sprite.x > (Getmaxx - sprite.width))
		/****/sprite.x = (Getmaxx - sprite.width);

	   if (/****/sprite.y < 0 )
		/****/sprite.y = 0;
	    else
	    if (/****/sprite.y > (Getmaxy - sprite.height))
		/****/sprite.y = (Getmaxy - sprite.height);

     }

     #define sign(x) ((x<0)?-SpriteSpeed:((x>0)?SpriteSpeed:0))
   void csprite_object::MouseFeelControl (void)
     {
       int xx,yy;

	 FeelMouse(&xx,&yy);

	   sprite.x+=sign(xx);
	   sprite.y+=sign(yy);

	    if (/****/sprite.x < 0 )
		/****/sprite.x = 0;
	    else
	    if (/****/sprite.x > (Getmaxx - sprite.width))
		/****/sprite.x = (Getmaxx - sprite.width);

	   if (/****/sprite.y < 0 )
		/****/sprite.y = 0;
	    else
	    if (/****/sprite.y > (Getmaxy - sprite.height))
		/****/sprite.y = (Getmaxy - sprite.height);

     }



      void csprite_object::Home (csprite_object *Target)
      {
	if (/****/HomingFire.state == 0)
	      {
   /****/Homer.x1=   /****/sprite.x+/****/sprite.width;
   /****/Homer.y1=   /****/sprite.y+(/****/sprite.height>>1);
   /****/Homer.x2=   Target->sprite.x;
   /****/Homer.y2=   Target->sprite.y+(Target->sprite.height>>1);
   /****/HomingFire.state = SPRITE_ALIVE;
   /****/Homer.i=0;

  /****/Homer.dx=/****/Homer.x2-/****/Homer.x1;      /* the horizontal distance of the line */
  /****/Homer.dy=/****/Homer.y2-/****/Homer.y1;      /* the vertical distance of the line */
  /****/Homer.dxabs=abs(/****/Homer.dx);
  /****/Homer.dyabs=abs(/****/Homer.dy);
  /****/Homer.sdx=sgn(/****/Homer.dx);
  /****/Homer.sdy=sgn(/****/Homer.dy);
  /****/Homer.x=/****/Homer.dyabs>>1;
  /****/Homer.y=/****/Homer.dxabs>>1;
  /****/Homer.px=/****/Homer.x1;
  /****/Homer.py=/****/Homer.y1;

       }
     }

void csprite_object::HomeCall (void)
{
    if (/****/HomingFire.state == SPRITE_DEAD)
    {
//    /****/Homer.i=0;
    return;
    }

  /****/Homer.i+=/****/Homer.speed;

  if (/****/Homer.dxabs>=/****/Homer.dyabs) /* the line is more horizontal than vertical */
  {
//    if ((/****/Homer.i>=/****/Homer.dxabs))
//     {
//     /****/HomingFire.state = SPRITE_DEAD;
//     return;
//     }
    for(/****/Homer.cursor=0;
    /****/Homer.cursor<=/****/Homer.speed;
    /****/Homer.cursor++)

    {
      /****/Homer.y+=/****/Homer.dyabs;
      if (/****/Homer.y>=/****/Homer.dxabs)
      {
	/****/Homer.y-=/****/Homer.dxabs;
	/****/Homer.py+=/****/Homer.sdy;
      }
      /****/Homer.px+=/****/Homer.sdx;
    }
  }
  else /* the line is more vertical than horizontal */
  {
//     if (/****/Homer.i>= /****/Homer.dyabs)
//     {
//     /****/HomingFire.state = SPRITE_DEAD;
//     return;
//     }
      for(/****/Homer.cursor=0;
      /****/Homer.cursor<=/****/Homer.speed;
      /****/Homer.cursor++)
	{
      /****/Homer.x+=/****/Homer.dxabs;
      if (/****/Homer.x>=/****/Homer.dyabs)
      {
	/****/Homer.x-= /****/Homer.dyabs;
	/****/Homer.px+=/****/Homer.sdx;
      }
      /****/Homer.py+=/****/Homer.sdy;
    }


  }

      /****/HomingFire.x = /****/Homer.px;
      /****/HomingFire.y = /****/Homer.py;
      /****/HomingFire.paste_db();
}

   void csprite_object::initialize (int xx, int yy)
     {
     sprite.initialize(xx,yy);

     fire.initialize(0,0);
     fire.state     = SPRITE_DEAD;
     fire.frames[0]=  Explosion.data;
     fire.width     = Explosion.width;
     fire.height    = Explosion.height;

     HomingFire.initialize(0,0);
     HomingFire.state     = SPRITE_DEAD;
     HomingFire.frames[0] = Explosion.data;
     HomingFire.width     = Explosion.width;
     HomingFire.height    = Explosion.height;

     Homer.speed=10;
     FireSpeed  =5;
     SpriteSpeed=1;
     ClassInteger=SpriteSpeed;
     }





