Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Includes.h"
- #define screenHeight 640
- #define screenWidth 480
- int main()
- {
- //If Allegro 5 fails to initialize, exit.
- if(!al_init())
- return -1;
- //Initialize display.
- ALLEGRO_DISPLAY *display = NULL;
- al_set_new_display_flags(ALLEGRO_WINDOWED);
- display = al_create_display(screenHeight, screenWidth);
- al_set_window_title(display, "EOC++");
- //If display fails to initialize, exit.
- if(!display)
- return -1;
- //Install Keyboad, Mouse & Initialize most addons.
- al_install_keyboard();
- al_install_mouse();
- al_init_primitives_addon();
- al_init_font_addon();
- al_init_ttf_addon();
- al_init_image_addon();
- al_install_audio();
- al_init_acodec_addon();
- al_reserve_samples(1);
- //Create event queue
- ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
- //Create timer that will tick once per frame.
- ALLEGRO_TIMER *timer = al_create_timer(1.0/60.0); //60 frames per second.
- //register the event sources so they send events to our queue
- al_register_event_source(event_queue, al_get_display_event_source(display)); //display/window
- al_register_event_source(event_queue, al_get_keyboard_event_source()); //keyboard
- al_register_event_source(event_queue, al_get_mouse_event_source()); //mouse
- al_register_event_source(event_queue, al_get_timer_event_source(timer)); //fps timer
- //Initialize Bitmaps
- ALLEGRO_BITMAP *abg = al_load_bitmap("resources/images/0.bmp");
- ALLEGRO_BITMAP *bg = al_load_bitmap("resources/images/1.bmp");
- ALLEGRO_BITMAP *menub = al_load_bitmap("resources/images/2.bmp");
- ALLEGRO_BITMAP *login = al_load_bitmap("resources/images/3.bmp");
- ALLEGRO_BITMAP *menub2 = al_load_bitmap("resources/images/4.bmp");
- ALLEGRO_BITMAP *creation = al_load_bitmap("resources/images/5.bmp");
- ALLEGRO_BITMAP *readfirst = al_load_bitmap("resources/images/6.bmp");
- //Initialize MFX
- ALLEGRO_SAMPLE *lsm = al_load_sample("resources/mfx/mfx001.ogg");
- //Initialize Fonts
- //None yet.
- bool redraw = true;
- //Clicks
- bool loginclicked = false;
- bool accountclicked = false;
- bool okclicked = false;
- //Hovers for menu screen
- bool hovercreate = false;
- bool hoverplay = false;
- bool hovercredits = false;
- bool hoverexit = false;
- bool hoverconnect = false;
- bool hovercancel = false;
- //Hovers for account creation screen
- bool hovercreate2 = false;
- bool hovercancel2 = false;
- bool hoverok = false;
- al_convert_mask_to_alpha(menub, al_map_rgb(0,0,0));
- al_convert_mask_to_alpha(menub2, al_map_rgb(0,0,0));
- al_convert_mask_to_alpha(creation, al_map_rgb(0,0,0));
- al_clear_to_color(al_map_rgb(0,0,0));
- al_flip_display();
- //Start the timer
- al_start_timer(timer);
- /*when this variable is set to false
- the program will quit the main loop
- and free the allocated resources
- before quitting */
- while(1)
- {
- ALLEGRO_EVENT ev;
- al_wait_for_event(event_queue, &ev);
- if(ev.type == ALLEGRO_EVENT_TIMER)
- {
- al_play_sample(lsm, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_LOOP,NULL);
- redraw = true;
- }
- else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
- {
- break;
- }
- else if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
- {
- //handle key presses
- switch(ev.keyboard.keycode)
- {
- case ALLEGRO_KEY_F1:
- {
- }
- break;
- }
- }
- else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES)
- {
- ////////////////////////////////
- //Hovers for Menu screen
- //Hover Create Account button
- if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 300 && ev.mouse.y < 340)
- {
- hovercreate = true;
- }
- else
- hovercreate = false;
- //Hover Play button
- if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 340 && ev.mouse.y < 380)
- {
- hoverplay = true;
- }
- else
- hoverplay = false;
- //Hover Credits button
- if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 380 && ev.mouse.y < 420)
- {
- hovercredits = true;
- }
- else
- hovercredits = false;
- //Hover Exit button
- if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 420 && ev.mouse.y < 460)
- {
- hoverexit = true;
- }
- else
- hoverexit = false;
- //Hover Connect button
- if(ev.mouse.x > 388 && ev.mouse.x < 478 && ev.mouse.y > 400 && ev.mouse.y < 427)
- {
- hoverconnect = true;
- }
- else
- hoverconnect = false;
- //Hover Cancel button
- if(ev.mouse.x > 480 && ev.mouse.x < 570 && ev.mouse.y > 400 && ev.mouse.y < 427)
- hovercancel = true;
- else
- hovercancel = false;
- ////////////////////////////////
- ////////////////////////////////
- //Hovers for account creations screen
- //Hover create button
- if(ev.mouse.x > 358 && ev.mouse.x < 478 && ev.mouse.y > 420 && ev.mouse.y < 460)
- hovercreate2 = true;
- else
- hovercreate2 = false;
- //Hover cancel button
- if(ev.mouse.x > 480 && ev.mouse.x < 600 && ev.mouse.y > 420 && ev.mouse.y < 460)
- hovercancel2 = true;
- else
- hovercancel2 = false;
- //Hover OK Button
- if(ev.mouse.x > 297 && ev.mouse.x < 388 && ev.mouse.y > 315 && ev.mouse.y < 344)
- hoverok = true;
- else
- hoverok = false;
- }
- else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
- {
- if(ev.mouse.button & 1)
- {
- ////////////////////////////////
- //Menu buttons
- //Create Account button
- if(ev.mouse.x > 20 && ev.mouse.x < 200)
- {
- if(ev.mouse.y > 300 && ev.mouse.y < 340)
- {
- accountclicked = true;
- }
- }
- //Play button
- if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 340 && ev.mouse.y < 380)
- {
- loginclicked = true;
- }
- //Credits button
- //Exit button
- if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 420 && ev.mouse.y < 460)
- {
- break;
- }
- //Login Connect button
- //Login Cancel button
- if(ev.mouse.x > 480 && ev.mouse.x < 570 && ev.mouse.y > 400 && ev.mouse.y < 427)
- loginclicked = false;
- ////////////////////////////////
- ////////////////////////////////
- //Buttons in account creation screen
- //Cancel button
- if(ev.mouse.x > 480 && ev.mouse.x < 600 && ev.mouse.y > 420 && ev.mouse.y < 460)
- {
- accountclicked = false;
- okclicked = false;
- }
- //OK Button
- if(ev.mouse.x > 297 && ev.mouse.x < 388 && ev.mouse.y > 315 && ev.mouse.y < 344)
- okclicked = true;
- }
- }
- if(redraw && al_is_event_queue_empty(event_queue))
- {
- redraw = false;
- al_clear_to_color(al_map_rgb(0,0,0));
- if(!accountclicked)
- {
- //Draw BG
- al_draw_bitmap(bg, 0, 0, 0);
- //if mouse is not over create account button area, draw create account button.
- //Else, draw hovered create account button.
- if(!hovercreate)
- al_draw_bitmap_region(menub, 0, 0, 180, 40, 20, 300, 0);
- else
- al_draw_bitmap_region(menub, 180, 0, 180, 40, 20, 300, 0);
- //If mouse is not over play button area, draw play button.
- //Else, draw hovered play button.
- if(!hoverplay)
- al_draw_bitmap_region(menub, 0, 40, 180, 40, 20, 340, 0);
- else
- al_draw_bitmap_region(menub, 180, 40, 180, 40, 20, 340, 0);
- //if mouse is not over credits button area, draw credits button.
- //Else, draw hovered credit button.
- if(!hovercredits)
- al_draw_bitmap_region(menub, 0, 80, 180, 40, 20, 380, 0);
- else
- al_draw_bitmap_region(menub, 180, 80, 180, 40, 20, 380, 0);
- //if mouse is not over exit button area, draw exit button.
- //Else, draw hovered exit button.
- if(!hoverexit)
- al_draw_bitmap_region(menub, 0, 120, 180, 40, 20, 420, 0);
- else
- al_draw_bitmap_region(menub, 180, 120, 180, 40, 20, 420, 0);
- if(loginclicked)
- {
- al_draw_bitmap(login, 300, 300, 0);
- if(!hoverconnect)
- al_draw_bitmap_region(menub2, 0, 0, 91, 29, 388, 400, 0);
- else
- al_draw_bitmap_region(menub2, 91, 0, 91, 29, 388, 400, 0);
- if(!hovercancel)
- al_draw_bitmap_region(menub2, 0, 29, 91, 29, 480, 400, 0);
- else
- al_draw_bitmap_region(menub2, 91, 29, 91, 29, 480, 400, 0);
- }
- }
- else
- {
- al_draw_bitmap(abg, 0, 0, 0);
- if(!hovercreate2)
- al_draw_bitmap_region(creation, 0, 0, 120, 40, 358, 420, 0);
- else
- al_draw_bitmap_region(creation, 120, 0, 120, 40, 358, 420, 0);
- if(!hovercancel2)
- al_draw_bitmap_region(creation, 0, 40, 120, 40, 480, 420, 0);
- else
- al_draw_bitmap_region(creation, 120, 40, 120, 40, 480, 420, 0);
- if(!okclicked)
- {
- al_draw_bitmap(readfirst, 640 / 2 / 2, 480 / 2 / 2, 0);
- if(!hoverok)
- al_draw_bitmap_region(menub2, 0, 116, 91, 29, 297, 315, 0);
- else
- al_draw_bitmap_region(menub2, 91, 116, 91, 29, 297, 315, 0);
- }
- }
- al_flip_display();
- }
- }
- al_destroy_sample(lsm);
- al_destroy_bitmap(readfirst);
- al_destroy_bitmap(creation);
- al_destroy_bitmap(menub2);
- al_destroy_bitmap(login);
- al_destroy_bitmap(menub);
- al_destroy_bitmap(bg);
- al_destroy_bitmap(abg);
- al_destroy_timer(timer);
- al_destroy_event_queue(event_queue);
- al_destroy_display(display);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement