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.
26 void createSceneList()
28 char sceneLine[1024] = "";
31 Cutscene *scene = NULL;
35 line = strtok(NULL, "\n");
39 if (strcmp(sceneLine, "@EOF@") == 0)
45 if (strcmp(line, "END") == 0)
48 if (strcmp(line, "NEW") == 0)
50 scene = new Cutscene();
53 // Assume graphics is first line after new
54 line = strtok(NULL, "\n");
55 if (strcmp(line, "@none@") != 0)
57 strlcpy(scene->sprite, line, sizeof scene->sprite);
58 debug(("Loading cutscene image %s\n", scene->sprite));
59 graphics.quickSprite(scene->sprite, graphics.loadImage(scene->sprite));
61 line = strtok(NULL, "\n");
62 sscanf(line, "%d", &waitTime);
63 scene->waitTime = (waitTime * 100);
64 line = strtok(NULL, "\n");
67 if (scene && strcmp(line, "@none@") != 0)
69 scene->appendText(line);
74 bool setupScene(const char *stagename)
80 if (!engine.loadData(_("data/ending")))
81 return graphics.showErrorAndExit("Couldn't load cutscene data file (%s)", _("data/ending")), false;
83 char *line = strtok((char*)engine.dataBuffer, "\n");
86 graphics.clearChatString();
94 sscanf(line, "%*c %[^]]", sceneLine);
95 if (strcmp(sceneLine, stagename) == 0)
103 line = strtok(NULL, "\n");
125 void showScene(bool allowSkip)
127 graphics.setFontSize(0);
128 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
130 SDL_FillRect(graphics.screen, NULL, graphics.black);
133 Cutscene *scene = (Cutscene*)sceneList.getHead();
135 SDL_Surface *panel = graphics.quickSprite("panel", graphics.createSurface(640, 90));
136 SDL_Surface *image = NULL;
137 SDL_FillRect(panel, NULL, graphics.black);
139 float panelAlpha = 0;
141 SDL_SetAlpha(panel, 0);
146 float changeTime = 100;
148 engine.resetTimeDifference();
150 audio.playMusicOnce();
154 graphics.updateScreen();
158 engine.doTimeDifference();
160 if ((engine.userAccepts()) && (allowSkip))
167 if (panelAlpha < 256)
169 panelAlpha += (1 * engine.getTimeDifference());
170 SDL_SetAlpha(panel, panelAlpha);
173 SDL_SetAlpha(image, panelAlpha);
174 graphics.blit(image, 0, 0, graphics.screen, false);
176 graphics.blit(panel, 0, 390, graphics.screen, false);
179 changeTime -= (1 * engine.getTimeDifference());
183 if (scene->next != NULL)
185 scene = (Cutscene*)scene->next;
187 changeTime = scene->waitTime;
188 graphics.clearChatString();
189 graphics.createChatString(scene->text);
190 SDL_FillRect(panel, NULL, graphics.black);
191 graphics.drawChatString(panel, 0);
194 if (strcmp(scene->sprite, "") != 0)
196 debug(("Getting cutscene %s\n", scene->sprite));
197 image = graphics.getSprite(scene->sprite, true)->image[0];
198 SDL_SetColorKey(image, 0, SDL_MapRGB(image->format, 0, 0, 0));
210 SDL_FillRect(graphics.screen, NULL, graphics.black);
214 void checkStartCutscene()
216 // Easy mode doesn't have cutscenes!
222 char sceneName[1024];
223 snprintf(sceneName, sizeof sceneName, "%s Start", game.stageName);
225 if (setupScene(sceneName))
227 audio.loadMusic("music/cutscene");
235 void checkEndCutscene()
237 // Easy mode doesn't have cutscenes!
244 char sceneName[1024];
245 snprintf(sceneName, sizeof sceneName, "%s End", game.stageName);
247 debug(("%s\n", sceneName));
249 bool allowSkip = true;
251 // Don't let the player skip the end of game cutscene...
252 // So we get the music timed well! :)
253 if (strcmp(game.stageName, "Final Battle") == 0)
258 if (setupScene(sceneName))
260 if (strcmp(game.stageName, "Final Battle") != 0)
262 audio.loadMusic("music/cutscene");
266 audio.loadMusic("music/end");
269 showScene(allowSkip);
276 void easyGameFinished()
281 audio.loadMusic("music/gameover");
282 setupScene("Easy Game Finished");
285 graphics.delay(3500);