📄 title.cpp
字号:
{menuType = 1; selectedOption = 1;} else if (selectedOption == 4) {menuType = 2; selectedOption = 1;} else if (selectedOption == 5) { if (engine.cheat) {menuType = 3; selectedOption = 1;} else engine.done = 1; } else if (selectedOption == 6) engine.done = 1; break; case 1: if (selectedOption != listLength) {engine.done = 1; continueSaveSlot = selectedOption; selectedOption = 3;} else {menuType = 0; selectedOption = 1;} break; case 2: if ((selectedOption == 1) && (engine.useAudio)) currentGame.useSound = 1 - currentGame.useSound; else if ((selectedOption == 2) && (engine.useAudio)) { currentGame.useMusic = 1 - currentGame.useMusic; if (currentGame.useMusic) { if (Mix_PausedMusic() == 1) Mix_ResumeMusic(); else Mix_PlayMusic(engine.music, 1); } else { Mix_PauseMusic(); } } else if (selectedOption == 3) { currentGame.fullScreen = 1 - currentGame.fullScreen; #if LINUX SDL_WM_ToggleFullScreen(graphics.screen); #else if (currentGame.fullScreen) graphics.screen = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN); else graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_HWSURFACE|SDL_HWPALETTE); graphics.drawBackground(); flushBuffer(); #endif } else if (selectedOption == 4) Math::wrapChar(&(++currentGame.autoSaveSlot), -1, 4); else if (selectedOption == listLength) {menuType = 0; selectedOption = 1;} createOptionsMenu(); break; case 3: if (selectedOption == 1) engine.cheatShield = 1 - engine.cheatShield; else if (selectedOption == 2) engine.cheatAmmo = 1 - engine.cheatAmmo; else if (selectedOption == 3) engine.cheatCash = 1 - engine.cheatCash; else if (selectedOption == 4) engine.cheatTime = 1 - engine.cheatTime; else if (selectedOption == listLength) {menuType = 0; selectedOption = 1;} createCheatMenu(); break; case 4: if (selectedOption == listLength) {menuType = 0; selectedOption = 1;} break; } } engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0; } while (SDL_GetTicks() < (frameLimit + 16)){} frameLimit = SDL_GetTicks(); } Mix_HaltMusic(); SDL_FreeSurface(prlogo); SDL_FreeSurface(sflogo); engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0; resetLists(); if (selectedOption == 1) selectedOption = 2; // go straight to mission 0 if (selectedOption == 3) { newGame(); selectedOption = loadGame(continueSaveSlot); } // Send back a negative number... if (selectedOption > 4) { selectedOption = -1; exit(0); } return selectedOption;}/*Scrolls the intro text up the screen and nothing else. The text will be placedinto a data file when the game is finished.*/void showStory(){ graphics.freeGraphics(); int y = 620; FILE *fp; #if USEPACK int dataLocation = locateDataInPak("data/intro.txt", 1); fp = fopen(PACKLOCATION, "rb"); fseek(fp, dataLocation, SEEK_SET); #else fp = fopen("data/intro.txt", "rb"); #endif int i = 0; int nextPos = -1; char string[255]; fscanf(fp, "%d ", &nextPos); while (nextPos != -1) { fscanf(fp, "%[^\n]%*c", string); y += nextPos; graphics.textSurface(i, string, -1, y, FONT_WHITE); i++; fscanf(fp, "%d ", &nextPos); } fclose(fp); loadBackground("gfx/startUp.jpg"); graphics.blit(graphics.background, 0, 0); graphics.flushBuffer(); unsigned long frameLimit = SDL_GetTicks(); flushInput(); engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0; while (true) { graphics.updateScreen(); graphics.unBuffer(); getPlayerInput(); if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]) || (engine.keyState[SDLK_SPACE])) break; if (graphics.textShape[8].y > 450) { for (int i = 0 ; i < 9 ; i++) { graphics.textShape[i].y -= 0.25; graphics.blitText(i); } } else { SDL_Delay(3000); break; } while (SDL_GetTicks() < (frameLimit + 16)){} frameLimit = SDL_GetTicks(); }}/*The game over screen :(*/void gameover(){ graphics.flushBuffer(); graphics.freeGraphics(); SDL_FillRect(graphics.background, NULL, graphics.black); engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0; engine.gameSection = SECTION_INTERMISSION; loadMusic("music/Wybierak.mod"); SDL_Surface *gameover = loadImage("gfx/gameover.png"); graphics.clearScreen(graphics.black); graphics.updateScreen(); graphics.clearScreen(graphics.black); SDL_Delay(1000); if ((currentGame.useMusic) && (engine.useAudio)) { Mix_VolumeMusic(100); Mix_PlayMusic(engine.music, 1); } int x = (800 - gameover->w) / 2; int y = (600 - gameover->h) / 2; unsigned long frameLimit = SDL_GetTicks(); graphics.updateScreen(); flushInput(); engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = engine.keyState[SDLK_SPACE] = 0; while (true) { getPlayerInput(); if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]) || (engine.keyState[SDLK_SPACE])) break; graphics.updateScreen(); graphics.unBuffer(); x = ((800 - gameover->w) / 2) - Math::rrand(-2, 2); y = ((600 - gameover->h) / 2) - Math::rrand(-2, 2); graphics.blit(gameover, x, y); // Limit us to 60 frame a second while (SDL_GetTicks() < (frameLimit + 16)){} frameLimit = SDL_GetTicks(); } SDL_FreeSurface(gameover); if ((currentGame.useMusic) && (engine.useAudio)) Mix_HaltMusic(); graphics.flushBuffer();}void doCredits(){ loadBackground("gfx/credits.jpg"); graphics.flushBuffer(); graphics.freeGraphics(); if ((currentGame.useMusic) && (engine.useAudio)) loadMusic("music/Solace.s3m"); FILE *fp; int numberOfCredits = 0; int lastCredit = 0; int yPos = 0; int yPos2 = 510; char text[255]; textObject *credit; graphics.clearScreen(graphics.black); graphics.updateScreen(); graphics.clearScreen(graphics.black); SDL_Delay(1000); graphics.drawBackGround(); #if USEPACK int dataLocation = locateDataInPak("data/credits.txt", 1); fp = fopen(PACKLOCATION, "rb"); fseek(fp, dataLocation, SEEK_SET); #else fp = fopen("data/credits.txt", "rb"); #endif for (int i = 0 ; i < 6 ; i++) { fscanf(fp, "%[^\n]%*c", text); graphics.drawString(text, -1, 240 + (i * 20), FONT_WHITE); } fscanf(fp, "%d%*c", &numberOfCredits); credit = (textObject*) malloc(sizeof(textObject) * numberOfCredits); for (int i = 0 ; i < numberOfCredits ; i++) { fscanf(fp, "%d %[^\n]%*c", &yPos, text); credit[i].image = graphics.textSurface(text, FONT_WHITE); credit[i].x = (800 - credit[i].image->w) / 2; yPos2 += yPos; credit[i].y = yPos2; } fclose(fp); if ((currentGame.useMusic) && (engine.useAudio)) { Mix_VolumeMusic(100); Mix_PlayMusic(engine.music, 1); } SDL_Delay(3000); graphics.updateScreen(); SDL_Delay(10000); graphics.drawBackGround(); unsigned long frameLimit = SDL_GetTicks(); engine.done = 0; lastCredit = numberOfCredits - 1; SDL_Rect r1 = {0, 80, 800, 20}; SDL_Rect r2 = {0, 500, 800, 20}; engine.keyState[SDLK_ESCAPE] = 0; flushInput(); while (true) { graphics.updateScreen(); graphics.unBuffer(); getPlayerInput(); if (engine.keyState[SDLK_ESCAPE]) break; for (int i = 0 ; i < numberOfCredits ; i++) { if ((credit[i].y > 80) && (credit[i].y < 500)) graphics.blit(credit[i].image, (int)credit[i].x, (int)credit[i].y); if (credit[lastCredit].y > 400) credit[i].y -= 0.3; } SDL_FillRect(graphics.screen, &r1, graphics.black); SDL_FillRect(graphics.screen, &r2, graphics.black); while (SDL_GetTicks() < (frameLimit + 16)){} frameLimit = SDL_GetTicks(); } for (int i = 0 ; i < numberOfCredits ; i++) { SDL_FreeSurface(credit[i].image); } free(credit);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -