Some Window$ specific edits.
[dbw.git] / src / intro.cpp
blob8f95abe44bd3b6b5ba56d146f7161c3b25f737c4
1 /*
2 Copyright (C) 2004 Parallel Realities
3 Copyright (C) 2007 Kővágó Zoltán
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.
22 #include "intro.h"
23 #include "gettext.hpp"
25 void playIntro(int tx, int ty, int delay)
27 unsigned int frameLimit = SDL_GetTicks() + 16;
28 unsigned int time = 0;
30 graphics.setFontSize(1);
31 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
33 char *line[3];
34 SDL_Surface *text[3];
36 for (int i = 0 ; i < 3 ; i++)
38 line[i] = strtok(NULL, "\n");
40 if (!line[i])
42 graphics.showErrorAndExit(_("Malformed Intro Data"), "");
45 text[i] = NULL;
47 if (strcmp(line[i], "@none@"))
49 text[i] = graphics.getString(_(line[i]), true);
53 player.tx += tx;
54 player.ty += ty;
56 while (true)
58 engine.setPlayerPosition((int)player.x, (int)player.y, map.limitLeft, map.limitRight, map.limitUp, map.limitDown);
60 doGameStuff();
61 doSpawnPoints();
62 drawMapTopLayer();
64 for (int i = 0 ; i < 3 ; i++)
65 if (text[i] != NULL)
66 graphics.blit(text[i], bx + 320, 150 + (i * 30), graphics.screen, true);
68 if (engine.userAccepts())
69 break;
71 if (player.x < player.tx) player.x++;
72 if (player.x > player.tx) player.x--;
74 if ((int)player.x == player.tx)
76 if (time == 0)
78 time = SDL_GetTicks() + (delay * 1000);
82 if (time > 0)
83 if (SDL_GetTicks() > time)
84 break;
86 engine.delay(frameLimit);
87 frameLimit = SDL_GetTicks() + 16;
90 for (int i = 0 ; i < 3 ; i++)
91 if (text[i])
92 SDL_FreeSurface(text[i]);
95 void showIntroError()
97 SDL_FillRect(graphics.screen, NULL, graphics.black);
99 engine.flushInput();
101 graphics.setFontSize(1);
103 graphics.drawString(_("Couldn't play intro - Data file is missing."), 320, 150, true, graphics.screen);
104 graphics.drawString(_("This is not a fatal error, but could mean that the intro"), 320, 180, true, graphics.screen);
105 graphics.drawString(_("file has not been found or was not in the expected format."), 320, 210, true, graphics.screen);
106 graphics.drawString(_("However it may also be a sign that the game may not work correctly."), 320, 240, true, graphics.screen);
107 graphics.drawString(_("Press Escape to Continue"), 320, 350, true, graphics.screen);
109 while (true)
111 graphics.updateScreen();
112 engine.getInput();
113 if (engine.keyState[SDLK_ESCAPE])
114 break;
115 SDL_Delay(16);
119 void parseIntroCommand()
121 char *line;
122 char command[25], param[25];
124 line = strtok(NULL, "\n");
125 sscanf(line, "%s %s", command, param);
127 if (strcmp(command, "SPAWN") == 0)
129 SpawnPoint *sp = (SpawnPoint*)map.spawnList.getHead();
131 while (sp->next != NULL)
133 sp = (SpawnPoint*)sp->next;
135 if (strcmp(param, sp->name) == 0)
137 sp->active = true;
143 int doIntro()
145 int x, y, delay;
147 game.setMapName("data/introMap");
149 loadResources();
151 for (int i = 0 ; i < 4 ; i++)
153 addItem(101, "CherryPlant", rand() % 640, 9050, "CherryPlant", 100, 1, 0, false);
156 if (!engine.loadData("data/introText"))
158 showIntroError();
159 return SECTION_TITLE;
162 player.health = -100;
164 audio.playMusic();
166 char *line = strtok((char*)engine.dataBuffer, "\n");
168 while (true)
170 line = strtok(NULL, "\n");
171 sscanf(line, "%d %d %d", &x, &y, &delay);
173 if (delay == -1)
174 break;
176 parseIntroCommand();
178 playIntro(x, y, delay);
180 if (engine.userAccepts())
181 break;
184 if (!engine.userAccepts())
186 audio.fadeMusic();
187 graphics.fadeToBlack();
190 map.clear();
192 return SECTION_TITLE;