ending.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // All rights reserved.
  5. //
  6. // This file is part of SDLPAL.
  7. //
  8. // SDLPAL is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. //
  21. #include "main.h"
  22. static WORD g_wCurEffectSprite = 0;
  23. VOID
  24. PAL_EndingSetEffectSprite(
  25. WORD wSpriteNum
  26. )
  27. /*++
  28. Purpose:
  29. Set the effect sprite of the ending.
  30. Parameters:
  31. [IN] wSpriteNum - the number of the sprite.
  32. Return value:
  33. None.
  34. --*/
  35. {
  36. g_wCurEffectSprite = wSpriteNum;
  37. }
  38. VOID
  39. PAL_ShowFBP(
  40. WORD wChunkNum,
  41. WORD wFade
  42. )
  43. /*++
  44. Purpose:
  45. Draw an FBP picture to the screen.
  46. Parameters:
  47. [IN] wChunkNum - number of chunk in fbp.mkf file.
  48. [IN] wFade - fading speed of showing the picture.
  49. Return value:
  50. None.
  51. --*/
  52. {
  53. PAL_LARGE BYTE buf[320 * 200];
  54. PAL_LARGE BYTE bufSprite[320 * 200];
  55. const int rgIndex[6] = {0, 3, 1, 5, 2, 4};
  56. int i, j, k;
  57. BYTE a, b;
  58. if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0)
  59. {
  60. memset(buf, 0, sizeof(buf));
  61. }
  62. if (g_wCurEffectSprite != 0)
  63. {
  64. PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO);
  65. }
  66. if (wFade)
  67. {
  68. SDL_Surface *p = VIDEO_CreateCompatibleSurface(gpScreen);
  69. wFade++;
  70. wFade *= 10;
  71. PAL_FBPBlitToSurface(buf, p);
  72. VIDEO_BackupScreen(gpScreen);
  73. for (i = 0; i < 16; i++)
  74. {
  75. for (j = 0; j < 6; j++)
  76. {
  77. //
  78. // Blend the pixels in the 2 buffers, and put the result into the
  79. // backup buffer
  80. //
  81. for (k = rgIndex[j]; k < gpScreen->pitch * gpScreen->h; k += 6)
  82. {
  83. a = ((LPBYTE)(p->pixels))[k];
  84. b = ((LPBYTE)(gpScreenBak->pixels))[k];
  85. if (i > 0)
  86. {
  87. if ((a & 0x0F) > (b & 0x0F))
  88. {
  89. b++;
  90. }
  91. else if ((a & 0x0F) < (b & 0x0F))
  92. {
  93. b--;
  94. }
  95. }
  96. ((LPBYTE)(gpScreenBak->pixels))[k] = ((a & 0xF0) | (b & 0x0F));
  97. }
  98. VIDEO_RestoreScreen(gpScreen);
  99. if (g_wCurEffectSprite != 0)
  100. {
  101. int f = SDL_GetTicks() / 150;
  102. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
  103. gpScreen, PAL_XY(0, 0));
  104. }
  105. VIDEO_UpdateScreen(NULL);
  106. UTIL_Delay(wFade);
  107. }
  108. }
  109. VIDEO_FreeSurface(p);
  110. }
  111. //
  112. // HACKHACK: to make the ending show correctly
  113. //
  114. if (wChunkNum != (gConfig.fIsWIN95 ? 68 : 49))
  115. {
  116. PAL_FBPBlitToSurface(buf, gpScreen);
  117. }
  118. VIDEO_UpdateScreen(NULL);
  119. }
  120. VOID
  121. PAL_ScrollFBP(
  122. WORD wChunkNum,
  123. WORD wScrollSpeed,
  124. BOOL fScrollDown
  125. )
  126. /*++
  127. Purpose:
  128. Scroll up an FBP picture to the screen.
  129. Parameters:
  130. [IN] wChunkNum - number of chunk in fbp.mkf file.
  131. [IN] wScrollSpeed - scrolling speed of showing the picture.
  132. [IN] fScrollDown - TRUE if scroll down, FALSE if scroll up.
  133. Return value:
  134. None.
  135. --*/
  136. {
  137. SDL_Surface *p;
  138. PAL_LARGE BYTE buf[320 * 200];
  139. PAL_LARGE BYTE bufSprite[320 * 200];
  140. int i, l;
  141. SDL_Rect rect, dstrect;
  142. if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0)
  143. {
  144. return;
  145. }
  146. if (g_wCurEffectSprite != 0)
  147. {
  148. PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO);
  149. }
  150. p = VIDEO_CreateCompatibleSurface(gpScreen);
  151. if (p == NULL)
  152. {
  153. return;
  154. }
  155. VIDEO_BackupScreen(gpScreen);
  156. PAL_FBPBlitToSurface(buf, p);
  157. if (wScrollSpeed == 0)
  158. {
  159. wScrollSpeed = 1;
  160. }
  161. rect.x = 0;
  162. rect.w = 320;
  163. dstrect.x = 0;
  164. dstrect.w = 320;
  165. for (l = 0; l < 220; l++)
  166. {
  167. i = l;
  168. if (i > 200)
  169. {
  170. i = 200;
  171. }
  172. if (fScrollDown)
  173. {
  174. rect.y = 0;
  175. dstrect.y = i;
  176. rect.h = 200 - i;
  177. dstrect.h = 200 - i;
  178. }
  179. else
  180. {
  181. rect.y = i;
  182. dstrect.y = 0;
  183. rect.h = 200 - i;
  184. dstrect.h = 200 - i;
  185. }
  186. VIDEO_CopySurface(gpScreenBak, &rect, gpScreen, &dstrect);
  187. if (fScrollDown)
  188. {
  189. rect.y = 200 - i;
  190. dstrect.y = 0;
  191. rect.h = i;
  192. dstrect.h = i;
  193. }
  194. else
  195. {
  196. rect.y = 0;
  197. dstrect.y = 200 - i;
  198. rect.h = i;
  199. dstrect.h = i;
  200. }
  201. VIDEO_CopySurface(p, &rect, gpScreen, &dstrect);
  202. PAL_ApplyWave(gpScreen);
  203. if (g_wCurEffectSprite != 0)
  204. {
  205. int f = SDL_GetTicks() / 150;
  206. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
  207. gpScreen, PAL_XY(0, 0));
  208. }
  209. VIDEO_UpdateScreen(NULL);
  210. if (gpGlobals->fNeedToFadeIn)
  211. {
  212. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  213. gpGlobals->fNeedToFadeIn = FALSE;
  214. VIDEO_UpdateSurfacePalette(p, gpScreen);
  215. }
  216. UTIL_Delay(800 / wScrollSpeed);
  217. }
  218. VIDEO_CopyEntireSurface(p, gpScreen);
  219. VIDEO_FreeSurface(p);
  220. VIDEO_UpdateScreen(NULL);
  221. }
  222. VOID
  223. PAL_EndingAnimation(
  224. VOID
  225. )
  226. /*++
  227. Purpose:
  228. Show the ending animation.
  229. Parameters:
  230. None.
  231. Return value:
  232. None.
  233. --*/
  234. {
  235. LPBYTE buf;
  236. LPBYTE bufGirl;
  237. SDL_Surface *pUpper;
  238. SDL_Surface *pLower;
  239. SDL_Rect srcrect, dstrect;
  240. int yPosGirl = 180;
  241. int i;
  242. buf = (LPBYTE)UTIL_calloc(1, 64000);
  243. bufGirl = (LPBYTE)UTIL_calloc(1, 6000);
  244. pUpper = VIDEO_CreateCompatibleSurface(gpScreen);
  245. pLower = VIDEO_CreateCompatibleSurface(gpScreen);
  246. PAL_MKFDecompressChunk(buf, 64000, gConfig.fIsWIN95 ? 69 : 61, gpGlobals->f.fpFBP);
  247. PAL_FBPBlitToSurface(buf, pUpper);
  248. PAL_MKFDecompressChunk(buf, 64000, gConfig.fIsWIN95 ? 70 : 62, gpGlobals->f.fpFBP);
  249. PAL_FBPBlitToSurface(buf, pLower);
  250. PAL_MKFDecompressChunk(buf, 64000, 571, gpGlobals->f.fpMGO);
  251. PAL_MKFDecompressChunk(bufGirl, 6000, 572, gpGlobals->f.fpMGO);
  252. srcrect.x = 0;
  253. dstrect.x = 0;
  254. srcrect.w = 320;
  255. dstrect.w = 320;
  256. gpGlobals->wScreenWave = 2;
  257. for (i = 0; i < 400; i++)
  258. {
  259. //
  260. // Draw the background
  261. //
  262. srcrect.y = 0;
  263. srcrect.h = 200 - i / 2;
  264. dstrect.y = i / 2;
  265. dstrect.h = 200 - i / 2;
  266. VIDEO_CopySurface(pLower, &srcrect, gpScreen, &dstrect);
  267. srcrect.y = 200 - i / 2;
  268. srcrect.h = i / 2;
  269. dstrect.y = 0;
  270. dstrect.h = i / 2;
  271. VIDEO_CopySurface(pUpper, &srcrect, gpScreen, &dstrect);
  272. PAL_ApplyWave(gpScreen);
  273. //
  274. // Draw the beast
  275. //
  276. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 0), gpScreen, PAL_XY(0, -400 + i));
  277. PAL_RLEBlitToSurface(gConfig.fIsWIN95 ? buf + 0x8444 : PAL_SpriteGetFrame(buf, 1), gpScreen, PAL_XY(0, -200 + i));
  278. //
  279. // Draw the girl
  280. //
  281. yPosGirl -= i & 1;
  282. if (yPosGirl < 80)
  283. {
  284. yPosGirl = 80;
  285. }
  286. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufGirl, (SDL_GetTicks() / 50) % 4),
  287. gpScreen, PAL_XY(220, yPosGirl));
  288. //
  289. // Update the screen
  290. //
  291. VIDEO_UpdateScreen(NULL);
  292. if (gpGlobals->fNeedToFadeIn)
  293. {
  294. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  295. gpGlobals->fNeedToFadeIn = FALSE;
  296. VIDEO_UpdateSurfacePalette(pUpper, gpScreen);
  297. VIDEO_UpdateSurfacePalette(pLower, gpScreen);
  298. }
  299. UTIL_Delay(50);
  300. }
  301. gpGlobals->wScreenWave = 0;
  302. VIDEO_FreeSurface(pUpper);
  303. VIDEO_FreeSurface(pLower);
  304. free(buf);
  305. free(bufGirl);
  306. }
  307. VOID
  308. PAL_EndingScreen(
  309. VOID
  310. )
  311. {
  312. AUDIO_PlayMusic(0x1a, TRUE, 0);
  313. PAL_RNGPlay(gpGlobals->iCurPlayingRNG, 110, 150, 7);
  314. PAL_RNGPlay(gpGlobals->iCurPlayingRNG, 151, 999, 9);
  315. PAL_FadeOut(2);
  316. AUDIO_PlayMusic(0x19, TRUE, 0);
  317. PAL_ShowFBP(75, 0);
  318. PAL_FadeIn(5, FALSE, 1);
  319. PAL_ScrollFBP(74, 0xf, TRUE);
  320. PAL_FadeOut(1);
  321. SDL_FillRect(gpScreen, NULL, 0);
  322. gpGlobals->wNumPalette = 4;
  323. gpGlobals->fNeedToFadeIn = TRUE;
  324. PAL_EndingAnimation();
  325. AUDIO_PlayMusic(0, FALSE, 2);
  326. PAL_ColorFade(7, 15, FALSE);
  327. if (!AUDIO_PlayCDTrack(2))
  328. {
  329. AUDIO_PlayMusic(0x11, TRUE, 0);
  330. }
  331. SDL_FillRect(gpScreen, NULL, 0);
  332. PAL_SetPalette(0, FALSE);
  333. PAL_RNGPlay(0xb, 0, 999, 7);
  334. PAL_FadeOut(2);
  335. SDL_FillRect(gpScreen, NULL, 0);
  336. gpGlobals->wNumPalette = 8;
  337. gpGlobals->fNeedToFadeIn = TRUE;
  338. PAL_RNGPlay(10, 0, 999, 6);
  339. PAL_EndingSetEffectSprite(0);
  340. PAL_ShowFBP(77, 10);
  341. VIDEO_BackupScreen(gpScreen);
  342. PAL_EndingSetEffectSprite(0x27b);
  343. PAL_ShowFBP(76, 7);
  344. PAL_SetPalette(5, FALSE);
  345. PAL_ShowFBP(73, 7);
  346. PAL_ScrollFBP(72, 0xf, TRUE);
  347. PAL_ShowFBP(71, 7);
  348. PAL_ShowFBP(68, 7);
  349. PAL_EndingSetEffectSprite(0);
  350. PAL_ShowFBP(68, 6);
  351. PAL_WaitForKey(0);
  352. AUDIO_PlayMusic(0, FALSE, 1);
  353. UTIL_Delay(500);
  354. if (!AUDIO_PlayCDTrack(13))
  355. {
  356. AUDIO_PlayMusic(9, TRUE, 0);
  357. }
  358. PAL_ScrollFBP(67, 0xf, TRUE);
  359. PAL_ScrollFBP(66, 0xf, TRUE);
  360. PAL_ScrollFBP(65, 0xf, TRUE);
  361. PAL_ScrollFBP(64, 0xf, TRUE);
  362. PAL_ScrollFBP(63, 0xf, TRUE);
  363. PAL_ScrollFBP(62, 0xf, TRUE);
  364. PAL_ScrollFBP(61, 0xf, TRUE);
  365. PAL_ScrollFBP(60, 0xf, TRUE);
  366. PAL_ScrollFBP(59, 0xf, TRUE);
  367. AUDIO_PlayMusic(0, FALSE, 6);
  368. PAL_FadeOut(3);
  369. }