home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / demos / mfighter / build / menu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-14  |  2.4 KB  |  149 lines

  1. #include <fastgraf.h>
  2. #include <conio.h>
  3. #include "pages.h"
  4. #include "match.h"
  5. #include "menu.h"
  6.  
  7. const int PLAY = 1;
  8. const int HELP = 2;
  9. const int QUIT = 3;
  10.  
  11. const int MENU_PATCH_Y = 59;
  12. const int MENU_PATCH_X = 92;
  13.  
  14. //class Match;
  15. //class HelpPage;
  16.  
  17. MenuItem::MenuItem(Director* d,int m) : Performer(d)
  18.   {
  19.   myimage=m;
  20.   }
  21.  
  22. void MenuItem::display()
  23.   {
  24.   show_frame(MENU_PATCH_X,MENU_PATCH_Y,myimage);
  25.   }
  26.  
  27. void MenuItem::initialize()
  28.   {
  29.   load_gfxlib("menu.gfx");
  30.   load_sfxlib("sounds.sfx");
  31.   }
  32.  
  33. void MenuItem::play_switch_sound()
  34.   {
  35.   play_sound_clip(1); 
  36.   }
  37.  
  38. //---------------------------------------------- MENU -----------
  39.  
  40. CUELIST(Menu)
  41.   KEYSTROKE(UP,on_up)
  42.   KEYSTROKE(DN,on_down)
  43.   KEYSTROKE('\r',on_enter)
  44.   KEYSTROKE(ESC,on_escape)
  45.   KEYSTROKE('f',on_fight)
  46.   KEYSTROKE('h',on_help)
  47.   KEYSTROKE('q',on_quit)
  48. ENDCUELIST
  49.  
  50. Menu::Menu() : VideoDirector()
  51.   {
  52.   item[1]=new MenuItem(this,PLAY);
  53.   item[2]=new MenuItem(this,HELP);
  54.   item[3]=new MenuItem(this,QUIT);
  55.   }
  56.  
  57. Menu::~Menu()
  58.   {
  59.   delete item[1];
  60.   delete item[2];
  61.   delete item[3];
  62.   }
  63.  
  64. const Type_info& Menu::get_next_director()
  65.   {
  66.   if (cur==PLAY)  return typeid(Match);
  67.   if (cur==HELP)  return typeid(HelpPage);
  68.   return typeid(StopDirector);
  69.   }
  70.  
  71. void Menu::initialize()
  72.   {
  73.   cur=PLAY;
  74.   }
  75.  
  76. void Menu::display()
  77.   {
  78.   init_video(); 
  79.   show_pcx("menu.pcx");
  80.   if (cur!=PLAY)
  81.     item[cur]->display();
  82.   swap_video_pages();
  83.   synch_video_pages();
  84.   }  //tag
  85.  
  86. void Menu::on_up(int)
  87.   {
  88.   if (cur>PLAY)  cur--;
  89.   else  cur=ITEMS;
  90.   item[cur]->display();
  91.   item[cur]->play_switch_sound();
  92.   swap_video_pages();
  93.   }
  94.  
  95. void Menu::on_down(int)
  96.   {
  97.   if (cur<ITEMS)  cur++;
  98.   else  cur=PLAY;
  99.   item[cur]->display();
  100.   item[cur]->play_switch_sound();
  101.   swap_video_pages();
  102.   }
  103.  
  104.  
  105. void Menu::on_fight(int)
  106.   {
  107.   if (cur!=PLAY)
  108.     {
  109.     cur=PLAY;
  110.     item[cur]->display();
  111.     item[cur]->play_switch_sound();
  112.     swap_video_pages();
  113.     }
  114.   }
  115.  
  116. void Menu::on_help(int)
  117.   {
  118.   if (cur!=HELP)
  119.     {
  120.     cur=HELP;
  121.     item[cur]->display();
  122.     item[cur]->play_switch_sound();
  123.     swap_video_pages();
  124.     }
  125.   }
  126.  
  127. void Menu::on_quit(int)
  128.   {
  129.   if (cur!=QUIT)
  130.     {
  131.     cur=QUIT;
  132.     item[cur]->display();
  133.     item[cur]->play_switch_sound();
  134.     swap_video_pages();
  135.     }
  136.   }
  137.  
  138. void Menu::on_enter(int)
  139.   {
  140.   stop_director();
  141.   }
  142.  
  143. void Menu::on_escape(int)
  144.   {
  145.   cur=QUIT;
  146.   stop_director();
  147.   }
  148.  
  149.