#include "allegro.h"
#include "menu.h"
#include "stdio.h"

BITMAP* load_background_bmp(char chemin_background[])
{
	BITMAP* Background;

	Background=load_bitmap(chemin_background, NULL);
		if(Background == NULL){
			set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);



			allegro_message("Unable to load image !\n%s\n", allegro_error);
			return (NULL);
		}
return (Background);

}


int bounding_box_collision(int sprite1_x, int sprite1_y, int sprite1_w,int sprite1_h,
                           int sprite2_x, int sprite2_y, int sprite2_w,int sprite2_h)
{
    if ((sprite1_x > sprite2_x + sprite2_w - 1) || 
            (sprite1_y > sprite2_y + sprite2_h - 1) ||
            (sprite2_x > sprite1_x + sprite1_w - 1) || 
            (sprite2_y > sprite1_y + sprite1_h - 1)) 
    {
        // no collision
        return 0;
    }

    // collision
    return 1;
}

void menue (BITMAP *Buffer,BITMAP *Background,dog D)
{
BITMAP *menu2;
BITMAP *souris;
BITMAP *Images;
BITMAP *instructions;
menu A;
A.w=120; 
A.h=20;
A.b=94;
A.f=66;
A.m=34;
extern volatile int mouse_x;
extern volatile int mouse_y;
extern volatile int mouse_z;
extern volatile int mouse_b;
int mouse_w =45;
int mouse_h =55;

if(install_mouse() == -1) {
allegro_message("Erreur ! %s", allegro_error) ;
return-1 ;
}

A.Background2 = load_bitmap("./Images/menu.bmp", NULL);
A.x=100;
A.y=144;
A.a=193;
A.e=241;
A.l=283;
souris = load_bitmap("./Images/souris.bmp", NULL);
menu2 = load_bitmap("./Images/menu2.bmp", NULL);
instructions = load_bitmap("./Images/instructions.bmp", NULL);
blit(A.Background2, Buffer, 0, 0, 0, 0, A.Background2->w, A.Background2->h);
Images = souris;
draw_sprite(Buffer,Images, mouse_x, mouse_y);

while (!key[KEY_ESC]) { 

clear_bitmap(Buffer) ;
blit(A.Background2, Buffer, 0, 0, 0, 0, A.Background2->w, A.Background2->h);
blit(Buffer, screen, 0, 0, 0, 0, mouse_x, mouse_y);

draw_sprite(Buffer, Images, mouse_x, mouse_y);
blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H) ;

 if((mouse_b & 1) && (bounding_box_collision(mouse_x,mouse_y,mouse_w,
                      mouse_h,A.x,A.y,A.w,A.h)==1)) 
{ 
aller (D,Buffer,Background);
}

if((mouse_b & 1) && (bounding_box_collision(mouse_x,mouse_y,mouse_w,
                      mouse_h,A.x,A.a,A.b,A.h)==1)) 
{ while (!key[KEY_ESC])
   {
clear_bitmap(Buffer);
draw_sprite(Buffer,instructions, 0,0);
blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
} }

if((mouse_b & 1) && (bounding_box_collision(mouse_x,mouse_y,mouse_w,
                      mouse_h,A.x,A.e,A.f,A.h)==1)) 
{ while (!key[KEY_ESC])
   {
clear_bitmap(Buffer);
draw_sprite(Buffer,menu2, 0,0);
blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
} }

 if((mouse_b & 1) && (bounding_box_collision(mouse_x,mouse_y,mouse_w,
                      mouse_h,A.x,A.l,A.m,A.h)==1)) 
{ 
allegro_exit();
}

}
destroy_bitmap(Images);
destroy_bitmap(Buffer);
destroy_bitmap(menu2);
}

