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.
25 #include "CGraphics.h"
27 #include "CSpawnPoint.h"
28 #include "gettext.hpp"
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);
42 for (int i
= 0 ; i
< 3 ; i
++)
44 line
[i
] = strtok(NULL
, "\n");
48 graphics
.showErrorAndExit(_("Malformed Intro Data"), "");
53 if (strcmp(line
[i
], "@none@"))
55 text
[i
] = graphics
.getString(_(line
[i
]), true);
64 engine
.setPlayerPosition((int)player
.x
, (int)player
.y
, map
.limitLeft
, map
.limitRight
, map
.limitUp
, map
.limitDown
);
70 for (int i
= 0 ; i
< 3 ; i
++)
72 graphics
.blit(text
[i
], bx
+ 320, 150 + (i
* 30), graphics
.screen
, true);
74 if (engine
.userAccepts())
77 if (player
.x
< player
.tx
) player
.x
++;
78 if (player
.x
> player
.tx
) player
.x
--;
80 if ((int)player
.x
== player
.tx
)
84 time
= SDL_GetTicks() + (delay
* 1000);
89 if (SDL_GetTicks() > time
)
92 engine
.delay(frameLimit
);
93 frameLimit
= SDL_GetTicks() + 16;
96 for (int i
= 0 ; i
< 3 ; i
++)
98 SDL_FreeSurface(text
[i
]);
101 void showIntroError()
103 SDL_FillRect(graphics
.screen
, NULL
, graphics
.black
);
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
);
117 graphics
.updateScreen();
119 if (engine
.keyState
[SDLK_ESCAPE
])
125 void parseIntroCommand()
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)
153 game
.setMapName("data/introMap");
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"))
165 return SECTION_TITLE
;
168 player
.health
= -100;
172 char *line
= strtok((char*)engine
.dataBuffer
, "\n");
176 line
= strtok(NULL
, "\n");
177 sscanf(line
, "%d %d %d", &x
, &y
, &delay
);
184 playIntro(x
, y
, delay
);
186 if (engine
.userAccepts())
190 if (!engine
.userAccepts())
193 graphics
.fadeToBlack();
198 return SECTION_TITLE
;