home *** CD-ROM | disk | FTP | other *** search
/ 3D Games (Spidla) / 3dhry1.iso / carterrain / src / menu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-17  |  5.5 KB  |  212 lines

  1. #include <allegro.h>
  2. #include <alleggl.h>
  3. #include <GL/gl.h>
  4. #include "menu.h"
  5.  
  6. extern FONT *allegro_fnt;
  7. extern int players;
  8.  
  9. double mousex, mousey;
  10. int focus;
  11.  
  12. int playersselect(void);
  13.  
  14. void main_menu(void)
  15. {
  16.   glViewport(0, 0, SCREEN_W, SCREEN_H);
  17.   while(1)
  18.     {
  19.       mousex=(double)mouse_x/SCREEN_W*40-20;
  20.       mousey=(double)(SCREEN_H-mouse_y)/SCREEN_H*30-15;
  21.  
  22.       if(mousex>=-3 && mousex<=3 && mousey>=-1 && mousey<=1)
  23.     focus=1;
  24.       else if(mousex>=-3 && mousex<=3 && mousey>=-4 && mousey<=-2)
  25.     focus=2;
  26.       else if(mousex>=-3 && mousex<=3 && mousey>=-7 && mousey<=-5)
  27.     focus=3;
  28.       else
  29.     focus=0;
  30.  
  31.       allegro_gl_begin();
  32.  
  33.       glMatrixMode(GL_PROJECTION);
  34.       glPushMatrix();
  35.       glLoadIdentity();
  36.       glOrtho(-20,20,-15,15,-1,1);
  37.       glMatrixMode(GL_MODELVIEW);
  38.       glLoadIdentity();
  39.       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  40.       glDisable(GL_LIGHTING);
  41.  
  42.       glBegin(GL_QUADS);
  43.       glColor3f(0, focus==1?1:0.7, 0);
  44.       glVertex2f(3, 1);
  45.       glVertex2f(-3, 1);
  46.       glVertex2f(-3, -1);
  47.       glVertex2f(3, -1);
  48.       //      glColor3f(0, focus==2?1:0.7, 0);
  49.       //      glVertex2f(3, -2);
  50.       //      glVertex2f(-3, -2);
  51.       //      glVertex2f(-3, -4);
  52.       //      glVertex2f(3, -4);
  53.       glColor3f(0, focus==3?1:0.7, 0);
  54.       glVertex2f(3, -5);
  55.       glVertex2f(-3, -5);
  56.       glVertex2f(-3, -7);
  57.       glVertex2f(3, -7);
  58.       glEnd();
  59.  
  60.       glEnable(GL_TEXTURE_2D);
  61.       glEnable(GL_BLEND);
  62.       allegro_gl_printf(allegro_fnt, -2, 10, 0, makecol(0, 255, 0), "carterrain");
  63.       allegro_gl_printf(allegro_fnt, -1.5, 0, 0, makecol(255, 0, 0), "New Game");
  64.       //      allegro_gl_printf(allegro_fnt, -1.5, -3, 0, makecol(255, 0, 0), "Options");
  65.       allegro_gl_printf(allegro_fnt, -1.5, -6, 0, makecol(255, 0, 0), "Quit");
  66.       glDisable(GL_BLEND);
  67.       glDisable(GL_TEXTURE_2D);
  68.  
  69.       glColor3f(1, 1, 1);
  70.       glTranslatef(mousex, mousey, 0);
  71.       glBegin(GL_TRIANGLES);
  72.       glVertex2f(0, 0);
  73.       glVertex2f(0, -1);
  74.       glVertex2f(0.7, -0.8);
  75.       glEnd();
  76.  
  77.       glMatrixMode(GL_PROJECTION);
  78.       glPopMatrix();
  79.       glMatrixMode(GL_MODELVIEW);
  80.       glLoadIdentity();
  81.       allegro_gl_end();
  82.  
  83.       allegro_gl_begin();
  84.       glFinish();
  85.       allegro_gl_flip();
  86.       allegro_gl_end();
  87.  
  88.       if(mouse_b&1 && focus>0)
  89.     {
  90.       while(mouse_b&1);
  91.       if(focus==3)
  92.         {
  93.     allegro_gl_begin();
  94.     glMatrixMode(GL_PROJECTION);
  95.     glPushMatrix();
  96.     glLoadIdentity();
  97.     glViewport(0, 0, SCREEN_W, SCREEN_H);
  98.     glOrtho(-20,20,-15,15,-1,1);
  99.     glMatrixMode(GL_MODELVIEW);
  100.     glLoadIdentity();
  101.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  102.     glDisable(GL_LIGHTING);
  103.     glEnable(GL_TEXTURE_2D);
  104.  
  105.     glClear(GL_COLOR_BUFFER_BIT);
  106.     allegro_gl_printf(allegro_fnt, -2, 10, 0, makecol(0, 255, 0), "carterrain");
  107.     allegro_gl_printf(allegro_fnt, -8, 7, 0, makecol(0, 0, 255), "Programming & Graphics:  Benny Kramek");
  108.     allegro_gl_printf(allegro_fnt, -6, 5, 0, makecol(255, 255, 0), "http://www.wolfman8k.barrysworld.net");
  109.     allegro_gl_printf(allegro_fnt, -3, -3, 0, makecol(0, 128, 0), "Uses AllegroGL game programming library");
  110.     allegro_gl_printf(allegro_fnt, -3, -5, 0, makecol(0, 128, 0), "Uses ODE real-time physics library");
  111.     allegro_gl_printf(allegro_fnt, -7, -10, 0, makecol(255, 255, 255), "I hope you enjoyed playing!");
  112.  
  113.     glFinish();
  114.     allegro_gl_flip();
  115.     allegro_gl_end();
  116.  
  117.     rest(2000);
  118.     while(!key[KEY_ESC]);
  119.  
  120.     exit(0);
  121.         }
  122.       if(focus==1)
  123.         if(playersselect()==1)
  124.           break;
  125.     }
  126.     }
  127. }
  128.  
  129. int playersselect(void)
  130. {
  131.   int i;
  132.   while(1)
  133.     {
  134.       mousex=(double)mouse_x/SCREEN_W*40-20;
  135.       mousey=(double)(SCREEN_H-mouse_y)/SCREEN_H*30-15;
  136.  
  137.       focus=0;
  138.       for(i=0; i<6; i++)
  139.     if(mousex>=i*3-1-7.5 && mousex<=i*3+1-7.5 && mousey>=-1 && mousey<=1)
  140.       focus=i+1;
  141.       if(mousex>=-3 && mousex<=3 && mousey>=-7 && mousey<=-5)
  142.     focus=7;
  143.  
  144.       allegro_gl_begin();
  145.  
  146.       glMatrixMode(GL_PROJECTION);
  147.       glPushMatrix();
  148.       glLoadIdentity();
  149.       glOrtho(-20,20,-15,15,-1,1);
  150.       glMatrixMode(GL_MODELVIEW);
  151.       glLoadIdentity();
  152.       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  153.       glDisable(GL_LIGHTING);
  154.  
  155.       glBegin(GL_QUADS);
  156.       for(i=0; i<6; i++)
  157.     {
  158.       glColor3f(0, focus==i+1?1:0.7, 0);
  159.       glVertex2f(i*3+1-7.5, 1);
  160.       glVertex2f(i*3-1-7.5, 1);
  161.       glVertex2f(i*3-1-7.5, -1);
  162.       glVertex2f(i*3+1-7.5, -1);
  163.     }
  164.       glColor3f(0, focus==7?1:0.7, 0);
  165.       glVertex2f(3, -5);
  166.       glVertex2f(-3, -5);
  167.       glVertex2f(-3, -7);
  168.       glVertex2f(3, -7);
  169.       glEnd();
  170.  
  171.       glEnable(GL_TEXTURE_2D);
  172.       glEnable(GL_BLEND);
  173.       allegro_gl_printf(allegro_fnt, -4, 4, 0, makecol(0, 255, 0), "How many players?");
  174.       for(i=0; i<6; i++)
  175.     allegro_gl_printf(allegro_fnt, i*3-7.5, 0, 0, makecol(255, 0, 0), "%d", i+1);
  176.       allegro_gl_printf(allegro_fnt, -1.5, -6, 0, makecol(255, 0, 0), "Cancel");
  177.       glDisable(GL_BLEND);
  178.       glDisable(GL_TEXTURE_2D);
  179.  
  180.       glColor3f(1, 1, 1);
  181.       glTranslatef(mousex, mousey, 0);
  182.       glBegin(GL_TRIANGLES);
  183.       glVertex2f(0, 0);
  184.       glVertex2f(0, -1);
  185.       glVertex2f(0.7, -0.8);
  186.       glEnd();
  187.  
  188.       glMatrixMode(GL_PROJECTION);
  189.       glPopMatrix();
  190.       glMatrixMode(GL_MODELVIEW);
  191.       glLoadIdentity();
  192.       allegro_gl_end();
  193.  
  194.       allegro_gl_begin();
  195.       glFinish();
  196.       allegro_gl_flip();
  197.       allegro_gl_end();
  198.  
  199.       if(mouse_b&1 && focus>0)
  200.     {
  201.       while(mouse_b&1);
  202.       if(focus==7)
  203.         return 0;
  204.       else
  205.         {
  206.           players=focus;
  207.           return 1;
  208.         }
  209.     }
  210.     }  
  211. }
  212.