Guest User

Untitled

a guest
Jul 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.47 KB | None | 0 0
  1. #include "SDL.h"
  2. #include "SDL_ttf.h"
  3.  
  4. void ApplySurface (int, int, SDL_Surface *, SDL_Surface *);
  5.  
  6. int main (int argc, char ** args) {
  7.  
  8.     /* initialize */
  9.     SDL_Init (SDL_INIT_EVERYTHING);
  10.     TTF_Init ();
  11.  
  12.     /* create the window */
  13.     SDL_Surface * pScreen = SDL_SetVideoMode (1000, 500, 32, SDL_SWSURFACE);
  14.     SDL_WM_SetCaption ("CurlyBraceProduction's ", NULL);
  15.  
  16.     /* regulate frames per second stuff */
  17.     const int ciFPS = 30;
  18.     Uint32 uiStart = 0;
  19.  
  20.     /* game state bools */
  21.     bool bInMainMenu = 1;
  22.     bool bSinglePlayer = 0;
  23.     bool bMultiplayer = 0;
  24.     bool bInOptionsMenu = 0;
  25.     bool bReadingInformation = 0;
  26.  
  27.     /* main menu stuff */
  28.     int iMenuCounter = 0;
  29.     TTF_Font * Font = TTF_OpenFont ("font.ttf", 30);
  30.     SDL_Color Color = {0, 0, 0};
  31.     SDL_Surface * pText = NULL;
  32.  
  33.     /* game loop stuff */
  34.     bool bRunning = 1;
  35.     SDL_Event Event;
  36.  
  37.     /* game loop */
  38.     while (bRunning)
  39.     {
  40.  
  41.         /* get the current ticks */
  42.         uiStart = SDL_GetTicks ();
  43.  
  44.         /* set the background of the window to white */
  45.         SDL_FillRect (pScreen, &pScreen->clip_rect, SDL_MapRGB (pScreen->format, 255, 255, 255));
  46.  
  47.         while (SDL_PollEvent (&Event))
  48.         {
  49.  
  50.             switch (Event.type)
  51.             {
  52.  
  53.                 case SDL_QUIT: /* quit the program */
  54.                     bRunning = 0;
  55.                     break;
  56.  
  57.                 case SDL_KEYUP: /* a key was released */
  58.                     switch (Event.key.keysym.sym)
  59.                     {
  60.                         case SDLK_UP:
  61.                             if (bInMainMenu && iMenuCounter > 0)
  62.                             {
  63.                                 --iMenuCounter;
  64.                             }
  65.                             break;
  66.  
  67.                         case SDLK_DOWN:
  68.                             if (bInMainMenu && iMenuCounter < 4)
  69.                             {
  70.                                 ++iMenuCounter;
  71.                             }
  72.                             break;
  73.  
  74.                         case SDLK_RETURN:
  75.                             if (bInMainMenu)
  76.                             {
  77.                                 switch (iMenuCounter)
  78.                                 {
  79.                                     case 0:
  80.                                         break;
  81.  
  82.                                     case 1:
  83.                                         break;
  84.  
  85.                                     case 2:
  86.                                         break;
  87.  
  88.                                     case 3:
  89.                                         break;
  90.  
  91.                                     case 4:
  92.                                         bRunning = 0;
  93.                                         break;
  94.                                 }
  95.                                 iMenuCounter = 0;
  96.                             }
  97.                             break;
  98.                     }
  99.                     break;
  100.  
  101.             }
  102.  
  103.         }
  104.  
  105.         /* game state handling */
  106.         if (bInMainMenu)
  107.         {
  108.  
  109.             char * cpaText [] = {"Single Player", "Multiplayer", "Options", "Information", "Exit"};
  110.  
  111.             for (int iLoopCounter = 0, iY = 150; iLoopCounter < 5; ++iLoopCounter, iY += 35)
  112.             {
  113.  
  114.                 Color.r = 0;
  115.  
  116.                 if (iLoopCounter == iMenuCounter)
  117.                 {
  118.                     Color.r = 255;
  119.                 }
  120.  
  121.                 pText = TTF_RenderText_Solid (Font, cpaText [iLoopCounter], Color);
  122.                 ApplySurface (pScreen->clip_rect.w / 2 - pText->clip_rect.w / 2, iY, pText, pScreen);
  123.  
  124.             }
  125.  
  126.         }
  127.  
  128.         else if (bSinglePlayer)
  129.         {
  130.  
  131.  
  132.  
  133.         }
  134.  
  135.         else if (bMultiplayer)
  136.         {
  137.  
  138.  
  139.  
  140.         }
  141.  
  142.         else if (bInOptionsMenu)
  143.         {
  144.  
  145.  
  146.  
  147.         }
  148.  
  149.         else if (bReadingInformation)
  150.         {
  151.  
  152.  
  153.  
  154.         }
  155.  
  156.         /* display the screen */
  157.         SDL_Flip (pScreen);
  158.  
  159.         /* regulate the frames per second */
  160.         if (1000 / ciFPS > SDL_GetTicks () - uiStart)
  161.         {
  162.             SDL_Delay (1000 / ciFPS - (SDL_GetTicks () - uiStart));
  163.         }
  164.  
  165.     }
  166.  
  167.     /* shut down and clean up */
  168.     TTF_CloseFont (Font);
  169.     TTF_Quit ();
  170.     SDL_FreeSurface (pText);
  171.     SDL_Quit ();
  172. }
  173.  
  174. void ApplySurface (int iX, int iY, SDL_Surface * pSource, SDL_Surface * pDestination)
  175. {
  176.     SDL_Rect Rect;
  177.     Rect.x = iX;
  178.     Rect.y = iY;
  179.     SDL_BlitSurface (pSource, NULL, pDestination, &Rect);
  180. }
Add Comment
Please, Sign In to add comment