//Declaration de la class cercle avec ses fonctions membres 

//************************
//*** class_cercle.hpp ***
//************************

//Version 1.0

//Developed with Dev C++ 5.2.0.3 & Allegro 5.0.6

//By Alain Galiani
//Dedalusman
//nageondu@gmail.com

//Start          17 09 2011
//Finished       00 00 2012
//Last updat     17 09 2011

//History:

/*

*/

//********************==========================================================
//*** class_cercle ***==========================================================
//********************==========================================================

class class_cercle
{public:

  //*** DATAS ***

  lm4o ray;
  ALLEGRO_COLOR cou;
  lm4o pos_x,pos_y;
  lm4o vv_x,vv_y;

  lm4o b_sup_x,b_inf_x;
  lm4o b_sup_y,b_inf_y;

  lm4o lx_inf;
  lm4o lx_sup;
  lm4o ly_inf;
  lm4o ly_sup;

  //*** FONCTIONS ***

  void animation();
  void dessine();
  void dessine_plein();
  void creation(lm4o x,lm4o y,lm4o r,ALLEGRO_COLOR c,lm4o vx,lm4o vy);
  void hasard(lm4o r1,lm4o r2);
  void espace(lm4o lxi,lm4o lxs,lm4o lyi,lm4o lys);
};

void class_cercle::animation()
{
  pos_x+=vv_x;
  pos_y+=vv_y;

  b_sup_x=pos_x+ray;
  b_inf_x=pos_x-ray;
  b_sup_y=pos_y+ray;
  b_inf_y=pos_y-ray;

  if(b_sup_x>lx_sup)
  {
    vv_x=-vv_x;
    pos_x=(lx_sup+lx_sup)-pos_x-(ray+ray);
  } 
  else
  {
    if(b_inf_x<lx_inf)
    {
      vv_x=-vv_x;
      pos_x=-pos_x+(ray+ray)+(lx_inf+lx_inf);
    }
  }

  if(b_sup_y>ly_sup)
  {
    vv_y=-vv_y;
    pos_y=(ly_sup+ly_sup)-pos_y-(ray+ray);
  } 
  else
  {
    if(b_inf_y<ly_inf)
    {
      vv_y=-vv_y;
      pos_y=-pos_y+(ray+ray)+(ly_inf+ly_inf);
    }
  }
}

void class_cercle::dessine()
{
  al_draw_circle(pos_x,pos_y,ray,cou,1);
}

void class_cercle::dessine_plein()
{
  al_draw_filled_circle(pos_x,pos_y,ray,cou);
}

void class_cercle::creation(lm4o x,lm4o y,lm4o r,ALLEGRO_COLOR c,lm4o vx,lm4o vy)
{
  pos_x=x;
  pos_y=y;
  ray=r;
  cou=c;
  vv_x=vx;
  vv_y=vy;

  b_sup_x=x+r;
  b_inf_x=x-r;
  b_sup_y=y+r;
  b_inf_y=y-r;
}

void class_cercle::hasard(lm4o r1,lm4o r2)
{
  lm4o h;
  lm4o d,dx,dy;

  h=rand();
  d=r2-r1;
  ray=((h*d)/32767)+r1;

  h=rand();
  dx=lx_sup-lx_inf;
  pos_x=((h*dx)/32767)+lx_inf;

  if ((pos_x+ray)>=lx_sup)
  {
    pos_x=lx_sup-ray-2;
  }
  else
  {
    if((pos_x-ray)<=lx_inf)
    {
      pos_x=lx_inf+ray+2;
    }   
  }

  h=rand();
  dy=ly_sup-ly_inf;
  pos_y=((h*dy)/32767)+ly_inf;

  if ((pos_y+ray)>=ly_sup)
  {
    pos_y=ly_sup-ray-2;
  }
  else
  {
    if((pos_y-ray)<=ly_inf)
    {
      pos_y=ly_inf+ray+2;
    }   
  }

  cou=al_map_rgb(rand(),rand(),rand());

  h=rand();
  vv_x=((h*14)/32767)+1;
  if(rand()>16384)vv_x=-vv_x;

  h=rand();
  vv_y=((h*14)/32767)+1;
  if(rand()>16384)vv_y=-vv_y;

  b_sup_x=pos_x+ray;
  b_inf_x=pos_x-ray;
  b_sup_y=pos_y+ray;
  b_inf_y=pos_y-ray;
}

void class_cercle::espace(lm4o lxi,lm4o lxs,lm4o lyi,lm4o lys)
{
  lx_inf=lxi;
  lx_sup=lxs;
  ly_inf=lyi;
  ly_sup=lys;
}
