1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "drascula/drascula.h"
24
25 namespace Drascula {
26
placeIgor()27 void DrasculaEngine::placeIgor() {
28 int igY = 0;
29
30 if (currentChapter == 4) {
31 igY = 138;
32 } else {
33 if (trackIgor == 3)
34 igY = 138;
35 else if (trackIgor == 1)
36 igY = 76;
37 }
38
39 copyRect(1, igY, igorX, igorY, 54, 61, frontSurface, screenSurface);
40 }
41
placeDrascula()42 void DrasculaEngine::placeDrascula() {
43 int drX = 0;
44
45 if (trackDrascula == 1)
46 drX = 47;
47 else if (trackDrascula == 0)
48 drX = 1;
49 else if (trackDrascula == 3 && currentChapter == 1)
50 drX = 93;
51
52 if (currentChapter == 6)
53 copyRect(drX, 122, drasculaX, drasculaY, 45, 77, drawSurface2, screenSurface);
54 else
55 copyRect(drX, 122, drasculaX, drasculaY, 45, 77, backSurface, screenSurface);
56 }
57
hiccup(int counter)58 void DrasculaEngine::hiccup(int counter) {
59 int y = 0, trackCharacter = 0;
60 if (currentChapter == 3)
61 y = -1;
62
63 do {
64 counter--;
65
66 updateEvents();
67 updateRoom();
68 if (currentChapter == 3)
69 updateScreen(0, 0, 0, y, 320, 200, screenSurface);
70 else
71 updateScreen(0, 1, 0, y, 320, 198, screenSurface);
72
73 if (trackCharacter == 0)
74 y++;
75 else
76 y--;
77
78 if (currentChapter == 3) {
79 if (y == 1)
80 trackCharacter = 1;
81 if (y == -1)
82 trackCharacter = 0;
83 } else {
84 if (y == 2)
85 trackCharacter = 1;
86 if (y == 0)
87 trackCharacter = 0;
88 }
89 pause(3);
90 } while (counter > 0);
91
92 updateRoom();
93 updateScreen();
94 }
95
startWalking()96 void DrasculaEngine::startWalking() {
97 _characterMoved = true;
98
99 stepX = STEP_X;
100 stepY = STEP_Y;
101
102 if (currentChapter == 2) {
103 if ((roomX < curX) && (roomY <= (curY + curHeight)))
104 quadrant_1();
105 else if ((roomX < curX) && (roomY > (curY + curHeight)))
106 quadrant_3();
107 else if ((roomX > curX + curWidth) && (roomY <= (curY + curHeight)))
108 quadrant_2();
109 else if ((roomX > curX + curWidth) && (roomY > (curY + curHeight)))
110 quadrant_4();
111 else if (roomY < curY + curHeight)
112 walkUp();
113 else if (roomY > curY + curHeight)
114 walkDown();
115 else
116 _characterMoved = false;
117 } else {
118 if ((roomX < curX + curWidth / 2 ) && (roomY <= (curY + curHeight)))
119 quadrant_1();
120 else if ((roomX < curX + curWidth / 2) && (roomY > (curY + curHeight)))
121 quadrant_3();
122 else if ((roomX > curX + curWidth / 2) && (roomY <= (curY + curHeight)))
123 quadrant_2();
124 else if ((roomX > curX + curWidth / 2) && (roomY > (curY + curHeight)))
125 quadrant_4();
126 else
127 _characterMoved = false;
128 }
129 _startTime = getTime();
130 }
131
moveCharacters()132 void DrasculaEngine::moveCharacters() {
133 int curPos[6];
134 int r;
135
136 if (_characterMoved && stepX == STEP_X) {
137 for (r = 0; r < stepX; r++) {
138 if (currentChapter != 2) {
139 if (trackProtagonist == 0 && roomX - r == curX + curWidth / 2) {
140 _characterMoved = false;
141 stepX = STEP_X;
142 stepY = STEP_Y;
143 }
144 if (trackProtagonist == 1 && roomX + r == curX + curWidth / 2) {
145 _characterMoved = false;
146 stepX = STEP_X;
147 stepY = STEP_Y;
148 curX = roomX - curWidth / 2;
149 curY = roomY - curHeight;
150 }
151 } else if (currentChapter == 2) {
152 if (trackProtagonist == 0 && roomX - r == curX) {
153 _characterMoved = false;
154 stepX = STEP_X;
155 stepY = STEP_Y;
156 }
157 if (trackProtagonist == 1 && roomX + r == curX + curWidth) {
158 _characterMoved = false;
159 stepX = STEP_X;
160 stepY = STEP_Y;
161 curX = roomX - curWidth + 4;
162 curY = roomY - curHeight;
163 }
164 }
165 }
166 }
167 if (_characterMoved && stepY == STEP_Y) {
168 for (r = 0; r < stepY; r++) {
169 if (trackProtagonist == 2 && roomY - r == curY + curHeight) {
170 _characterMoved = false;
171 stepX = STEP_X;
172 stepY = STEP_Y;
173 }
174 if (trackProtagonist == 3 && roomY + r == curY + curHeight) {
175 _characterMoved = false;
176 stepX = STEP_X;
177 stepY = STEP_Y;
178 }
179 }
180 }
181
182 if (currentChapter != 2 && currentChapter != 3) {
183 if (!_characterVisible) {
184 increaseFrameNum();
185 return;
186 }
187 }
188
189 if (!_characterMoved) {
190 curPos[0] = 0;
191 curPos[1] = DIF_MASK_HARE;
192 curPos[2] = curX;
193 curPos[3] = curY;
194 if (currentChapter == 2) {
195 curPos[4] = curWidth;
196 curPos[5] = curHeight;
197 } else {
198 curPos[4] = CHARACTER_WIDTH;
199 curPos[5] = CHARACTER_HEIGHT;
200 }
201
202 if (trackProtagonist == 0) {
203 curPos[1] = 0;
204 if (currentChapter == 2)
205 copyRect(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
206 extraSurface, screenSurface);
207 else
208 reduce_hare_chico(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
209 factor_red[curY + curHeight], extraSurface, screenSurface);
210 } else if (trackProtagonist == 1) {
211 if (currentChapter == 2)
212 copyRect(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
213 extraSurface, screenSurface);
214 else
215 reduce_hare_chico(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
216 factor_red[curY + curHeight], extraSurface, screenSurface);
217 } else if (trackProtagonist == 2) {
218 if (currentChapter == 2)
219 copyRect(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
220 backSurface, screenSurface);
221 else
222 reduce_hare_chico(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
223 factor_red[curY + curHeight], backSurface, screenSurface);
224 } else {
225 if (currentChapter == 2)
226 copyRect(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
227 frontSurface, screenSurface);
228 else
229 reduce_hare_chico(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
230 factor_red[curY + curHeight], frontSurface, screenSurface);
231 }
232 } else if (_characterMoved) {
233 curPos[0] = _frameX[_characterFrame];
234 curPos[1] = frame_y + DIF_MASK_HARE;
235 curPos[2] = curX;
236 curPos[3] = curY;
237 if (currentChapter == 2) {
238 curPos[4] = curWidth;
239 curPos[5] = curHeight;
240 } else {
241 curPos[4] = CHARACTER_WIDTH;
242 curPos[5] = CHARACTER_HEIGHT;
243 }
244 if (trackProtagonist == 0) {
245 curPos[1] = 0;
246 if (currentChapter == 2)
247 copyRect(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
248 extraSurface, screenSurface);
249 else
250 reduce_hare_chico(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
251 factor_red[curY + curHeight], extraSurface, screenSurface);
252 } else if (trackProtagonist == 1) {
253 if (currentChapter == 2)
254 copyRect(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
255 extraSurface, screenSurface);
256 else
257 reduce_hare_chico(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
258 factor_red[curY + curHeight], extraSurface, screenSurface);
259 } else if (trackProtagonist == 2) {
260 if (currentChapter == 2)
261 copyRect(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
262 backSurface, screenSurface);
263 else
264 reduce_hare_chico(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
265 factor_red[curY + curHeight], backSurface, screenSurface);
266 } else {
267 if (currentChapter == 2)
268 copyRect(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
269 frontSurface, screenSurface);
270 else
271 reduce_hare_chico(curPos[0], curPos[1], curPos[2], curPos[3], curPos[4], curPos[5],
272 factor_red[curY + curHeight], frontSurface, screenSurface);
273 }
274 increaseFrameNum();
275 }
276 }
277
quadrant_1()278 void DrasculaEngine::quadrant_1() {
279 float distanceX, distanceY;
280
281 if (currentChapter == 2)
282 distanceX = curX - roomX;
283 else
284 distanceX = curX + curWidth / 2 - roomX;
285
286 distanceY = (curY + curHeight) - roomY;
287
288 if (distanceX < distanceY) {
289 curDirection = kDirectionUp;
290 trackProtagonist = 2;
291 stepX = (int)(distanceX / (distanceY / STEP_Y));
292 } else {
293 curDirection = kDirectionUp;
294 trackProtagonist = 0;
295 stepY = (int)(distanceY / (distanceX / STEP_X));
296 }
297 }
298
quadrant_2()299 void DrasculaEngine::quadrant_2() {
300 float distanceX, distanceY;
301
302 if (currentChapter == 2)
303 distanceX = ABS(curX + curWidth - roomX);
304 else
305 distanceX = ABS(curX + curWidth / 2 - roomX);
306
307 distanceY = (curY + curHeight) - roomY;
308
309 if (distanceX < distanceY) {
310 curDirection = kDirectionRight;
311 trackProtagonist = 2;
312 stepX = (int)(distanceX / (distanceY / STEP_Y));
313 } else {
314 curDirection = kDirectionRight;
315 trackProtagonist = 1;
316 stepY = (int)(distanceY / (distanceX / STEP_X));
317 }
318 }
319
quadrant_3()320 void DrasculaEngine::quadrant_3() {
321 float distanceX, distanceY;
322
323 if (currentChapter == 2)
324 distanceX = curX - roomX;
325 else
326 distanceX = curX + curWidth / 2 - roomX;
327
328 distanceY = roomY - (curY + curHeight);
329
330 if (distanceX < distanceY) {
331 curDirection = kDirectionLeft;
332 trackProtagonist = 3;
333 stepX = (int)(distanceX / (distanceY / STEP_Y));
334 } else {
335 curDirection = kDirectionLeft;
336 trackProtagonist = 0;
337 stepY = (int)(distanceY / (distanceX / STEP_X));
338 }
339 }
340
quadrant_4()341 void DrasculaEngine::quadrant_4() {
342 float distanceX, distanceY;
343
344 if (currentChapter == 2)
345 distanceX = ABS(curX + curWidth - roomX);
346 else
347 distanceX = ABS(curX + curWidth / 2 - roomX);
348
349 distanceY = roomY - (curY + curHeight);
350
351 if (distanceX < distanceY) {
352 curDirection = kDirectionDown;
353 trackProtagonist = 3;
354 stepX = (int)(distanceX / (distanceY / STEP_Y));
355 } else {
356 curDirection = kDirectionDown;
357 trackProtagonist = 1;
358 stepY = (int)(distanceY / (distanceX / STEP_X));
359 }
360 }
361
increaseFrameNum()362 void DrasculaEngine::increaseFrameNum() {
363 if (getTime() - _startTime >= 6) {
364 _startTime = getTime();
365 _characterFrame++;
366 if (_characterFrame == 6)
367 _characterFrame = 0;
368
369 if (curDirection == kDirectionUp) {
370 curX -= stepX;
371 curY -= stepY;
372 } else if (curDirection == kDirectionRight) {
373 curX += stepX;
374 curY -= stepY;
375 } else if (curDirection == kDirectionDown) {
376 curX += stepX;
377 curY += stepY;
378 } else if (curDirection == kDirectionLeft) {
379 curX -= stepX;
380 curY += stepY;
381 }
382 }
383
384 if (currentChapter != 2) {
385 curY += (int)(curHeight - newHeight);
386 curX += (int)(curWidth - newWidth);
387 curHeight = (int)newHeight;
388 curWidth = (int)newWidth;
389 }
390
391 // Fix bug #5903 DRASCULA-IT: Crash/graphic glitch at castle towers
392 // Chapter 5 Room 45 is the castle tower part
393 // Fixing the character's coordinate(0,0) in the tower section to prevent out of window coordinates and crash
394 if ((currentChapter == 5) && (_roomNumber == 45)) {
395 curY = 0;
396 curX = 0;
397 curHeight = 0;
398 curWidth = 0;
399 }
400 }
401
walkDown()402 void DrasculaEngine::walkDown() {
403 curDirection = kDirectionDown;
404 trackProtagonist = 3;
405 stepX = 0;
406 }
407
walkUp()408 void DrasculaEngine::walkUp() {
409 curDirection = kDirectionUp;
410 trackProtagonist = 2;
411 stepX = 0;
412 }
413
moveVonBraun()414 void DrasculaEngine::moveVonBraun() {
415 int pos_vb[6];
416
417 if (vonBraunHasMoved == 0) {
418 pos_vb[0] = 256;
419 pos_vb[1] = 129;
420 pos_vb[2] = vonBraunX;
421 pos_vb[3] = 66;
422 pos_vb[4] = 33;
423 pos_vb[5] = 69;
424 if (trackVonBraun == 0)
425 pos_vb[0] = 222;
426 else if (trackVonBraun == 1)
427 pos_vb[0] = 188;
428 } else {
429 pos_vb[0] = actorFrames[kFrameVonBraun];
430 pos_vb[1] = (trackVonBraun == 0) ? 62 : 131;
431 pos_vb[2] = vonBraunX;
432 pos_vb[3] = 66;
433 pos_vb[4] = 28;
434 pos_vb[5] = 68;
435
436 actorFrames[kFrameVonBraun] += 29;
437 if (actorFrames[kFrameVonBraun] > 146)
438 actorFrames[kFrameVonBraun] = 1;
439 }
440
441 copyRect(pos_vb[0], pos_vb[1], pos_vb[2], pos_vb[3], pos_vb[4], pos_vb[5],
442 frontSurface, screenSurface);
443 }
444
placeVonBraun(int pointX)445 void DrasculaEngine::placeVonBraun(int pointX) {
446 trackVonBraun = (pointX < vonBraunX) ? 0 : 1;
447 vonBraunHasMoved = 1;
448
449 while (!shouldQuit()) {
450 updateEvents();
451 updateRoom();
452 updateScreen();
453 if (trackVonBraun == 0) {
454 vonBraunX = vonBraunX - 5;
455 if (vonBraunX <= pointX)
456 break;
457 } else {
458 vonBraunX = vonBraunX + 5;
459 if (vonBraunX >= pointX)
460 break;
461 }
462 pause(5);
463 }
464
465 vonBraunHasMoved = 0;
466 }
467
468
469
470 } // End of namespace Drascula
471