コード例 #1
0
ファイル: ex05.cpp プロジェクト: bambams/ma5king
int main() {
   ALLEGRO_DISPLAY     *display;
   ALLEGRO_TIMER       *tick_timer;

   if (!al_init()) {
      TRACE("Allegro init failed!\n");
      return 1;
   }

   al_init_font_addon();
   al_init_image_addon();
   al_init_primitives_addon();
   al_install_keyboard();
   al_install_mouse();

   display = al_create_display(640, 480);
   if (!display) {
      TRACE("Display init failed!\n");
      return 1;
   }

   al_hide_mouse_cursor(display);

   /* Must set this before calling InstallMASkinG() ! */
   MAS::SetLogicRate(1.0 / 0.02);

   /* MASkinG must be initialized after the display. */
   if (InstallMASkinG("allegro.cfg") != MAS::Error::NONE ) {
      TRACE("MA5kinG init failed!\n");
      return 1;
   }

   tick_timer = al_create_timer(0.02);

   queue = al_create_event_queue();
   al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE *) al_get_keyboard_event_source());
   al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE *) al_get_mouse_event_source());
   al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE *) display);
   al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE *) tick_timer);

   // create a new dialog on the current display
   MyDialog *dlg = new MyDialog();

   al_start_timer(tick_timer);

   /* You have to call this manually. */
   dlg->Start();

   while (!dlg->ShouldClose()) {
      ALLEGRO_EVENT event;
      al_wait_for_event(queue, &event);

      switch (event.type) {
         case ALLEGRO_EVENT_TIMER:
            if (event.timer.source == tick_timer) {
               dlg->DoTick();

               /* Skip the drawing if we've got more events to process. */
               if (!al_event_queue_is_empty(queue))
                  continue;

               /* Redraw the screen */
               al_clear_to_color(al_map_rgb(0, 0, 0));
               dlg->Draw();
               al_flip_display();
            }
            else
               /* Oh, it must be the game timer. */
               dlg->ProcessEvent(&event);
         break;
         default:
            dlg->ProcessEvent(&event);
      }
   }

   /* You have to call this manually. */
   dlg->End();

   // delete the dialog
   delete dlg;

   ExitMASkinG();

   return 0;
}