⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menu.cpp

📁 SDL-Ball这款经典的弹球游戏克隆自arkanoid、dxball、breakout
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ************************************************************************* *     SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux     Copyright (C) 2008 DusteD.dk    This program is free software: you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation, either version 3 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program.  If not, see <http://www.gnu.org/licenses/>.  * ************************************************************************* */struct score {  int score;  string name;};//TODO: get the other textue stuff into the class tooclass menuClass {private:GLuint texHighScore[20]; textureClass tex[40];GLuint dl;public:  menuClass()  {    glGenTextures(20, &texHighScore[0]);    genHsTex(); //load the highscore file (if exists) and print to texture    textureManager texMgr;    dl = glGenLists(5); //Generate displaylists      SDL_Color txtColorRed = {255,0,0};    SDL_Color txtColorGreen = {0,255,0};    SDL_Color txtColorBlue = {0,0,255};    SDL_Color txtColorWhite = {255,255,255};    SDL_Color txtColorBlack = {0,0,0};      texMgr.load("data/gfx/menu/menu0.png", tex[0]);    texMgr.load("data/gfx/menu/but0.png", tex[1]);    texMgr.load("data/gfx/menu/but1.png", tex[2]);    texMgr.load("data/gfx/menu/but2.png", tex[3]);      glGenTextures(1, &tex[4].prop.texture);    glGenTextures(1, &tex[5].prop.texture);    glGenTextures(1, &tex[6].prop.texture);    glGenTextures(1, &tex[7].prop.texture);    glGenTextures(1, &tex[8].prop.texture);    glGenTextures(1, &tex[9].prop.texture);    glGenTextures(1, &tex[10].prop.texture);    glGenTextures(1, &tex[11].prop.texture);    glGenTextures(1, &tex[12].prop.texture);    glGenTextures(1, &tex[13].prop.texture);    glGenTextures(1, &tex[14].prop.texture);    glGenTextures(1, &tex[15].prop.texture);    glGenTextures(1, &tex[16].prop.texture);    glGenTextures(1, &tex[17].prop.texture);    glGenTextures(1, &tex[18].prop.texture);    glGenTextures(1, &tex[19].prop.texture);    glGenTextures(1, &tex[20].prop.texture);    glGenTextures(1, &tex[21].prop.texture);    glGenTextures(1, &tex[22].prop.texture);    glGenTextures(1, &tex[23].prop.texture);    glGenTextures(1, &tex[24].prop.texture);    glGenTextures(1, &tex[25].prop.texture);    glGenTextures(1, &tex[26].prop.texture);    glGenTextures(1, &tex[27].prop.texture);    glGenTextures(1, &tex[28].prop.texture);    glGenTextures(1, &tex[29].prop.texture);    glGenTextures(1, &tex[30].prop.texture);    glGenTextures(1, &tex[31].prop.texture);    glGenTextures(1, &tex[32].prop.texture);    texMgr.load("data/gfx/menu/highscorebg.png", tex[33]);          writeTxt(fonts[0],txtColorBlack,"Exit Game", tex[4].prop.texture,1); //0    writeTxt(fonts[0],txtColorBlack,"Settings",  tex[5].prop.texture,1);    writeTxt(fonts[0],txtColorBlack,"Highscores",tex[6].prop.texture,1);    writeTxt(fonts[0],txtColorBlack,"Save Game", tex[7].prop.texture,1);    writeTxt(fonts[0],txtColorBlack,"Load Game", tex[8].prop.texture,1);    writeTxt(fonts[0],txtColorBlack,"Continue",  tex[9].prop.texture,1);    writeTxt(fonts[0],txtColorBlack,"New Game",  tex[10].prop.texture,1);      writeTxt(fonts[0],txtColorRed,  "Exit Game?",tex[11].prop.texture,1); //7     writeTxt(fonts[0],txtColorBlack,"Yes",    tex[12].prop.texture,1);    writeTxt(fonts[0],txtColorBlack,"No",     tex[13].prop.texture,1);        writeTxt(fonts[0],txtColorWhite,"Settings", tex[14].prop.texture,1); //10    writeTxt(fonts[0],txtColorBlack,"Video Settings",tex[15].prop.texture,1);    writeTxt(fonts[0],txtColorBlack,"Sound Settings",tex[16].prop.texture,1);      writeTxt(fonts[0],txtColorWhite,"Video Settings",tex[17].prop.texture,1);    writeTxt(fonts[0],txtColorBlack,"Fullscreen On/Off",tex[18].prop.texture,1); //14        writeTxt(fonts[0],txtColorBlack,"Eyecandy On/Off",tex[19].prop.texture,1);    writeTxt(fonts[0],txtColorBlack,"1600x1200", tex[20].prop.texture,1);    writeTxt(fonts[0],txtColorBlack,"1024x768", tex[21].prop.texture,1); //18    writeTxt(fonts[0],txtColorBlack,"Background On/Off", tex[22].prop.texture,1); //18          writeTxt(fonts[0],txtColorWhite,"Sound Settings", tex[23].prop.texture,1); //19    writeTxt(fonts[0],txtColorBlack,"Sound On", tex[24].prop.texture,1);    writeTxt(fonts[0],txtColorBlack,"Sound Off", tex[25].prop.texture,1);        writeTxt(fonts[0],txtColorWhite,"New Game", tex[28].prop.texture,1);    writeTxt(fonts[0],txtColorGreen,"Easy", tex[29].prop.texture,1);    writeTxt(fonts[0],txtColorBlue, "Normal", tex[30].prop.texture,1);        writeTxt(fonts[0],txtColorBlack,"Back", tex[32].prop.texture,1); //28      //Baggrund    glNewList(dl, GL_COMPILE);      glEnable(GL_TEXTURE_2D);      glBindTexture(GL_TEXTURE_2D, tex[0].prop.texture);      glBegin( GL_QUADS );        glTexCoord2f(0.0f,0.0f);glVertex3f( -1.0, 1.0, 0.0 );        glTexCoord2f(1.0f,0.0f);glVertex3f(  1.0, 1.0, 0.0 );        glTexCoord2f(1.0f,1.0f);glVertex3f(  1.0,-1.0, 0.0 );        glTexCoord2f(0.0f,1.0f);glVertex3f( -1.0,-1.0, 0.0 );      glEnd( );      glDisable(GL_TEXTURE_2D);    glEndList( );        //Hvide    glNewList(dl+1, GL_COMPILE);      glEnable(GL_TEXTURE_2D);      glBindTexture(GL_TEXTURE_2D, tex[1].prop.texture);      glBegin( GL_QUADS );        glTexCoord2f(0.132f,0.3f); glVertex3f(  -0.5, 0.07, 0.0 );        glTexCoord2f(0.87f, 0.3f); glVertex3f(   0.5, 0.07, 0.0 );        glTexCoord2f(0.87f, 0.7f); glVertex3f(   0.5,-0.07, 0.0 );        glTexCoord2f(0.132f,0.7f); glVertex3f(  -0.5,-0.07, 0.0 );      glEnd( );    glEndList( );        //Røde    glNewList(dl+2, GL_COMPILE);      glEnable(GL_TEXTURE_2D);      glBindTexture(GL_TEXTURE_2D, tex[2].prop.texture);      glBegin( GL_QUADS );        glTexCoord2f(0.132f,0.3f); glVertex3f(  -0.5, 0.07, 0.0 );        glTexCoord2f(0.87f, 0.3f); glVertex3f(   0.5, 0.07, 0.0 );        glTexCoord2f(0.87f, 0.7f); glVertex3f(   0.5,-0.07, 0.0 );        glTexCoord2f(0.132f,0.7f); glVertex3f(  -0.5,-0.07, 0.0 );      glEnd( );    glEndList( );      glNewList(dl+3, GL_COMPILE);      glEnable(GL_TEXTURE_2D);      glBegin( GL_QUADS );        glTexCoord2f(0.0f,-0.02f); glVertex3f(  -0.5, 0.07, 0.0 );        glTexCoord2f(1.0f,-0.02f); glVertex3f(   0.5, 0.07, 0.0 );        glTexCoord2f(1.0f,0.13f); glVertex3f(   0.5,-0.07, 0.0 );        glTexCoord2f(0.0f,0.13f); glVertex3f(  -0.5,-0.07, 0.0 );      glEnd( );      glDisable(GL_TEXTURE_2D);    glEndList( );      //Grøn    glNewList(dl+4, GL_COMPILE);      glEnable(GL_TEXTURE_2D);      glBindTexture(GL_TEXTURE_2D, tex[3].prop.texture);      glBegin( GL_QUADS );        glTexCoord2f(0.132f,0.3f); glVertex3f(  -0.5, 0.07, 0.0 );        glTexCoord2f(0.87f, 0.3f); glVertex3f(   0.5, 0.07, 0.0 );        glTexCoord2f(0.87f, 0.7f); glVertex3f(   0.5,-0.07, 0.0 );        glTexCoord2f(0.132f,0.7f); glVertex3f(  -0.5,-0.07, 0.0 );      glEnd( );    glEndList( );  }    void genHsTex()  {    ifstream hsList;    SDL_Color color = { 255,255,255 };    string line;    char txt[128];    int i=0,t;    struct score *final, *temp;        final = new struct score[1];        hsList.open("data/highscores.txt");        if(hsList.is_open())    {      while(!hsList.eof())      {        getline(hsList,line);        if(line != "")        {                              final[i].score = atoi(line.substr(0, line.find('|')).data());          final[i].name = line.substr(line.find('|')+1);                  temp = new struct score[i+1];          temp = final;                  final = new struct score[i+2];                    for(t = 0; t < i+1; t++)          {            final[t] = temp[t];          }          i++;        }      }      hsList.close();      delete[] temp;                  //Beware! Idiotic sorting method below, DO NOT LEARN HOW TO DO THIS!! IT IS WRONG AND SHOULD BE PUNISHED HARD (goes drinking again..)      int k;      bool done=0;      bool swaps=0;      struct score temp;      while(!done)      {        for(k=0; k < i; k++)        {          for(t=0; t < i; t++)          {            if(final[k].score > final[t].score)            {              swaps=1;              temp = final[t];              final[t] = final[k];              final[k] = temp;            } else {              swaps=0;            }          }        }        if(swaps == 0)        {          done=1;        }      }      //End of idiotic sorting method.           for(t=0; t < 20; t++)     {        sprintf(txt, "%i - %s", final[t].score, final[t].name.data());        writeTxt(fonts[3], color, txt, texHighScore[t],0);     }    } // if is open    /* */    }  void doMenu()  {      int i=0;    glColor4f(1.0, 1.0, 1.0, 1.0);    glLoadIdentity();    glTranslatef(0.0,0.0,-3.0f);    glCallList(dl); //baggrunden      glTranslatef(0.0,-1.0,0.0f);    if(var.menu==1)    {            for(i=0; i < 6; i++)      {        glTranslatef(0.0,0.22,0.0f);        if(var.menuItem-1==i)        {          glCallList(dl+2);        }        else        {          glCallList(dl+1);        }                glBindTexture(GL_TEXTURE_2D, tex[i+4].prop.texture);        glCallList(dl+3);              }        //new game for sigselv      glTranslatef(0.0,0.22,0.0f);      if(var.menuItem==7)        glCallList(dl+2);      else        glCallList(dl+4);              glBindTexture(GL_TEXTURE_2D, tex[10].prop.texture);      glCallList(dl+3);          if(var.menuPressed)      {        switch(var.menuItem)        {          case 1: //quit            var.menu=6;            break;          case 2: //settings            var.menu=2;            break;          case 3: //highscores            var.menu=7;            break;          case 6: //resume            resumeGame();            break;          case 7: //new game            var.menu=5;        }        var.menuPressed=0;      }    var.menuNumItems=7;    } else if(var.menu==2)    {      //Settings            //Back      glTranslatef(0.0,0.22,0.0f);      if(var.menuItem==1)        glCallList(dl+2);      else        glCallList(dl+1);              glBindTexture(GL_TEXTURE_2D, tex[32].prop.texture);      glCallList(dl+3);        //settings      glLoadIdentity();      glTranslatef(0.0, 0.54,-3.0f);            glCallList(dl+4);            glBindTexture(GL_TEXTURE_2D, tex[14].prop.texture);      glCallList(dl+3);            //Video      glTranslatef(0.0,-0.22,0.0f);      if(var.menuItem==6)        glCallList(dl+2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -