X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fgame.cpp;h=29aafdfbae6255ccee848fe24dc315f71d7d03e7;hb=6671923e966e5fb82eeac52be174fb6295dc9ee7;hp=8fa42b2e05e794d6e959d9fa193da0988e1a4a52;hpb=bcd19efa602b9279399b17e7756b8212df0fa234;p=quix0rs-blobwars.git diff --git a/src/game.cpp b/src/game.cpp index 8fa42b2..29aafdf 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,5 +1,6 @@ /* -Copyright (C) 2004 Parallel Realities +Copyright (C) 2004-2011 Parallel Realities +Copyright (C) 2011-2015 Perpendicular Dimensions This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -34,7 +35,7 @@ void showInGameOptions() { if (!engine.loadWidgets(_("data/inGameWidgets"))) { - graphics.showErrorAndExit(ERR_FILE, _("data/inGameWidgets")); + return graphics.showErrorAndExit(ERR_FILE, _("data/inGameWidgets")); } graphics.drawRect(120, 100, 400, 300, graphics.black, graphics.white, graphics.screen); @@ -99,9 +100,9 @@ void showInGameOptions() engine.getInput(); config.populate(); - if ((config.isControl(CONTROL::PAUSE)) || (engine.keyState[SDLK_ESCAPE])) + if ((config.isControl(CONTROL::PAUSE)) || (engine.keyState[SDL_SCANCODE_ESCAPE])) { - engine.keyState[SDLK_ESCAPE] = 0; + engine.keyState[SDL_SCANCODE_ESCAPE] = 0; config.resetControl(CONTROL::PAUSE); break; } @@ -276,11 +277,6 @@ void doGameStuff() doParticles(); - if ((SDL_GetAppState() & SDL_APPINPUTFOCUS) == 0) - { - engine.paused = true; - } - replayData.set(config.command); replayData.commit(); } @@ -292,10 +288,11 @@ int gameover() if (!engine.loadWidgets(_("data/gameOverWidgets"))) { - graphics.showErrorAndExit(ERR_FILE, _("data/gameOverWidgets")); + return graphics.showErrorAndExit(ERR_FILE, _("data/gameOverWidgets")), SECTION_GAME; } SDL_Surface *gameover = graphics.quickSprite("Game Over", graphics.loadImage("gfx/main/gameover.png")); + graphics.setTransparent(gameover); audio.loadGameOverMusic(); audio.playMusic(); @@ -315,7 +312,9 @@ int gameover() if (game.canContinue > 1) { Widget *widget = engine.getWidgetByName("gameOverNo"); - sprintf(widget->label, "%s (%d)", widget->label, game.canContinue); + char postfix[100]; + snprintf(postfix, sizeof postfix, " (%d)", game.canContinue); + strlcat(widget->label, postfix, sizeof widget->label); } while (true) @@ -383,11 +382,11 @@ void showMissionInformation() SDL_Surface *panel = graphics.createSurface(400, 300); SDL_Surface *panelBack = graphics.alphaRect(400, 300, 0x00, 0x00, 0x00); - SDL_SetColorKey(panel, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(panel->format, 0, 0, 0)); + SDL_SetColorKey(panel, SDL_TRUE, SDL_MapRGB(panel->format, 0, 0, 0)); graphics.drawRect(1, 1, 398, 298, graphics.black, graphics.white, panelBack); - char message[100]; + char message[256]; int col1 = 25; int col2 = 375; int y = 30; @@ -407,13 +406,13 @@ void showMissionInformation() if (map.totalMIAs > 0) { graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00); - sprintf(message, _("Rescue %d MIAs"), map.requiredMIAs); + snprintf(message, sizeof message, _("Rescue %d MIAs"), map.requiredMIAs); graphics.drawString(message, col1, y, TXT_LEFT, panel); if (map.foundMIAs < map.requiredMIAs) { graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00); - sprintf(message, "%d / %d", map.foundMIAs, map.requiredMIAs); + snprintf(message, sizeof message, "%d / %d", map.foundMIAs, map.requiredMIAs); graphics.drawString(message, col2, y, TXT_RIGHT, panel); } else @@ -457,7 +456,7 @@ void showMissionInformation() } else { - sprintf(message, "%d / %d", objective->currentValue, objective->targetValue); + snprintf(message, sizeof message, "%d / %d", objective->currentValue, objective->targetValue); graphics.drawString(message, col2, y, TXT_RIGHT, panel); } } @@ -471,7 +470,7 @@ void showMissionInformation() if (game.skill == 3) { graphics.setFontColor(0xff, 0xff, 0x00, 0x00, 0x00, 0x00); - sprintf(message, _("Time Limit - %d:%.2d Minutes"), map.remainingMinutes, map.remainingSeconds); + snprintf(message, sizeof message, _("Time Limit - %d:%.2d Minutes"), map.remainingMinutes, map.remainingSeconds); graphics.drawString(message, 200, 260, TXT_CENTERED, panel); } @@ -530,7 +529,7 @@ void beamInPlayer() unsigned int frameLimit = SDL_GetTicks() + 16; - audio.playSound(SND_TELEPORT1, CH_ANY); + audio.playSound(SND_TELEPORT1, CH_ANY, player.x); engine.setPlayerPosition((int)player.x, (int)player.y, map.limitLeft, map.limitRight, map.limitUp, map.limitDown); @@ -566,12 +565,13 @@ int doGame() SDL_FillRect(graphics.screen, NULL, graphics.black); graphics.delay(1000); - Uint32 then, frames, frameLimit, millis, frameCounter; + Uint32 frames, frameLimit, millis; + Uint32 start, cur; #if DEBUG - Uint32 now; + Uint32 now, then, frameCounter; char fps[10]; - strcpy(fps, "fps"); + strlcpy(fps, "fps", sizeof fps); #endif engine.messageTime = -1; @@ -614,8 +614,10 @@ int doGame() frameLimit = SDL_GetTicks() + 16; frames = millis = 0; - then = SDL_GetTicks(); - frameCounter = SDL_GetTicks(); + start = SDL_GetTicks(); +#ifdef DEBUG + then = frameCounter = start; +#endif if ((strcmp(map.name, "Space Station") == 0) && (!game.continueFromCheckPoint)) { @@ -639,6 +641,7 @@ int doGame() { ++frames; ++millis; + cur = SDL_GetTicks(); if (game.missionOverReason != MIS_PLAYEROUT) { @@ -680,8 +683,9 @@ int doGame() drawMapTopLayer(); doStatusBar(); + doMusicInfo(cur - start); - if ((engine.keyState[SDLK_ESCAPE]) && (game.missionOver == 0)) + if ((engine.keyState[SDL_SCANCODE_ESCAPE]) && (game.missionOver == 0)) { if (replayData.replayMode == REPLAY_MODE::NONE) { @@ -791,7 +795,9 @@ int doGame() config.populate(); config.doPause(); graphics.updateScreen(); + #ifdef DEBUG then = SDL_GetTicks(); + #endif frames = 0; if (!engine.paused) @@ -802,14 +808,15 @@ int doGame() SDL_Delay(16); } - if ((engine.keyState[SDLK_F3]) && (engine.cheatSkipLevel)) + if ((engine.keyState[SDL_SCANCODE_F3]) && (engine.cheatSkipLevel)) { autoCompleteAllObjectives(true); + engine.keyState[SDL_SCANCODE_F3] = 0; engine.setInfoMessage("Skipping Mission...", 2, INFO_OBJECTIVE); } #if DEBUG - if (engine.keyState[SDLK_F1]) + if (engine.keyState[SDL_SCANCODE_F1]) { autoCompleteAllObjectives(false); } @@ -824,10 +831,10 @@ int doGame() engine.delay(frameLimit); } - if (engine.keyState[SDLK_F5]) + if (engine.keyState[SDL_SCANCODE_F5]) { replayData.fast = !replayData.fast; - engine.keyState[SDLK_F5] = 0; + engine.keyState[SDL_SCANCODE_F5] = 0; } frameLimit = SDL_GetTicks() + 16; @@ -836,12 +843,13 @@ int doGame() frameLimit = SDL_GetTicks() + 64; #if DEBUG - graphics.drawString(fps, 600, 30, true, graphics.screen); + static Graphics::SurfaceCache fpsCache; + graphics.drawString(fps, 600, 30, true, graphics.screen, fpsCache); if (SDL_GetTicks() > frameCounter + 500) { now = SDL_GetTicks(); - sprintf(fps, "%2.2f fps", ((double)frames*1000)/(now - then)); + snprintf(fps, sizeof fps, "%2.2f fps", ((double)frames*1000)/(now - then)); then = frameCounter = SDL_GetTicks(); frames = 0; } @@ -866,7 +874,7 @@ int doGame() if (strcmp(map.name, "Space Station")) { graphics.delay(1000); - audio.loadMusic("music/commando.xm"); + audio.loadMusic("music/grasslands"); audio.playMusic(); graphics.fadeToBlack();