2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 void createSceneList()
26 char sceneLine[1024] = "";
29 Cutscene *scene = NULL;
33 line = strtok(NULL, "\n");
37 if (strcmp(sceneLine, "@EOF@") == 0)
43 if (strcmp(line, "END") == 0)
46 if (strcmp(line, "NEW") == 0)
48 scene = new Cutscene();
51 // Assume graphics is first line after new
52 line = strtok(NULL, "\n");
53 if (strcmp(line, "@none@") != 0)
55 strlcpy(scene->sprite, line, sizeof scene->sprite);
56 debug(("Loading cutscene image %s\n", scene->sprite));
57 graphics.quickSprite(scene->sprite, graphics.loadImage(scene->sprite));
59 line = strtok(NULL, "\n");
60 sscanf(line, "%d", &waitTime);
61 scene->waitTime = (waitTime * 100);
62 line = strtok(NULL, "\n");
65 if (strcmp(line, "@none@") != 0)
67 scene->appendText(line);
72 bool setupScene(const char *stagename)
78 if (!engine.loadData(_("data/ending")))
79 graphics.showErrorAndExit("Couldn't load cutscene data file (%s)", _("data/ending"));
81 char *line = strtok((char*)engine.dataBuffer, "\n");
84 graphics.clearChatString();
92 sscanf(line, "%*c %[^]]", sceneLine);
93 if (strcmp(sceneLine, stagename) == 0)
101 line = strtok(NULL, "\n");
123 void showScene(bool allowSkip)
125 graphics.setFontSize(0);
126 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
128 SDL_FillRect(graphics.screen, NULL, graphics.black);
131 Cutscene *scene = (Cutscene*)sceneList.getHead();
133 SDL_Surface *panel = graphics.quickSprite("panel", graphics.createSurface(640, 90));
134 SDL_Surface *image = NULL;
135 SDL_FillRect(panel, NULL, graphics.black);
137 float panelAlpha = 0;
139 SDL_SetAlpha(panel, 0);
144 float changeTime = 100;
146 engine.resetTimeDifference();
148 audio.playMusicOnce();
152 graphics.updateScreen();
156 engine.doTimeDifference();
158 if ((engine.userAccepts()) && (allowSkip))
165 if (panelAlpha < 256)
167 panelAlpha += (1 * engine.getTimeDifference());
168 SDL_SetAlpha(panel, panelAlpha);
171 SDL_SetAlpha(image, panelAlpha);
172 graphics.blit(image, 0, 0, graphics.screen, false);
174 graphics.blit(panel, 0, 390, graphics.screen, false);
177 changeTime -= (1 * engine.getTimeDifference());
181 if (scene->next != NULL)
183 scene = (Cutscene*)scene->next;
185 changeTime = scene->waitTime;
186 graphics.clearChatString();
187 graphics.createChatString(scene->text);
188 SDL_FillRect(panel, NULL, graphics.black);
189 graphics.drawChatString(panel, 0);
192 if (strcmp(scene->sprite, "") != 0)
194 debug(("Getting cutscene %s\n", scene->sprite));
195 image = graphics.getSprite(scene->sprite, true)->image[0];
196 SDL_SetColorKey(image, 0, SDL_MapRGB(image->format, 0, 0, 0));
208 SDL_FillRect(graphics.screen, NULL, graphics.black);
212 void checkStartCutscene()
214 // Easy mode doesn't have cutscenes!
220 char sceneName[1024];
221 snprintf(sceneName, sizeof sceneName, "%s Start", game.stageName);
223 if (setupScene(sceneName))
225 audio.loadMusic("music/cutscene");
233 void checkEndCutscene()
235 // Easy mode doesn't have cutscenes!
242 char sceneName[1024];
243 snprintf(sceneName, sizeof sceneName, "%s End", game.stageName);
245 debug(("%s\n", sceneName));
247 bool allowSkip = true;
249 // Don't let the player skip the end of game cutscene...
250 // So we get the music timed well! :)
251 if (strcmp(game.stageName, "Final Battle") == 0)
256 if (setupScene(sceneName))
258 if (strcmp(game.stageName, "Final Battle") != 0)
260 audio.loadMusic("music/cutscene");
264 audio.loadMusic("music/end");
267 showScene(allowSkip);
274 void easyGameFinished()
279 audio.loadMusic("music/gameover");
280 setupScene("Easy Game Finished");
283 graphics.delay(3500);