Advertisement
Guest User

EOC++ 24-08-2014

a guest
Aug 24th, 2014
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.95 KB | None | 0 0
  1. #include "Includes.h"
  2.  
  3. #define screenHeight 640
  4. #define screenWidth 480
  5.  
  6. int main()
  7. {
  8.     //If Allegro 5 fails to initialize, exit.
  9.     if(!al_init())
  10.         return -1;
  11.  
  12.     //Initialize display.
  13.     ALLEGRO_DISPLAY *display = NULL;
  14.     al_set_new_display_flags(ALLEGRO_WINDOWED);
  15.     display = al_create_display(screenHeight, screenWidth);
  16.     al_set_window_title(display, "EOC++");
  17.  
  18.     //If display fails to initialize, exit.
  19.     if(!display)
  20.         return -1;
  21.  
  22.     //Install Keyboad, Mouse & Initialize most addons.
  23.     al_install_keyboard();
  24.     al_install_mouse();
  25.     al_init_primitives_addon();
  26.     al_init_font_addon();
  27.     al_init_ttf_addon();
  28.     al_init_image_addon();
  29.     al_install_audio();
  30.     al_init_acodec_addon();
  31.     al_reserve_samples(1);
  32.  
  33.     //Create event queue
  34.     ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
  35.  
  36.     //Create timer that will tick once per frame.
  37.     ALLEGRO_TIMER *timer = al_create_timer(1.0/60.0); //60 frames per second.
  38.  
  39.     //register the event sources so they send events to our queue
  40.     al_register_event_source(event_queue, al_get_display_event_source(display)); //display/window
  41.     al_register_event_source(event_queue, al_get_keyboard_event_source()); //keyboard
  42.     al_register_event_source(event_queue, al_get_mouse_event_source()); //mouse
  43.     al_register_event_source(event_queue, al_get_timer_event_source(timer)); //fps timer
  44.  
  45.     //Initialize Bitmaps
  46.     ALLEGRO_BITMAP *abg = al_load_bitmap("resources/images/0.bmp");
  47.     ALLEGRO_BITMAP *bg = al_load_bitmap("resources/images/1.bmp");
  48.     ALLEGRO_BITMAP *menub = al_load_bitmap("resources/images/2.bmp");
  49.     ALLEGRO_BITMAP *login = al_load_bitmap("resources/images/3.bmp");
  50.     ALLEGRO_BITMAP *menub2 = al_load_bitmap("resources/images/4.bmp");
  51.     ALLEGRO_BITMAP *creation = al_load_bitmap("resources/images/5.bmp");
  52.     ALLEGRO_BITMAP *readfirst = al_load_bitmap("resources/images/6.bmp");
  53.  
  54.     //Initialize MFX
  55.     ALLEGRO_SAMPLE *lsm = al_load_sample("resources/mfx/mfx001.ogg");
  56.  
  57.     //Initialize Fonts
  58.     //None yet.
  59.  
  60.     bool redraw = true;
  61.  
  62.     //Clicks
  63.     bool loginclicked = false;
  64.     bool accountclicked = false;
  65.     bool okclicked = false;
  66.  
  67.     //Hovers for menu screen
  68.     bool hovercreate = false;
  69.     bool hoverplay = false;
  70.     bool hovercredits = false;
  71.     bool hoverexit = false;
  72.     bool hoverconnect = false;
  73.     bool hovercancel = false;
  74.     //Hovers for account creation screen
  75.     bool hovercreate2 = false;
  76.     bool hovercancel2 = false;
  77.     bool hoverok = false;
  78.  
  79.     al_convert_mask_to_alpha(menub, al_map_rgb(0,0,0));
  80.     al_convert_mask_to_alpha(menub2, al_map_rgb(0,0,0));
  81.     al_convert_mask_to_alpha(creation, al_map_rgb(0,0,0));
  82.     al_clear_to_color(al_map_rgb(0,0,0));
  83.     al_flip_display();
  84.  
  85.     //Start the timer
  86.     al_start_timer(timer);
  87.  
  88.     /*when this variable is set to false
  89.       the program will quit the main loop
  90.       and free the allocated resources
  91.       before quitting */
  92.     while(1)
  93.     {
  94.         ALLEGRO_EVENT ev;
  95.         al_wait_for_event(event_queue, &ev);
  96.  
  97.         if(ev.type == ALLEGRO_EVENT_TIMER)
  98.         {
  99.             al_play_sample(lsm, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_LOOP,NULL);
  100.             redraw = true;
  101.         }
  102.         else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
  103.         {
  104.             break;
  105.         }
  106.         else if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
  107.         {
  108.             //handle key presses
  109.             switch(ev.keyboard.keycode)
  110.             {
  111.             case ALLEGRO_KEY_F1:
  112.                 {
  113.                 }
  114.                 break;
  115.             }
  116.         }
  117.         else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES)
  118.         {
  119.             ////////////////////////////////
  120.             //Hovers for Menu screen
  121.             //Hover Create Account button
  122.             if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 300 && ev.mouse.y < 340)
  123.             {
  124.                 hovercreate = true;
  125.             }
  126.             else
  127.                 hovercreate = false;
  128.  
  129.             //Hover Play button
  130.             if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 340 && ev.mouse.y < 380)
  131.             {
  132.                 hoverplay = true;
  133.             }
  134.             else
  135.                 hoverplay = false;
  136.  
  137.             //Hover Credits button
  138.             if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 380 && ev.mouse.y < 420)
  139.             {
  140.                 hovercredits = true;
  141.             }
  142.             else
  143.                 hovercredits = false;
  144.  
  145.             //Hover Exit button
  146.             if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 420 && ev.mouse.y < 460)
  147.             {
  148.                 hoverexit = true;
  149.             }
  150.             else
  151.                 hoverexit = false;
  152.  
  153.             //Hover Connect button
  154.             if(ev.mouse.x > 388 && ev.mouse.x < 478 && ev.mouse.y > 400 && ev.mouse.y < 427)
  155.             {
  156.                 hoverconnect = true;
  157.             }
  158.             else
  159.                 hoverconnect = false;
  160.  
  161.             //Hover Cancel button
  162.             if(ev.mouse.x > 480 && ev.mouse.x < 570 && ev.mouse.y > 400 && ev.mouse.y < 427)
  163.                 hovercancel = true;
  164.             else
  165.                 hovercancel = false;
  166.             ////////////////////////////////
  167.  
  168.             ////////////////////////////////
  169.             //Hovers for account creations screen
  170.             //Hover create button
  171.             if(ev.mouse.x > 358 && ev.mouse.x < 478 && ev.mouse.y > 420 && ev.mouse.y < 460)
  172.                 hovercreate2 = true;
  173.             else
  174.                 hovercreate2 = false;
  175.  
  176.             //Hover cancel button
  177.             if(ev.mouse.x > 480 && ev.mouse.x < 600 && ev.mouse.y > 420 && ev.mouse.y < 460)
  178.                 hovercancel2 = true;
  179.             else
  180.                 hovercancel2 = false;
  181.  
  182.             //Hover OK Button
  183.             if(ev.mouse.x > 297 && ev.mouse.x < 388 && ev.mouse.y > 315 && ev.mouse.y < 344)
  184.                 hoverok = true;
  185.             else
  186.                 hoverok = false;
  187.         }
  188.         else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
  189.         {
  190.             if(ev.mouse.button & 1)
  191.             {
  192.                 ////////////////////////////////
  193.                 //Menu buttons
  194.                 //Create Account button
  195.                 if(ev.mouse.x > 20 && ev.mouse.x < 200)
  196.                 {
  197.                     if(ev.mouse.y > 300 && ev.mouse.y < 340)
  198.                     {
  199.                             accountclicked = true;
  200.                     }
  201.                 }
  202.  
  203.                 //Play button
  204.                 if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 340 && ev.mouse.y < 380)
  205.                 {
  206.                    
  207.                         loginclicked = true;
  208.                 }
  209.                
  210.                 //Credits button
  211.                
  212.                 //Exit button
  213.                 if(ev.mouse.x > 20 && ev.mouse.x < 200 && ev.mouse.y > 420 && ev.mouse.y < 460)
  214.                 {
  215.                     break;
  216.                 }
  217.  
  218.                 //Login Connect button
  219.                
  220.                 //Login Cancel button
  221.                 if(ev.mouse.x > 480 && ev.mouse.x < 570 && ev.mouse.y > 400 && ev.mouse.y < 427)
  222.                     loginclicked = false;
  223.                 ////////////////////////////////
  224.  
  225.                 ////////////////////////////////
  226.                 //Buttons in account creation screen
  227.                 //Cancel button
  228.                 if(ev.mouse.x > 480 && ev.mouse.x < 600 && ev.mouse.y > 420 && ev.mouse.y < 460)
  229.                 {
  230.                     accountclicked = false;
  231.                     okclicked = false;
  232.                 }
  233.  
  234.                 //OK Button
  235.                 if(ev.mouse.x > 297 && ev.mouse.x < 388 && ev.mouse.y > 315 && ev.mouse.y < 344)
  236.                     okclicked = true;
  237.             }
  238.         }
  239.  
  240.         if(redraw && al_is_event_queue_empty(event_queue))
  241.         {
  242.             redraw = false;
  243.             al_clear_to_color(al_map_rgb(0,0,0));
  244.  
  245.             if(!accountclicked)
  246.             {
  247.                 //Draw BG
  248.                 al_draw_bitmap(bg, 0, 0, 0);
  249.  
  250.                 //if mouse is not over create account button area, draw create account button.
  251.                 //Else, draw hovered create account button.
  252.                 if(!hovercreate)
  253.                     al_draw_bitmap_region(menub, 0, 0, 180, 40, 20, 300, 0);
  254.                 else
  255.                     al_draw_bitmap_region(menub, 180, 0, 180, 40, 20, 300, 0);
  256.  
  257.                 //If mouse is not over play button area, draw play button.
  258.                 //Else, draw hovered play button.
  259.                 if(!hoverplay)
  260.                     al_draw_bitmap_region(menub, 0, 40, 180, 40, 20, 340, 0);
  261.                 else
  262.                     al_draw_bitmap_region(menub, 180, 40, 180, 40, 20, 340, 0);
  263.  
  264.                 //if mouse is not over credits button area, draw credits button.
  265.                 //Else, draw hovered credit button.
  266.                 if(!hovercredits)
  267.                     al_draw_bitmap_region(menub, 0, 80, 180, 40, 20, 380, 0);
  268.                 else
  269.                     al_draw_bitmap_region(menub, 180, 80, 180, 40, 20, 380, 0);
  270.  
  271.                 //if mouse is not over exit button area, draw exit button.
  272.                 //Else, draw hovered exit button.
  273.                 if(!hoverexit)
  274.                     al_draw_bitmap_region(menub, 0, 120, 180, 40, 20, 420, 0);
  275.                 else
  276.                     al_draw_bitmap_region(menub, 180, 120, 180, 40, 20, 420, 0);
  277.  
  278.                 if(loginclicked)
  279.                 {
  280.                     al_draw_bitmap(login, 300, 300, 0);
  281.                     if(!hoverconnect)
  282.                         al_draw_bitmap_region(menub2, 0, 0, 91, 29, 388, 400, 0);
  283.                     else
  284.                         al_draw_bitmap_region(menub2, 91, 0, 91, 29, 388, 400, 0);
  285.  
  286.                     if(!hovercancel)
  287.                         al_draw_bitmap_region(menub2, 0, 29, 91, 29, 480, 400, 0);
  288.                     else
  289.                         al_draw_bitmap_region(menub2, 91, 29, 91, 29, 480, 400, 0);
  290.                 }
  291.             }
  292.             else
  293.             {
  294.                 al_draw_bitmap(abg, 0, 0, 0);
  295.                 if(!hovercreate2)
  296.                     al_draw_bitmap_region(creation, 0, 0, 120, 40, 358, 420, 0);
  297.                 else
  298.                     al_draw_bitmap_region(creation, 120, 0, 120, 40, 358, 420, 0);
  299.                 if(!hovercancel2)
  300.                     al_draw_bitmap_region(creation, 0, 40, 120, 40, 480, 420, 0);
  301.                 else
  302.                     al_draw_bitmap_region(creation, 120, 40, 120, 40, 480, 420, 0);
  303.                 if(!okclicked)
  304.                 {
  305.                     al_draw_bitmap(readfirst, 640 / 2 / 2, 480 / 2 / 2, 0);
  306.                     if(!hoverok)
  307.                         al_draw_bitmap_region(menub2, 0, 116, 91, 29, 297, 315, 0);
  308.                     else
  309.                         al_draw_bitmap_region(menub2, 91, 116, 91, 29, 297, 315, 0);
  310.                 }
  311.             }
  312.             al_flip_display();
  313.         }
  314.     }
  315.    
  316.     al_destroy_sample(lsm);
  317.     al_destroy_bitmap(readfirst);
  318.     al_destroy_bitmap(creation);
  319.     al_destroy_bitmap(menub2);
  320.     al_destroy_bitmap(login);
  321.     al_destroy_bitmap(menub);
  322.     al_destroy_bitmap(bg);
  323.     al_destroy_bitmap(abg);
  324.     al_destroy_timer(timer);
  325.     al_destroy_event_queue(event_queue);
  326.     al_destroy_display(display);
  327.     return 0;
  328. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement