Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SDL.h"
- #include "SDL_ttf.h"
- void ApplySurface (int, int, SDL_Surface *, SDL_Surface *);
- int main (int argc, char ** args) {
- /* initialize */
- SDL_Init (SDL_INIT_EVERYTHING);
- TTF_Init ();
- /* create the window */
- SDL_Surface * pScreen = SDL_SetVideoMode (1000, 500, 32, SDL_SWSURFACE);
- SDL_WM_SetCaption ("CurlyBraceProduction's ", NULL);
- /* regulate frames per second stuff */
- const int ciFPS = 30;
- Uint32 uiStart = 0;
- /* game state bools */
- bool bInMainMenu = 1;
- bool bSinglePlayer = 0;
- bool bMultiplayer = 0;
- bool bInOptionsMenu = 0;
- bool bReadingInformation = 0;
- /* main menu stuff */
- int iMenuCounter = 0;
- TTF_Font * Font = TTF_OpenFont ("font.ttf", 30);
- SDL_Color Color = {0, 0, 0};
- SDL_Surface * pText = NULL;
- /* game loop stuff */
- bool bRunning = 1;
- SDL_Event Event;
- /* game loop */
- while (bRunning)
- {
- /* get the current ticks */
- uiStart = SDL_GetTicks ();
- /* set the background of the window to white */
- SDL_FillRect (pScreen, &pScreen->clip_rect, SDL_MapRGB (pScreen->format, 255, 255, 255));
- while (SDL_PollEvent (&Event))
- {
- switch (Event.type)
- {
- case SDL_QUIT: /* quit the program */
- bRunning = 0;
- break;
- case SDL_KEYUP: /* a key was released */
- switch (Event.key.keysym.sym)
- {
- case SDLK_UP:
- if (bInMainMenu && iMenuCounter > 0)
- {
- --iMenuCounter;
- }
- break;
- case SDLK_DOWN:
- if (bInMainMenu && iMenuCounter < 4)
- {
- ++iMenuCounter;
- }
- break;
- case SDLK_RETURN:
- if (bInMainMenu)
- {
- switch (iMenuCounter)
- {
- case 0:
- break;
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- bRunning = 0;
- break;
- }
- iMenuCounter = 0;
- }
- break;
- }
- break;
- }
- }
- /* game state handling */
- if (bInMainMenu)
- {
- char * cpaText [] = {"Single Player", "Multiplayer", "Options", "Information", "Exit"};
- for (int iLoopCounter = 0, iY = 150; iLoopCounter < 5; ++iLoopCounter, iY += 35)
- {
- Color.r = 0;
- if (iLoopCounter == iMenuCounter)
- {
- Color.r = 255;
- }
- pText = TTF_RenderText_Solid (Font, cpaText [iLoopCounter], Color);
- ApplySurface (pScreen->clip_rect.w / 2 - pText->clip_rect.w / 2, iY, pText, pScreen);
- }
- }
- else if (bSinglePlayer)
- {
- }
- else if (bMultiplayer)
- {
- }
- else if (bInOptionsMenu)
- {
- }
- else if (bReadingInformation)
- {
- }
- /* display the screen */
- SDL_Flip (pScreen);
- /* regulate the frames per second */
- if (1000 / ciFPS > SDL_GetTicks () - uiStart)
- {
- SDL_Delay (1000 / ciFPS - (SDL_GetTicks () - uiStart));
- }
- }
- /* shut down and clean up */
- TTF_CloseFont (Font);
- TTF_Quit ();
- SDL_FreeSurface (pText);
- SDL_Quit ();
- }
- void ApplySurface (int iX, int iY, SDL_Surface * pSource, SDL_Surface * pDestination)
- {
- SDL_Rect Rect;
- Rect.x = iX;
- Rect.y = iY;
- SDL_BlitSurface (pSource, NULL, pDestination, &Rect);
- }
Add Comment
Please, Sign In to add comment