// effacement du vaisseau quand on est au milieu
// pause lors du jeu, ou q pour recommencer la partie

#ifndef MAIN_H
#define MAIN_H


//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------


    #include <windows.h>        // Header File For Windows
    #include <gl/gl.h>            // Header File For The OpenGL32 Library
    #include <gl/glu.h>            // Header File For The GLu32 Library
    #include <gl/glext.h>        // Header File For The Glaux Library
    #include <gl/glaux.h>        // Header File For The Glaux Library
    #include <stdio.h>            // Header pour charger une image
    #include <math.h>
    #include <stdlib.h>                             // Header pour le random
    #include <time.h>
    #include <mmsystem.h>                           // Header pour le son wav

    #include <fmod\fmod.h>
    #include <fmod\fmod_errors.h>    // optionnel


//------------------------------------------------------------------------------
// Macros
//------------------------------------------------------------------------------


    #define BLEND_ACTIVE                    \
    {                                       \
        glEnable ( GL_BLEND );              \
        glBlendFunc ( GL_ONE, GL_ONE );     \
        glDisable ( GL_DEPTH_TEST );        \
    }                                       \
    
    #define BLEND_DESACTIVE                 \
    {                                       \
        glDisable ( GL_BLEND );             \
        glEnable ( GL_DEPTH_TEST );         \
    }                                       \

    #define ERREUR(mess)                    \
    {                                       \
        KillGLWindow ( );                   \
        MessageBox(NULL, mess, "Erreur", MB_OK | MB_ICONEXCLAMATION);\
        return false;                       \
    }                                       \
    
    #define EXIT                            \
    {                                       \
        fclose(fichier);                    \
        return -1;                          \
    }                                       \
    
    
//------------------------------------------------------------------------------
// Constantes
//------------------------------------------------------------------------------


    #define CTOI(C)     (*(int*)&C)         // Conversion d'un char en entier
    #define pi          3.1415926535897932384626433832795f // PI pour les angles
    #define maxp        500                  // nombre de points (étoiles)
    #define COLOR_ARC_EN_CIEL   glColor3f(1.0f*float(cos(arc_en_ciel/20.0f)),1.0f*float(sin(arc_en_ciel/25.0f)),1.0f-0.5f*float(cos(arc_en_ciel/17.0f)));
    #define NB_BOUTTON  3
    #define WIDTH       800
    #define HEIGHT      600
    #define BPP         32

    //---  TEXTURES  ---//
    #define TEX_ESTRELLA    0
    #define TEX_TERRE       1
    #define TEX_MARS        2
    #define TEX_JUPITER     3
    #define TEX_BG          4
    #define TEX_360         5
    
    #define TEX_TARGET      6
    #define TEX_FONT        7
    #define TEX_EXPLOSION   8
    #define TEX_RADAR       9
    
    #define TEX_FIRE        10
    #define TEX_SHINE       11
    #define TEX_VAISSEAU_1  12
    #define TEX_VAISSEAU_2  13
    #define TEX_VAISSEAU_3  14
    #define TEX_VAISSEAU_4  15
    #define TEX_VAISSEAU_5  16
    #define TEX_ENV         17

    #define TEX_FLARE_01    18
    #define TEX_FLARE_02    19
    #define TEX_FLARE_03    20
    #define TEX_FLARE_04    21
    #define TEX_FLARE_05    22
    #define TEX_FLARE_06    23
    
    #define TEX_OPENGL      24
    #define TEX_DEVCPP      25
    #define TEX_FMOD        26

    #define TEX_ANNONCE     27
    #define TEX_NIV         28
    
    #ifndef __cplusplus
        typedef int bool;
        #define false (1==2)
        #define true (1==1)
    #endif

//------------------------------------------------------------------------------
// Structures
//------------------------------------------------------------------------------


    struct s_laser
     {
        float taille;
        float vitesse;
        float x, y;
        float debz, finz;
        bool  affich;
     } laser[10];
    int nb_laser = 0;

    struct points
     {
        float StartX;
        float StartY;
        float StartZ;
        float InitXVel;
        float InitYVel;
        float InitZVel;
        float wind;
        float color[3]; // Les 3 couleurs RVB
        float intensity;
        float t;
     } etoile[maxp];
     
    struct point {
        float x, y, z;
    };
    
    struct mesh_struct {
        float posx, posy, posz;
        float anglex, angley;
        float rotz;                  // tonneau
        int frags;
        int vie;
        int nb_points;
        int nb_faces;
        int nb_uv;
        int nb_uvfaces;
        struct point * liste_de_points;
        struct point ** liste_de_faces;
        struct point * liste_uv;
        struct point ** liste_uvfaces;
        struct point * liste_points_normales;
        struct point * liste_faces_normales;
    };

    struct ennemi_struct {
        int id;
        float tps;
        char nom[255];
        float posx, posy, posz;
        bool affich;
        bool explode;
        struct mesh_struct mesh;
    };

    struct nivo_struct {
        char nom[255];
        int longueur;
        int nb_ennemis;
        int id_enn;
        struct ennemi_struct * enn;
    };

    typedef struct button{
        int x,y;
        int coinhgx;
        int coinhgy;
        int coinbdx;
       int coinbdy;
        int taille;
       char *texte;
        char *coul;
       char *coul2;
    } boutton, *bout;
    
    // Gestion du temps
    struct TEMPS
    {
        int tps;                // temps depuis le début
        float non_ecoule;       // temps non ecoulé pendant la pause
        float ecart;            // ecart de temps entre deux frames
        long int frame;         // nombre de frames depuis le début
        int frame_fps;          // nombre réinitialisé pour les FPS
        int base;               // temps réinitialisé pour les FPS
        int pause;              // pause du temps
        float fps;              // nombre de FPS
    };
    struct TEMPS temps;

//------------------------------------------------------------------------------
// Variables
//------------------------------------------------------------------------------


    // Pour notre fenêtre
    HDC     hDC=NULL;               // Device Context
    HGLRC   hRC=NULL;               // Rendering Context
    HWND    hWnd=NULL;              // Handle de notre fenêtre
    HINSTANCE   hInstance;          // Instance de notre application

    // Pour la gestion de notre programme
    bool    keys[256];              // Tableau stockant les touches utilisées
    bool    active=TRUE;            // Flag indiquant si la fenêtre est active (défaut : TRUE)
    bool    fullscreen=TRUE;        // Flag indiquant si la fenêtre est en plein écran (défaut : TRUE)
    
    // Les différentes étapes de notre programme
    bool playLoad=true;
    bool playIntro=false;
    bool playMenu=false;
    bool playJouer=false;
    bool playOptions=false;
    bool playQuitter=false;
    bool playBandeAnnonce=false;
    bool Pause=false;
    
    // Les modèles
    struct mesh_struct vaisseau;           // Vaisseau
    struct mesh_struct sphere;             // Planete
    struct mesh_struct ennemi[20];         // Ennemis
    bool  tonneau = false;          // Tonneau effectué par le vaisseau (touche entrée durant le jeu)
    
    // Les textures
    GLuint texture[50];             // Les textures utilisées dans le programme (50)
    int   base;                     // Liste pour afficher un caractère
    bool multitexturing = true;     // Activation du multitexturing
    PFNGLACTIVETEXTUREARBPROC       glActiveTextureARB = 0;
    PFNGLMULTITEXCOORD2FARBPROC     glMultiTexCoord2fARB = 0;
    PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB = 0;
    int     numero=TEX_VAISSEAU_1;  // Première texture du vaisseau
    float   matFlare[16];           // Lens Flares (16)
    int     vaisseauTransparence=0; // 0 : pas de blend / 1 : blend activé / 2 : blend activé sur vaisseau
    
    // Les niveaux
    struct nivo_struct nivo;               // Les différents niveaux
    int num_nivo = 1;               // Le premier niveau initialisé
    int joueur_nivo=0;              // Niveau de difficulté choisi par le joueur

    // Les sons
    FSOUND_SAMPLE   *snd_niv=NULL, *snd_flip=NULL, *snd_explode=NULL,
                    *snd_intro=NULL, *snd_byebye=NULL, *snd_fire=NULL;

    // Options du programme
    bool aff_wireframe = false;     // touche F2
    bool menuEntrer=false;
    bool menuOption=false;
    bool menuQuit=false;
    bool menuJouer=false;
    
    int nb_enn=0;                   // Nombre d'ennemis affichés à l'écran

    float avancex=0.0f, avancey=-1.0f, avancez=-10.0f;

    double vx1=0.0f, vy1=-1.0f, vz1=-10.0f;
    double vx2=-8.0f, vy2=1.0f, vz2=-25.0f;
    double vx3=8.0f, vy3=2.5f, vz3=-40.0f;

    double tempx1=0.0f, tempy1=0.0f, tempz1=0.0f;
    double tempx2=0.0f, tempy2=0.0f, tempz2=0.0f;
    double tempx3=0.0f, tempy3=0.0f, tempz3=0.0f;

    double resultx1=0.0f, resulty1=0.0f, resultz1=0.0f;
    double resultx2=0.0f, resulty2=0.0f, resultz2=0.0f;
    double resultx3=0.0f, resulty3=0.0f, resultz3=0.0f;

    double disty=0.0f;

    float   angle_planete=0.0f;
    int     rotation_planete=0;
    float   cpt=0;
    float   cpt2=0;
    int     ind=0;
    float   arc_en_ciel = 0.0f;
    float   vitesse=0.0f;           // Vitesse de rotation de la tentacule ( bande annonce )
    
    int     debug;


//------------------------------------------------------------------------------
// Fonctions
//------------------------------------------------------------------------------


    // main.cpp
    // Affichage de la fenêtre
    bool DrawGLScene ( void );
    // affiche.h
    void AffichageRadar ( );
    void AffichageASE ( struct mesh_struct mesh, int tex, int tex_env );
    void AfficheVaisseau (int numero );
    void AfficheVaisseau_options ( int numero );
    bool AfficheVaisseau_quitter (int quit_vaisseau, int tex);
    void AfficheReactors ( );
    bool AfficheLaser ( int num );
    void AfficheEnnemi ( struct mesh_struct mesh );
    void AfficheCrosshair ( );
    void AfficheBackground ( int tex, float zoom );
    void AfficheTarget ( );
    void AfficheJauge ( int vie );
    void AfficheEtoiles ( );
    void Passage3DTo2D ( );
    void Passage2DTo3D ( );
    void glPrint(int x, int y, char *color, int size, const char *string, ...);
    void AfficheExplosion ( int num );
    void CalculFlare ( float posx, float coeff, float posz, float x[3], float y[3], float size, int tex );
    void AfficheFlare ( float posx, float posy, float posz );
    // charge.h
    bool chargement ( );
    void BuildFont( );
    int  LoadASE ( char nomFic[255], struct mesh_struct * mesh );
    void InitEtoile( struct points *ipoint);
    int  LoadBMP(char *File, int nb);
    int  LoadTGA(char *filename, int nb);
    int  LoadNIV ( char *File, struct nivo_struct * nivo );
    int  LoadRAW ( char nomFic[255], int nb );
    int  FreeASE ( struct mesh_struct mesh );
    // menu.h
    void Progression ( );
    void Progression_inv ( );
    bool bande_annonce ( );
    bool jouer( int );
    bool quitter ( );
    void Init_button ( );
    bool options ( );
    void buttons_options ( );
    void enter ( );
    bool menu ( );
    // intro.h
    float CalculAngle ( float vitesse, float max, float angle_old );
    void Tentacule ( float angle );
    void DrawEtoile ( float , float , float , float , float  );
    bool debFade ( float secondes, bool ouverture );
    bool attenteFade ( float secondes );
    void finFade ( );
    bool intro ( );
    // move.h
    void ReinitialiserMesh ( struct mesh_struct * mesh, struct mesh_struct * mesh_old );
    int  EnnemiInit ( struct mesh_struct * mesh );
    int  EnnemiMove ( struct mesh_struct * mesh );
    bool EnnemiCollision ( struct mesh_struct * mesh1, struct mesh_struct * mesh2 );
    int  Tonneau ( struct mesh_struct * mesh );
    // GLFunc.h
    // Création de la fenêtre
    bool CreateGLWindow ( char* title, int width, int height, int bits, bool fullscreenflag );
    // Destruction de la fenêtre
    void KillGLWindow ( void );
    // Redimensionnement de la fenêtre
    void ReSizeGLScene ( int width, int height );
    // Initialisation d'OpenGL
    bool InitGL ( void );
    // Réception des messages de notre fenêtre
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    // Fonction principale
    int  WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow );

#endif


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