thenuke321

Untitled

Jul 14th, 2015
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.62 KB | None | 0 0
  1. #include <allegro5/allegro.h>
  2. #include <allegro5/allegro_native_dialog.h>
  3. #include <allegro5/allegro_font.h>
  4. #include <allegro5/allegro_ttf.h>
  5. #include <allegro5/allegro_primitives.h>
  6. #include <cstdlib>
  7. #include <time.h>
  8. #include <stdio.h>
  9. #include <iostream>
  10. #include "I:\Software Stuff\C++ Code\Allegro\Game\Game\old.h"
  11. //#include "old.h"
  12. using namespace std;
  13.  
  14. #define xDisplay 1000
  15. #define yDisplay 600
  16. #define maxFrameRate 60
  17.  
  18. #define windowFrameMode ALLEGRO_NOFRAME
  19.  
  20. class Core
  21. {
  22. private:
  23.     ALLEGRO_DISPLAY *mainDisplay; // This is a pointer for the display!
  24. public:
  25.     void makeWindow(int);
  26.     void drawShit();
  27.     void testKeys();
  28. };
  29.  
  30.  
  31. void Core::makeWindow(int mode)
  32. {
  33.     // Use mode 1 to make and mode 0 to break window
  34.     if(mode == 1)
  35.     {
  36.        
  37.         // This is a catch of sorts to grab errors
  38.         if(!al_init()) // This if statment is needed for some fucking real cuz yeah it is fucked and shit like that
  39.         {
  40.             al_show_native_message_box(NULL,NULL,NULL,"ERROR",NULL,NULL);
  41.         }
  42.         al_set_new_display_flags(windowFrameMode); // Uses the windowFrameModes
  43.         mainDisplay = al_create_display(xDisplay,yDisplay); // This sets the size of the windows and uses the defines
  44.         al_set_new_display_refresh_rate(maxFrameRate); // This is the FPS thing
  45.         al_set_window_title(mainDisplay,"Atton's Testing Ground");
  46.     }
  47.     if(mode == 0)
  48.     {
  49.         al_destroy_display(mainDisplay);
  50.     }
  51. }
  52.  
  53.  
  54. void Core::drawShit()
  55. {
  56.     int x1(400);
  57.     int y1(400);
  58.     int x2(450);
  59.     int y2(500);
  60.    
  61.    
  62.  
  63.     al_init_primitives_addon(); // This calls the draw functions
  64.     ALLEGRO_COLOR electricBlue = al_map_rgb(44,117,255);
  65.     while(true)
  66.     {
  67.         cin >> x1 >> y1 >> x2 >> y2;
  68.         //cout << x1 << y1 << x2 << y2 << endl;
  69.         //al_draw_rectangle(400,400,450,500,electricBlue,1.0);
  70.         al_draw_rectangle(x1,y1,x2,y2,electricBlue,1.0);
  71.         al_draw_line(x1,y1,x2,y2,electricBlue,1.0);
  72.         al_flip_display();
  73.  
  74.         al_rest(0.016);
  75.     }
  76. }
  77.  
  78. void Core::testKeys()
  79. {
  80.     al_install_keyboard();
  81.     al_init_primitives_addon();
  82.  
  83.     ALLEGRO_COLOR electricBlue = al_map_rgb(44,117,255);
  84.     ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
  85.     ALLEGRO_TIMER *timer = al_create_timer(1.0 / 60);
  86.  
  87.     al_register_event_source(event_queue, al_get_keyboard_event_source());
  88.     al_register_event_source(event_queue, al_get_timer_event_source(timer));
  89.  
  90.  
  91.     enum Direction{UP,DOWN,LEFT,RIGHT};
  92.     bool done = false;
  93.     bool draw = false;
  94.     int x = 10;
  95.     int y = 10;
  96.     int moveSpeed = 5;
  97.     int dir = DOWN;
  98.     al_start_timer(timer);
  99.  
  100.     while(!done)
  101.     {
  102.         ALLEGRO_EVENT events;
  103.         al_wait_for_event(event_queue, &events);
  104.         if(events.type == ALLEGRO_EVENT_KEY_DOWN)
  105.         {
  106.             switch(events.keyboard.keycode)
  107.             {
  108.             case ALLEGRO_KEY_DOWN:
  109.                 dir = DOWN;
  110.                 break;
  111.             case ALLEGRO_KEY_UP:
  112.                 dir = UP;
  113.                 break;
  114.             case ALLEGRO_KEY_RIGHT:
  115.                 dir = RIGHT;
  116.                 break;
  117.             case ALLEGRO_KEY_LEFT:
  118.                 dir = LEFT;
  119.             case ALLEGRO_KEY_ESCAPE:
  120.                 //done = true;
  121.                 break;
  122.             }
  123.             if(events.type == ALLEGRO_EVENT_TIMER)
  124.             {
  125.                 switch(dir)
  126.                 {
  127.                 case DOWN:
  128.                     y+= moveSpeed;
  129.                     break;
  130.                 case UP:
  131.                     y -= moveSpeed;
  132.                     break;
  133.                 case RIGHT:
  134.                     x+= moveSpeed;
  135.                     break;
  136.                 case LEFT:
  137.                     x-= moveSpeed;
  138.                     break;
  139.                     draw = true;
  140.                 }
  141.             }
  142.         }
  143.         if(draw)
  144.         {
  145.             draw = false;
  146.             al_draw_rectangle(x,y,x + 20,y + 20,electricBlue,2.0);
  147.             al_flip_display();
  148.             //al_clear_to_color(al_map_rgb(0,0,0));
  149.         }
  150.     }
  151.     makeWindow(0);
  152.     al_destroy_event_queue(event_queue);
  153. }
  154.  
  155. int main(int argc, char **argv)
  156. {
  157.     Core Function;
  158.     Function.makeWindow(1);
  159.    
  160.     //getSystemInfo();
  161.     //getSystemInfo();
  162.     Function.testKeys();
  163.     cout << "OP DONE" << endl;
  164.     system("pause");
  165.  
  166.     return 0;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment