Advertisement
DizzyFoxkit

IDE/Linker/Codblocks project

Aug 15th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.85 KB | None | 0 0
  1. // Game.cpp
  2. #include <stdio.h>
  3. #include <allegro5/allegro.h>
  4.  
  5. #include "Managers.hpp"
  6.  
  7. int main(int argc, char **argv)
  8. {
  9.  
  10.  
  11.     if(!al_init()) {
  12.         fprintf(stderr, "Failed to initialize Allegro\n");
  13.         return -1;
  14.     }
  15.  
  16.     EventManager *emanager;
  17.     DisplayManager *display;
  18.  
  19.     emanager->registerSources();
  20.     display->registerDisplay();
  21.  
  22.  
  23.    return 0;
  24. }
  25.  
  26. // Managers.cpp
  27. #include <stdio.h>
  28. #include <allegro5/allegro.h>
  29.  
  30. #include "Managers.hpp"
  31. /* Self built manager to seperate out into the MVC model as much as possible */
  32. EventManager::EventManager()
  33.     {
  34.          ALLEGRO_EVENT_QUEUE *event_queue = NULL; // The event queue declaration
  35.          ALLEGRO_TIMER *timer = NULL;
  36.          float FPS = 60;
  37.     }
  38. EventManager::~EventManager()
  39.     {
  40.         al_destroy_event_queue(event_queue);
  41.         al_destroy_timer(timer);
  42.     }
  43.  
  44. int EventManager::registerSources() // register all the sources for input: Mouse, Keyboard, Gamepad.
  45.     {
  46.  
  47.         if(!al_install_mouse()){
  48.             fprintf(stderr, "Failed to initialize the Mouse\n");
  49.             return -1;
  50.         }
  51.  
  52.         if(!al_install_keyboard()){
  53.             fprintf(stderr, "Failed to initialize the Keyboard\n");
  54.             return -1;
  55.         }
  56.  
  57.         timer = al_create_timer(1.0 / FPS);
  58.         if(!timer) {
  59.             fprintf(stderr, "Failed to create timer \n");
  60.             return -1;
  61.         }
  62.  
  63.         event_queue = al_create_event_queue();
  64.         if(!event_queue) {
  65.             fprintf(stderr, "Failed to create the Event Queue\n");
  66.             return -1;
  67.         }
  68.  
  69.         al_register_event_source(event_queue, al_get_mouse_event_source());
  70.         al_register_event_source(event_queue, al_get_keyboard_event_source());
  71.  
  72.     }
  73.  
  74.  
  75. /* Manager to handle the display end of things. Essentially the view. */
  76. Displaymanager::DisplayManager()
  77.     {
  78.         float FPS = 60;
  79.         int SCREEN_W = 640;
  80.         int SCREEN_H = 480;
  81.         bool redraw = true;
  82.         ALLEGRO_DISPLAY *display = NULL;
  83.         ALLEGRO_TIMER *timer = NULL;
  84.         ALLEGRO_EVENT_QUEUE *event_queue = NULL;
  85.     }
  86.  
  87. DisplayManager::~DisplayManager()
  88.     {
  89.         al_destroy_display(display);
  90.         al_destory_timer(timer);
  91.         al_destroy_event_queue(event_queue);
  92.     }
  93.  
  94. int DisplayManager::registerDisplay()
  95.     {
  96.         timer = al_create_timer(1.0/FPS);
  97.         if(!timer) {
  98.             fprintf(stderr, "Faile to Create DisplayManager Timer\n");
  99.             al_destroy_timer(timer);
  100.             return -1;
  101.         }
  102.  
  103.         display = al_create_display();
  104.         if(!display) {
  105.             fprintf(stderr, "Failed to create the Display \n");
  106.             al_destory_display(display);
  107.             al_destory_timer(timer);
  108.             return -1;
  109.         }
  110.  
  111.         event_queue = al_create_event_queue();
  112.         if(!event_queue) {
  113.             fprintf(stderr, "Failed to create the Display Event_Queue/n");
  114.             al_destory_event_queue(event_queue);
  115.             al_destory_timer(timer);
  116.             al_destory_display(display);
  117.             return -1;
  118.         }
  119.  
  120.         al_register_event_source(event_queue, al_get_display_event_source(display));
  121.  
  122.         al_regisger_event_source(event_queue, al_get_timer_event_source(timer));
  123.  
  124.  
  125.     }
  126.  
  127. void DisplayManager::Draw()
  128.     {
  129.         al_flip_display();
  130.     }
  131.  
  132. // Managers.hpp
  133. #ifndef ALL_MANAGER //if ALL_MANAGER hasn't been defnined yet
  134. #define ALL_MANAGER
  135. class EventManager
  136. /* Self built manager to separate out the program into the MVC model as much as possible. */
  137. {
  138. public:
  139.     EventManager();
  140.     ~EventManager();
  141.     int registerSources();
  142. };
  143.  
  144. class DisplayManager
  145. /* Display manager to handle the drawing methods. Essentially a view */
  146. {
  147. public:
  148.     DisplayManager();
  149.     ~DisplayManager();
  150.     int registerDisplay();
  151.     void Draw();
  152. };
  153.  
  154. #endif // ALL_MANAGER
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement