//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------


void Progression ( )
{
    if(cpt==0)
    {
        tempx1=vx1; tempy1=vy1; tempz1=vz1;
        tempx2=vx2; tempy2=vy2; tempz2=vz2;
        tempx3=vx3; tempy3=vy3; tempz3=vz3;
 
        resultx1=fabs(vx3-vx1); resulty1=fabs(vy3-vy1); resultz1=fabs(vz3-vz1);
        resultx2=fabs(vx1-vx2); resulty2=fabs(vy1-vy2); resultz2=fabs(vz1-vz2);
        resultx3=fabs(vx2-vx3); resulty3=fabs(vy2-vy3); resultz3=fabs(vz2-vz3);
    }
    
    cpt+=temps.ecart*100;

    if(vx3>=tempx1) vx3-=resultx1*temps.ecart;
    else vx3+=resultx1*temps.ecart;

    if(vy3>=tempy1) vy3-=resulty1*temps.ecart;
    else vy3+=resulty1*temps.ecart;

    if(vz3>=tempz1) vz3-=resultz1*temps.ecart;
    else vz3+=resultz1*temps.ecart;

    if(vx1>=tempx2) vx1-=resultx2*temps.ecart;
    else vx1+=resultx2*temps.ecart;

    if(vy1>=tempy2) vy1-=resulty2*temps.ecart;
    else vy1+=resulty2*temps.ecart;

    if(vz1>=tempz2) vz1-=resultz2*temps.ecart;
    else vz1+=resultz2*temps.ecart;

    if(vx2>=tempx3) vx2-=resultx3*temps.ecart;
    else vx2+=resultx3*temps.ecart;

    if(vy2>=tempy3) vy2-=resulty3*temps.ecart;
    else vy2+=resulty3*temps.ecart;

    if(vz2>=tempz3) vz2-=resultz3*temps.ecart;
    else vz2+=resultz3*temps.ecart;

    if ( cpt >= 100 )
    {
        cpt=0;
        rotation_planete=0;
        ind++;
        ind=abs(ind);
    }
}


//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------


void Progression_inv ( )
{

    if(cpt==0)
    {
        tempx1=vx1; tempy1=vy1; tempz1=vz1;
        tempx2=vx2; tempy2=vy2; tempz2=vz2;
        tempx3=vx3; tempy3=vy3; tempz3=vz3;

        resultx1=fabs(vx1-vx3); resulty1=fabs(vy1-vy3); resultz1=fabs(vz1-vz3);
        resultx2=fabs(vx3-vx2); resulty2=fabs(vy3-vy2);resultz2=fabs(vz3-vz2);
        resultx3=fabs(vx2-vx1); resulty3=fabs(vy2-vy1); resultz3=fabs(vz2-vz1);
    }

    cpt+=temps.ecart*100;

    if(vx1>=tempx3) vx1-=resultx1*temps.ecart;
    else vx1+=resultx1*temps.ecart;

    if(vy1>=tempy3) vy1-=resulty1*temps.ecart;
    else vy1+=resulty1*temps.ecart;

    if(vz1>=tempz3) vz1-=resultz1*temps.ecart;
    else vz1+=resultz1*temps.ecart;

    if(vx3>=tempx2) vx3-=resultx2*temps.ecart;
    else vx3+=resultx2*temps.ecart;

    if(vy3>=tempy2) vy3-=resulty2*temps.ecart;
    else vy3+=resulty2*temps.ecart;

    if(vz3>=tempz2) vz3-=resultz2*temps.ecart;
    else vz3+=resultz2*temps.ecart;

    if(vx2>=tempx1) vx2-=resultx3*temps.ecart;
    else vx2+=resultx3*temps.ecart;

    if(vy2>=tempy1) vy2-=resulty3*temps.ecart;
    else vy2+=resulty3*temps.ecart;

    if(vz2>=tempz1) vz2-=resultz3*temps.ecart;
    else vz2+=resultz3*temps.ecart;

    if (cpt >= 100)
    {
        cpt=0;
        rotation_planete=0;

        if(ind==0) ind=2;
        else ind--;

        ind=abs(ind);
    }
}


//------------------------------------------------------------------------------
// Joue la bande annonce à la star wars, avec une tantacule
// Retourne false si la bande annonce est finie
//------------------------------------------------------------------------------


bool bande_annonce ( )
{
    static float defil = 0.0f;            // défilement de la bande annonce
    static float angle = 0.0f;          // angle de rotation déjà effectué dans la frame précédente
    static float accel = 0.0f;          // accélération permettant de tourner dans les deux sens de façon progressive
    float val;                          // valeur permettant de gagner du temps pour le calcul de l'hypothénuse
    
    accel+=temps.ecart*50;                            // on accélère
    vitesse = 2*cos(accel*pi/180.0f);   // on modifie la vitesse
    angle += vitesse*temps.ecart*100;                   // on modifie l'angle
    
    glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    // si le défilement est terminé
	if ((defil<-1.0f) || (keys[13] == true))
	{
        // initialisation du temps de départ
        temps.base = clock ( );
        temps.tps  = clock ( );
        temps.frame_fps = 0;
        defil = 0.0f;
		playJouer = true;
		return false;
	}

    //---- BANDE ANNONCE ----//
    glColor3d ( 1, 1, 1 );
	glDisable ( GL_COLOR );
	glEnable ( GL_TEXTURE_2D );

    glBindTexture ( GL_TEXTURE_2D, texture[TEX_ANNONCE] );
    glBegin(GL_QUADS);
        glTexCoord2d(0.0f,0.0f+defil); glVertex3f(-2.0f,-2.0f,-5.0f);
        glTexCoord2d(0.0f,0.5f+defil); glVertex3f(-2.0f,0.0f,-8.0f);
        glTexCoord2d(1.0f,0.5f+defil); glVertex3f(2.0f,0.0f,-8.0f);
        glTexCoord2d(1.0f,0.0f+defil); glVertex3f(2.0f,-2.0f,-5.0f);
    glEnd();
    
    // TimeStep corrigé pour le défilement du chapitre
	if ( defil == 0 ) defil += 0.0005;
    else defil-= 0.0005*temps.ecart*100;

	
	glEnable ( GL_COLOR );
	glDisable ( GL_TEXTURE_2D );
    //-----------------------//
	
    //---- TENTACULES ----//
    // Transformations appliquées au cube
    glTranslatef ( 0.0f, 6.0f, -30.0f );      // On se recule pour voir la scène
    glRotatef ( angle + vitesse, 0, 0, 1 );   // On effectue une rotation sur l'axe z
    glColor3f ( 0.0f, 0.0f, 1.0f );           // On donne une couleur de 0 à 1 (RVB)
    glBegin(GL_QUADS);                        // On dessine notre carré centrale
        glVertex3f( -1.0f, -1.0f, 0.0f );
        glVertex3f( -1.0f,  1.0f, 0.0f );
        glVertex3f(  1.0f,  1.0f, 0.0f );
        glVertex3f(  1.0f, -1.0f, 0.0f );
    glEnd();

    // Tentacules
    Tentacule ( angle );
    glRotatef ( 90, 0, 0, 1 );   // On effectue une rotation sur l'axe z
    Tentacule ( angle );
    glRotatef ( 90, 0, 0, 1 );   // On effectue une rotation sur l'axe z
    Tentacule ( angle );
    glRotatef ( 90, 0, 0, 1 );   // On effectue une rotation sur l'axe z
    Tentacule ( angle );
    //--------------------//
	
    return true;
}


//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------


void buttons_options ( )
{
	int i;

    if (keys[VK_UP])                        // Is F1 Being Pressed?
    {
        keys[VK_UP]=FALSE;
    	if ( joueur_nivo > 0 ) joueur_nivo--;
    }

    if (keys[VK_DOWN])
    {
        keys[VK_DOWN]=FALSE;
		if ( joueur_nivo < 2 ) joueur_nivo++;
    }

	bout *bt=NULL;
    bt=(bout*)malloc(30*sizeof(boutton*));

    for(i=0;i<30;i++)
        bt[i]=(bout)malloc(1*sizeof(boutton));

    //BOUTTONS NIVEAUX

	bt[0]->x=(640)-200-(16*2);
    bt[0]->y=480/2-200;
    bt[0]->texte="Petit Joueur";
    bt[0]->taille=16;
    bt[0]->coul="yellow";
	bt[0]->coinhgx=(640)-200-(16*3);
    bt[0]->coinhgy=480/2-200-10;
    bt[0]->coinbdx=(640)-200+(16*8);
    bt[0]->coinbdy=480/2-200+20;
    
    bt[1]->x=(640)-200-(16*2);
    bt[1]->y=480/2-120;
    bt[1]->texte="Joueur Moyen";
    bt[1]->taille=16;
    bt[1]->coul="yellow";
	bt[1]->coinhgx=(640)-200-(16*3);
    bt[1]->coinhgy=480/2-120-10;
    bt[1]->coinbdx=(640)-200+(16*8);
    bt[1]->coinbdy=480/2-120+20;

    bt[2]->x=(640)-200-(16*2);
    bt[2]->y=480/2-30;
    bt[2]->texte="Joueur expert";
    bt[2]->taille=16;
    bt[2]->coul="yellow";
    bt[2]->coinhgx=(640)-200-(16*3);
    bt[2]->coinhgy=480/2-30-10;
    bt[2]->coinbdx=(640)-200+(16*8);
    bt[2]->coinbdy=480/2-30+20;

//BOUTTONS MENU

	bt[3]->x=100-(16*2);
    bt[3]->y=480/2+30;
    bt[3]->texte="MENU";
    bt[3]->taille=32;
    bt[3]->coul="blue";

    bt[4]->x=5;
    bt[4]->y=480/2+110;
    bt[4]->texte="<- ";
    bt[4]->taille=16;
    bt[4]->coul="red";

	bt[5]->x=50-(25);
    bt[5]->y=480/2+110;
    bt[5]->texte=" move planet left";
    bt[5]->taille=16;
    bt[5]->coul="green";

    bt[6]->x=5;
    bt[6]->y=480/2+140;
    bt[6]->texte="-> ";
    bt[6]->taille=16;
    bt[6]->coul="red";

	bt[7]->x=50-(25);
    bt[7]->y=480/2+140;
    bt[7]->texte=" move planet right";
    bt[7]->taille=16;
    bt[7]->coul="green";

	bt[8]->x=50-(16*3);
    bt[8]->y=480/2+170;
    bt[8]->texte="Enter ";
    bt[8]->taille=16;
    bt[8]->coul="red";

	bt[9]->x=50+(16);
    bt[9]->y=480/2+170;
    bt[9]->texte="select planet";
    bt[9]->taille=16;
    bt[9]->coul="green";

//BOUTTONS JOUER

    bt[10]->x=300-(16*2);
    bt[10]->y=480/2+30;
    bt[10]->texte="PLAY";
    bt[10]->taille=32;
    bt[10]->coul="blue";

	bt[11]->x=250-(16*2);
    bt[11]->y=480/2+110;
    bt[11]->texte="<- ->";
    bt[11]->taille=16;
    bt[11]->coul="red";

	bt[12]->x=250+16;
    bt[12]->y=480/2+110;
    bt[12]->texte=" move spaceship" ;
    bt[12]->taille=16;
    bt[12]->coul="green";

    bt[13]->x=250-(16*2);
    bt[13]->y=480/2+140;
    bt[13]->texte="Up-Down ";
    bt[13]->taille=16;
    bt[13]->coul="red";

	bt[14]->x=250+(16*3);
    bt[14]->y=480/2+140;
    bt[14]->texte=" move again";
    bt[14]->taille=16;
    bt[14]->coul="green";

	bt[15]->x=250-(16*2);
    bt[15]->y=480/2+170;
    bt[15]->texte="Space ";
    bt[15]->taille=16;
    bt[15]->coul="red";

	bt[16]->x=250+(16*2);
    bt[16]->y=480/2+170;
    bt[16]->texte="FIRE !!!";
    bt[16]->taille=16;
    bt[16]->coul="green";

//BOUTONS OPTION

    bt[17]->x=500-(16*2);
    bt[17]->y=480/2+30;
    bt[17]->texte="OPTION";
    bt[17]->taille=32;
    bt[17]->coul="blue";

	bt[18]->x=450-(16);
    bt[18]->y=480/2+110;
    bt[18]->texte="<- ->";
    bt[18]->taille=16;
    bt[18]->coul="red";

	bt[19]->x=450+(30);
    bt[19]->y=480/2+110;
    bt[19]->texte=" change texture";
    bt[19]->taille=16;
    bt[19]->coul="green";

    bt[20]->x=450-16;
    bt[20]->y=480/2+140;
    bt[20]->texte="Up - Down ";
    bt[20]->taille=16;
    bt[20]->coul="red";

	bt[21]->x=450+(16*5);
    bt[21]->y=480/2+140;
    bt[21]->texte="level ";
    bt[21]->taille=16;
    bt[21]->coul="green";

	bt[22]->x=450-(16);
    bt[22]->y=480/2+170;
    bt[22]->texte=" M ";
    bt[22]->taille=16;
    bt[22]->coul="red";

	bt[23]->x=450+(16*2);
    bt[23]->y=480/2+170;
    bt[23]->texte="music (on/off)";
    bt[23]->taille=16;
    bt[23]->coul="green";
    
    // le fond noir ( moitié basse de l'écran), puis coin haut droit
    glColor3f ( 0.0f, 0.0f, 0.0f );
    glBegin ( GL_QUADS );
        glVertex2d(     0, HEIGHT/2 );
        glVertex2d( WIDTH, HEIGHT/2 );
        glVertex2d( WIDTH, HEIGHT );
        glVertex2d(     0, HEIGHT );
    glEnd();
    glBegin ( GL_QUADS );
        glVertex2d( WIDTH/2,        0 );
        glVertex2d(   WIDTH,        0 );
        glVertex2d(   WIDTH, HEIGHT/2 );
        glVertex2d( WIDTH/2, HEIGHT/2 );
    glEnd();

	for(i=0;i<24;i++)
        glPrint ( bt[i]->x*WIDTH/640, bt[i]->y*HEIGHT/480, bt[i]->coul, bt[i]->taille, bt[i]->texte );

    glColor3d ( 1, 1, 1 );

    glDisable ( GL_TEXTURE_2D );
    glEnable ( GL_COLOR );

     // LA BORDURE pour les niveaux
    glLineWidth(2);
    glColor3f ( 0.0f, 1.0f, 1.0f );
    glBegin(GL_LINE_LOOP);
        glVertex2d(bt[joueur_nivo]->coinhgx*WIDTH/640,bt[joueur_nivo]->coinhgy*HEIGHT/480);
        glVertex2d(bt[joueur_nivo]->coinhgx*WIDTH/640,bt[joueur_nivo]->coinbdy*HEIGHT/480);
        glVertex2d(bt[joueur_nivo]->coinbdx*WIDTH/640,bt[joueur_nivo]->coinbdy*HEIGHT/480);
        glVertex2d(bt[joueur_nivo]->coinbdx*WIDTH/640,bt[joueur_nivo]->coinhgy*HEIGHT/480);
    glEnd();
    
    //tous les cadres
    // LA BORDURE
    glLineWidth(10);
    glColor3f ( 0.9f, 0.2f, 0.3f );
    glBegin(GL_LINE_LOOP);
        glVertex2d(     0,      0);
        glVertex2d(     0, HEIGHT);
        glVertex2d( WIDTH, HEIGHT);
        glVertex2d( WIDTH,      0);
    glEnd();

    // LA BORDURE
    glLineWidth(5);
    glColor3f ( 0.9f, 0.2f, 0.3f );
    glBegin(GL_LINES);
        glVertex2d( 0, HEIGHT/2);
        glVertex2d( WIDTH,HEIGHT/2);
    glEnd();

    // LA BORDURE
    glLineWidth(5);
    glColor3f ( 0.9f, 0.2f, 0.3f );
    glBegin(GL_LINES);
        glVertex2d( WIDTH/2, HEIGHT/2);
        glVertex2d( WIDTH/2, 0);
    glEnd();

    // LA BORDURE
    glLineWidth(3);
    glColor3f ( 0.9f, 0.2f, 0.3f );
    glBegin(GL_LINES);
        //glVertex2d(     0, HEIGHT/2);
        //glVertex2d(     0, HEIGHT);
        glVertex2d( WIDTH/3,HEIGHT);
        glVertex2d( WIDTH/3,HEIGHT/2);
    glEnd();

    // LA BORDURE
    glLineWidth(3);
    glColor3f ( 0.9f, 0.2f, 0.3f );
    glBegin(GL_LINES);
        //glVertex2d(WIDTH/3,HEIGHT/2);
        //glVertex2d(WIDTH/3, HEIGHT);
        glVertex2d((WIDTH/3)*2, HEIGHT/2);
        glVertex2d((WIDTH/3)*2,HEIGHT);
    glEnd();
    glLineWidth(1);

    free ( bt );
}


bool options()
{
    int i;

    glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    playMenu=false;

    Passage3DTo2D ( );

    buttons_options();

    Passage2DTo3D ( );

    glEnable ( GL_TEXTURE_2D );

    AfficheVaisseau_options ( numero );

    if ((playOptions==true)&&(menuEntrer==true))
    {
        playMenu=true;
        menuEntrer=false;
        return false;
    }

    return true;
}



//------------------------------------------------------------------------------
// La partie est lancée
// numero : texture du vaisseau
//------------------------------------------------------------------------------


bool jouer ( int numero )
{
    int i;
    int tmp;

    glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    if ( nivo.id_enn < nivo.nb_ennemis )
    {
        if ( nivo.enn[nivo.id_enn].tps < (double)(temps.tps - temps.base) / CLOCKS_PER_SEC )
        {
            nivo.enn[nb_enn].mesh.posx = nivo.enn[nb_enn].posx;
            nivo.enn[nb_enn].mesh.posy = nivo.enn[nb_enn].posy;
            nivo.enn[nb_enn].mesh.posz = nivo.enn[nb_enn].posz;
            nivo.enn[nb_enn].affich = true;
            nivo.enn[nb_enn].explode = false;
            nb_enn++;
            nivo.id_enn++;
        }
    }

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clear The Screen And The Depth Buffer

    Passage3DTo2D ( );
    AfficheBackground ( TEX_NIV, (double)(temps.tps - temps.base) / CLOCKS_PER_SEC / (2 * nivo.longueur) );

    Passage2DTo3D ( );

    // on parcours tous les ennemis à l'écran
    for ( i=nb_enn-1 ; i >= 0 ; i-- )
    {
//-------------- NEW NEW 2003 03 06 -------------------------------//
        if ((keys['V']) || (keys['v'])) { nivo.enn[i].explode = true; nivo.enn[i].affich = false; }
        // est-il en bon état ?
        if ( nivo.enn[i].affich == true ) AfficheEnnemi ( nivo.enn[i].mesh );
        // ou est-il en train d'exploser ?
        if ( nivo.enn[i].explode == true )
        {
            AfficheExplosion ( i );
            AfficheFlare ( nivo.enn[i].mesh.posx, nivo.enn[i].mesh.posy, nivo.enn[i].mesh.posz );
        }
        // on le déplace et on vérifie s'il est encore affiché
        tmp = EnnemiMove ( &nivo.enn[i].mesh );
        // s'il n'est plus affichable, il n'est plus affiché
        if ( tmp == 1 ) { nivo.enn[i].affich = false; }
        // est-il en train de percuter notre vaisseau ?
        if ( nivo.enn[i].affich == true ) EnnemiCollision ( &vaisseau, &nivo.enn[i].mesh );
//-------------- NEW NEW 2003 03 06 -------------------------------//
    }
    
    // on refait le tri dans les ennemis encore affichés
    // fonction de buggage
/*
    i = nb_enn - 1;
    while ( i >= 0 )
    {
        if (( nivo.enn[i].affich == false ) && ( nivo.enn[i].explode == false ))
        {
            if ( i != nb_enn - 1 ) ReinitialiserMesh ( &nivo.enn[i].mesh, &nivo.enn[nb_enn-1].mesh );
            nb_enn--;
        }
        i--;
    }
*/
    AfficheVaisseau (numero);
    if ( joueur_nivo < 2 ) AfficheCrosshair ( );
    if ( joueur_nivo < 1 ) AfficheTarget ( );
    AfficheEtoiles ( );

    Passage3DTo2D ( );
    
    AfficheJauge ( vaisseau.vie );

    // Affichage du radar
    if ( joueur_nivo < 2 ) AffichageRadar ( );

    // Affichage d'un cadre pour le temps et le nombre de frags
    glColor3d ( 1, 1, 1 );
    glBegin ( GL_QUADS );
        glVertex3f ( WIDTH-191, HEIGHT-9, 0 );
        glVertex3f ( WIDTH-191, HEIGHT-81, 0 );
        glVertex3f ( WIDTH-9,   HEIGHT-81, 0 );
        glVertex3f ( WIDTH-9,   HEIGHT-9, 0 );
    glEnd ( );
    glColor3f ( 0.2f, 0.3f, 0.2f);
    glBegin ( GL_QUADS );
        glVertex3f ( WIDTH-190, HEIGHT-10, 0 );
        glVertex3f ( WIDTH-190, HEIGHT-80, 0 );
        glVertex3f ( WIDTH-10,  HEIGHT-80, 0 );
        glVertex3f ( WIDTH-10,  HEIGHT-10, 0 );
    glEnd ( );
    
    // Affiche les FPS
    glPrint ( WIDTH-180, HEIGHT-70, "blue",   16, "FPS    : %2.2f", temps.fps);
    // Affichage du nombre de frags
    glPrint ( WIDTH-180, HEIGHT-50, "red",    16, "Point%c : %d", (vaisseau.frags > 1 ) ?('s'):(' '), vaisseau.frags );
    // Affichage du temps
    glPrint ( WIDTH-180, HEIGHT-30, "yellow", 16, "Temps  : %2.2f s", (float)(temps.tps - temps.base) / CLOCKS_PER_SEC  - temps.non_ecoule);
    
    Passage2DTo3D ( );

    glDisable ( GL_TEXTURE_2D ) ;
    glEnable ( GL_COLOR );

    // si le niveau arrive à son terme, on charge le suivant
    if ( ((float)(temps.tps - temps.base) / CLOCKS_PER_SEC) > nivo.longueur )
    {
        // initialisation du temps de départ
        temps.base = clock ( );
        // initialisation du temps de départ
        temps.tps = clock ( );
        // niveau suivant
        num_nivo++;
        char niv[255];
        sprintf ( niv, "chapitres/chapitre%02d.bmp", num_nivo );
        LoadBMP ( niv, TEX_ANNONCE );
        sprintf ( niv, "chapitres/bg%02d.bmp", num_nivo );
        LoadBMP ( niv, TEX_NIV );
        sprintf ( niv, "niveaux/nivo%02d.txt", num_nivo );
        LoadNIV ( niv, &nivo );
        BuildFont ( );
        playBandeAnnonce = true;
        return false;
    }
    else return true;
}


//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------


bool quitter( )
{
    int i;
    bool  mv_quit = false;
    bool  mv_quit1 = false;
    bool  mv_quit2 = false;

    glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    playMenu=false;
    playJouer=false;
    playOptions=false;

    glEnable ( GL_TEXTURE_2D );
    glColor3f(1.0f,1.0f,1.0f);

    mv_quit  = AfficheVaisseau_quitter ( 0, TEX_VAISSEAU_1 );
    mv_quit1 = AfficheVaisseau_quitter ( 1, TEX_VAISSEAU_2 );
    mv_quit2 = AfficheVaisseau_quitter ( 2, TEX_VAISSEAU_3 );

    Passage3DTo2D ( );

    bout *bt=NULL;
    bt=(bout*)malloc(NB_BOUTTON*sizeof(boutton*));

    for(i=0;i<NB_BOUTTON;i++)
        bt[i]=(bout)malloc(1*sizeof(boutton));

    bt[0]->x=(WIDTH/2)-90-(32*2);
    bt[0]->y=HEIGHT/2-140;
    bt[0]->texte="Remi Duhautoy";
    bt[0]->taille=32;
    bt[0]->coul="arc";


    bt[1]->x=(WIDTH/2)-100-(32*2);
    bt[1]->y=HEIGHT/2-60;
    bt[1]->texte="Julien Durieux";
    bt[1]->taille=32;
    bt[1]->coul="arc";


    bt[2]->x=(WIDTH/2)-110-(32*2);
    bt[2]->y=HEIGHT/2+20;
    bt[2]->texte="Samuel Monteiro";
    bt[2]->taille=32;
    bt[2]->coul="arc";

    if ( mv_quit == true )
    glPrint ( bt[0]->x, bt[0]->y, bt[0]->coul, bt[0]->taille, bt[0]->texte );
    if ( mv_quit1 == true )
    glPrint ( bt[1]->x, bt[1]->y, bt[1]->coul, bt[1]->taille, bt[1]->texte );
    if ( mv_quit2 == true )
    glPrint ( bt[2]->x, bt[2]->y, bt[2]->coul, bt[2]->taille, bt[2]->texte );

    Passage2DTo3D ( );

    arc_en_ciel+=temps.ecart*100;
    glColor3d ( 1, 1, 1 );
    
    free ( bt );

    return (1 - attenteFade ( 6 ));
}


//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------

  
void Init_button ( )
{
    int i;

    bout *bt=NULL;
    bt=(bout*)malloc(NB_BOUTTON*sizeof(boutton*));

    for(i=0;i<NB_BOUTTON;i++)
        bt[i]=(bout)malloc(1*sizeof(boutton));
 
    POINT mouse;
    GetCursorPos(&mouse);

    if ( Pause == false )
    {
        bt[0]->x=(WIDTH/2)+10-(32*2);
        bt[0]->y=3*HEIGHT/4;
        bt[0]->texte="Jouer";
        bt[0]->taille=32;
        bt[0]->coul="red";
    }
    else
    {
        bt[0]->x=(WIDTH/2)-10-(32*2);
        bt[0]->y=3*HEIGHT/4;
        bt[0]->texte="Continuer";
        bt[0]->taille=24;
        bt[0]->coul="red";
    }


    bt[1]->x=(WIDTH/2)-10-(32*2);
    bt[1]->y=3*HEIGHT/4;
    bt[1]->texte="Options";
    bt[1]->taille=32;
    bt[1]->coul="cyan";


    bt[2]->x=(WIDTH/2)-10-(32*2);
    bt[2]->y=3*HEIGHT/4;
    bt[2]->texte="Quitter";
    bt[2]->taille=32;
    bt[2]->coul="yellow";

    ind=ind%3;

//    if(menuEntrer==false)
        glPrint ( bt[ind]->x, bt[ind]->y, bt[ind]->coul, bt[ind]->taille, bt[ind]->texte );

    glColor3d ( 1, 1, 1 );

}


//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------


void enter ( )
{
    disty=fabs(avancey-HEIGHT/(float)140);
    avancey+=disty*temps.ecart;
    avancez+=0.1f*temps.ecart*100;
}


//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------


bool menu ( )
{
    int num_planete;
    static float theta=0.0f;
    static int angle = 0;

    glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Reset of Buffers

        Passage3DTo2D ( );
        AfficheBackground ( TEX_BG, 0 );
        glPushMatrix ();

        glColor3d(1,1,1);
        glEnable(GL_BLEND);
        glBlendFunc(GL_ONE,GL_ONE);
        glDisable(GL_DEPTH_TEST);

        Passage2DTo3D ( );

    glPushMatrix ();


    glTranslatef ( 0, 5, -20 );
    glEnable ( GL_BLEND );          // activation du blending
    glDisable ( GL_DEPTH_TEST );    // donc on retire le test de la distance

    glDisable ( GL_COLOR );
    glEnable ( GL_TEXTURE_2D );
    glBindTexture ( GL_TEXTURE_2D, texture[TEX_ESTRELLA] );

    glBegin (GL_QUADS);
        glTexCoord2d ( 0, 0.33f ); glVertex3f ( -3.0f, -1.0f, 0 );
        glTexCoord2d ( 0, 0.66f ); glVertex3f ( -3.0f,  1.0f, 0 );
        glTexCoord2d ( 1, 0.66f ); glVertex3f (  3.0f,  1.0f, 0 );
        glTexCoord2d ( 1, 0.33f ); glVertex3f (  3.0f, -1.0f, 0 );
    glEnd ();

    glDisable ( GL_TEXTURE_2D );
    glEnable ( GL_COLOR );

    glTranslated ( 3, 1, 0 );

    glRotatef ( theta , 1.0f, 1.0f, 0.0f);
    glColor3f ( 0.93f, 0.92f, 0.15f );
    DrawEtoile ( 0, 0, 0, 0.2, 0.6 );
    theta += temps.ecart*100;

    glPopMatrix ();

        Passage3DTo2D ( );

        glDisable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);

        glDisable(GL_BLEND);

        //AFFICHAGES 2D
        glDisable ( GL_TEXTURE_2D );
        glEnable ( GL_COLOR );

        // LA BORDURE
        glLineWidth(10);
        glColor3f ( 0.9f, 0.2f, 0.3f );
        glBegin(GL_LINE_LOOP);
            glVertex2d(     0,      0);
            glVertex2d(     0, HEIGHT);
            glVertex2d( WIDTH, HEIGHT);
            glVertex2d( WIDTH,      0);
        glEnd();
        glLineWidth(1);

        glEnable ( GL_TEXTURE_2D );

        Init_button ( );

        Passage2DTo3D ( );

        glColor3f(1.0f,1.0f,1.0f);

        glPushMatrix();

        for (num_planete=0;num_planete<3;num_planete++)
        {
            glPushMatrix();
            glTranslatef(0,-1,0);
            if(menuEntrer==false)
            {
                switch (num_planete) {
                    case 0 :glTranslated(vx1,vy1,vz1);break;
                    case 1 :glTranslated(vx2,vy2,vz2);break;
                    case 2 :glTranslated(vx3,vy3,vz3);break;
                }
            }

            if(rotation_planete==1) Progression();
            if(rotation_planete==2) Progression_inv();
        
            if(menuEntrer==true)
            {
                if(ind%3==0)
                {
                    switch (num_planete) {
                        case 0 :glTranslated(avancex,avancey,avancez);break;
                        case 1 :glTranslated(vx2,vy2,vz2);break;
                        case 2 :glTranslated(vx3,vy3,vz3);break;
                    }
                }

                if(ind%3==1)
                {
                    switch (num_planete) {
                        case 0 :glTranslated(vx1,vy1,vz1);break;
                        case 1 :glTranslated(vx2,vy2,vz2);break;
                        case 2 :glTranslated(avancex,avancey,avancez);break;
                    }
                }

                if(ind%3==2)
                {
                    switch (num_planete) {
                        case 0 :glTranslated(vx1,vy1,vz1);break;
                        case 1 :glTranslated(avancex,avancey,avancez);break;
                        case 2 :glTranslated(vx3,vy3,vz3);break;
                    }
                }
                enter();
            }

            glRotatef(-angle_planete,0.0f,1.0f,0.0f);
            glRotatef(-90,1.0f,0.0f,0.0f);

            angle_planete+=temps.ecart*100;

            AffichageASE ( sphere , num_planete+TEX_TERRE, TEX_ENV );

            glPopMatrix();
        }

        glPopMatrix();

    // Rejouer
    if ((ind==0)&&(avancez>1.0f)&&(menuEntrer==true)&&(Pause==true))
    {
        playJouer = true;
        menuEntrer=false;
        Pause = false;
        return false;
    }
    // Jouer
    if ((ind==0)&&(avancez>1.0f)&&(menuEntrer==true)&&(Pause==false))
    {
        char niv[255];
        sprintf ( niv, "chapitres/chapitre%02d.bmp", num_nivo );
        LoadBMP ( niv, TEX_ANNONCE );
        sprintf ( niv, "chapitres/bg%02d.bmp", num_nivo );
        LoadBMP ( niv, TEX_NIV );
        sprintf ( niv, "niveaux/nivo%02d.txt", num_nivo );
        LoadNIV ( niv, &nivo );
        BuildFont ( );
        free ( nivo.enn );
        LoadNIV ( niv, &nivo );
        menuEntrer=false;
        playBandeAnnonce=true;
        FSOUND_StopSound( FSOUND_ALL );
        FSOUND_PlaySoundEx(FSOUND_FREE, snd_niv, NULL, FALSE);
        return false;
    }
    // Options
    if ((ind==1)&&(avancez>1.0f)&&(menuEntrer==true))
    {
        menuEntrer=false;
        playOptions=true;
        return false;
    }
    // Quitter
    if ((ind==2)&&(avancez>1.0f)&&(menuEntrer==true))
    {
        FSOUND_StopSound( FSOUND_ALL );
        FSOUND_PlaySoundEx ( FSOUND_FREE, snd_byebye, NULL, FALSE );
        menuEntrer=false;
        playQuitter=true;
        return false;
    }
    

    return true;
}


//------------------------------------------------------------------------------
// Fin Du Fichier
//------------------------------------------------------------------------------