Removed that logo from this bramch aswell..
[dbw.git] / src / intro.cpp
bloba42bda82de6a95e7e6313de247d354bd4c7e703b
1 /*
2 Copyright © 2004 Parallel Realities
3 Copyright © 2007-2008 Kővágó Zoltán <DirtY.iCE.hu@gmail.com>
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 "CAudio.h"
23 #include "CGame.h"
24 #include "CEntity.h"
25 #include "CGraphics.h"
26 #include "CMap.h"
27 #include "CSpawnPoint.h"
28 #include "gettext.hpp"
29 #include "intro.h"
31 void playIntro(int tx, int ty, int delay)
33 unsigned int frameLimit = SDL_GetTicks() + 16;
34 unsigned int time = 0;
36 graphics.setFontSize(1);
37 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
39 char *line[3];
40 SDL_Surface *text[3];
42 for (int i = 0 ; i < 3 ; i++)
44 line[i] = strtok(NULL, "\n");
46 if (!line[i])
48 graphics.showErrorAndExit(_("Malformed Intro Data"), "");
51 text[i] = NULL;
53 if (strcmp(line[i], "@none@"))
55 text[i] = graphics.getString(_(line[i]), true);
59 player.tx += tx;
60 player.ty += ty;
62 while (true)
64 engine.setPlayerPosition((int)player.x, (int)player.y, map.limitLeft, map.limitRight, map.limitUp, map.limitDown);
66 doGameStuff();
67 doSpawnPoints();
68 drawMapTopLayer();
70 for (int i = 0 ; i < 3 ; i++)
71 if (text[i] != NULL)
72 graphics.blit(text[i], bx + 320, 150 + (i * 30), graphics.screen, true);
74 if (engine.userAccepts())
75 break;
77 if (player.x < player.tx) player.x++;
78 if (player.x > player.tx) player.x--;
80 if ((int)player.x == player.tx)
82 if (time == 0)
84 time = SDL_GetTicks() + (delay * 1000);
88 if (time > 0)
89 if (SDL_GetTicks() > time)
90 break;
92 engine.delay(frameLimit);
93 frameLimit = SDL_GetTicks() + 16;
96 for (int i = 0 ; i < 3 ; i++)
97 if (text[i])
98 SDL_FreeSurface(text[i]);
101 void showIntroError()
103 SDL_FillRect(graphics.screen, NULL, graphics.black);
105 engine.flushInput();
107 graphics.setFontSize(1);
109 graphics.drawString(_("Couldn't play intro - Data file is missing."), 320, 150, true, graphics.screen);
110 graphics.drawString(_("This is not a fatal error, but could mean that the intro"), 320, 180, true, graphics.screen);
111 graphics.drawString(_("file has not been found or was not in the expected format."), 320, 210, true, graphics.screen);
112 graphics.drawString(_("However it may also be a sign that the game may not work correctly."), 320, 240, true, graphics.screen);
113 graphics.drawString(_("Press Escape to Continue"), 320, 350, true, graphics.screen);
115 while (true)
117 graphics.updateScreen();
118 engine.getInput();
119 if (engine.keyState[SDLK_ESCAPE])
120 break;
121 SDL_Delay(16);
125 void parseIntroCommand()
127 char *line;
128 char command[25], param[25];
130 line = strtok(NULL, "\n");
131 sscanf(line, "%s %s", command, param);
133 if (strcmp(command, "SPAWN") == 0)
135 SpawnPoint *sp = (SpawnPoint*)map.spawnList.getHead();
137 while (sp->next != NULL)
139 sp = (SpawnPoint*)sp->next;
141 if (strcmp(param, sp->name) == 0)
143 sp->active = true;
149 int doIntro()
151 int x, y, delay;
153 game.setMapName("data/introMap");
155 loadResources();
157 for (int i = 0 ; i < 4 ; i++)
159 addItem(101, "CherryPlant", rand() % 640, 9050, "CherryPlant", 100, 1, 0, false);
162 if (!engine.loadData("data/introText"))
164 showIntroError();
165 return SECTION_TITLE;
168 player.health = -100;
170 audio.playMusic();
172 char *line = strtok((char*)engine.dataBuffer, "\n");
174 while (true)
176 line = strtok(NULL, "\n");
177 sscanf(line, "%d %d %d", &x, &y, &delay);
179 if (delay == -1)
180 break;
182 parseIntroCommand();
184 playIntro(x, y, delay);
186 if (engine.userAccepts())
187 break;
190 if (!engine.userAccepts())
192 audio.fadeMusic();
193 graphics.fadeToBlack();
196 map.clear();
198 return SECTION_TITLE;