#include "stdio.h"
#include "stdlib.h"
#include "souris.h"


int main ( int argc, char** argv )
{
    coordonnees souris;
    long done = 0;


    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )                    // initialize SDL video
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }


    atexit(SDL_Quit);                          // make sure SDL cleans up before exit


    SDL_Surface* screen = SDL_SetVideoMode(1300, 600, 16,SDL_HWSURFACE|SDL_DOUBLEBUF);                  // create a new window
    if ( !screen )
    {
        printf("Unable to set 640x480 video: %s\n", SDL_GetError());
        return 1;
    }

                                                                // load an image
    SDL_Surface* bmp = SDL_LoadBMP("menu.bmp");
    if (!bmp)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }

                                                         // centre the bitmap on screen
    SDL_Rect dstrect;
    dstrect.x = (screen->w - bmp->w) / 2;
    dstrect.y = (screen->h - bmp->h) / 2;

                                                                     // program main loop

    while (!done)
    {
                                                                  // message processing loop
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            // check for messages
            switch (event.type)
            {
                                                       // exit if the window is closed
            case SDL_QUIT:
                done = 1;
                break;

                                                          // check for keypresses
            case SDL_KEYDOWN:
                {
                                                         // exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = 1;
                    break;
                }
            case SDL_MOUSEBUTTONDOWN:                            /* Clic de la souris */
                {

                    souris.x = event.button.x;
                    souris.y = event.button.y;
                    if( souris.x > 582 && souris.x < 724 && souris.y > 196 && souris.y < 267)//bouton jouer
                    {
                        game(screen);
                    }
                    else if( souris.x > 585 && souris.x < 727 && souris.y > 383 && souris.y < 446)//bouton quitter
                    {
                        done = 1;
                    }

                }

                    break;

            } // end switch
        } // end of message processing

                                                                   // DRAWING STARTS HERE

                                                                 // clear screen
        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));

                                                                       // draw bitmap
        SDL_BlitSurface(bmp, 0, screen, &dstrect);

                                                                     // DRAWING ENDS HERE

                                                                  // finally, update the screen :)
        SDL_Flip(screen);
    }                                                        // end main loop

                                                                  // free loaded bitmap
    SDL_FreeSurface(bmp);

                                                              // all is well ;)
    printf("Exited cleanly\n");
    return 0;
}


