ending.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. #if SDL_VERSION_ATLEAST(2, 0, 0)
  215. SDL_SetSurfacePalette(p, gpScreen->format->palette);
  216. #else
  217. SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  218. #endif
  219. }
  220. UTIL_Delay(800 / wScrollSpeed);
  221. }
  222. VIDEO_CopyEntireSurface(p, gpScreen);
  223. VIDEO_FreeSurface(p);
  224. VIDEO_UpdateScreen(NULL);
  225. }
  226. VOID
  227. PAL_EndingAnimation(
  228. VOID
  229. )
  230. /*++
  231. Purpose:
  232. Show the ending animation.
  233. Parameters:
  234. None.
  235. Return value:
  236. None.
  237. --*/
  238. {
  239. LPBYTE buf;
  240. LPBYTE bufGirl;
  241. SDL_Surface *pUpper;
  242. SDL_Surface *pLower;
  243. SDL_Rect srcrect, dstrect;
  244. int yPosGirl = 180;
  245. int i;
  246. buf = (LPBYTE)UTIL_calloc(1, 64000);
  247. bufGirl = (LPBYTE)UTIL_calloc(1, 6000);
  248. pUpper = VIDEO_CreateCompatibleSurface(gpScreen);
  249. pLower = VIDEO_CreateCompatibleSurface(gpScreen);
  250. PAL_MKFDecompressChunk(buf, 64000, gConfig.fIsWIN95 ? 69 : 61, gpGlobals->f.fpFBP);
  251. PAL_FBPBlitToSurface(buf, pUpper);
  252. PAL_MKFDecompressChunk(buf, 64000, gConfig.fIsWIN95 ? 70 : 62, gpGlobals->f.fpFBP);
  253. PAL_FBPBlitToSurface(buf, pLower);
  254. PAL_MKFDecompressChunk(buf, 64000, 571, gpGlobals->f.fpMGO);
  255. PAL_MKFDecompressChunk(bufGirl, 6000, 572, gpGlobals->f.fpMGO);
  256. srcrect.x = 0;
  257. dstrect.x = 0;
  258. srcrect.w = 320;
  259. dstrect.w = 320;
  260. gpGlobals->wScreenWave = 2;
  261. for (i = 0; i < 400; i++)
  262. {
  263. //
  264. // Draw the background
  265. //
  266. srcrect.y = 0;
  267. srcrect.h = 200 - i / 2;
  268. dstrect.y = i / 2;
  269. dstrect.h = 200 - i / 2;
  270. VIDEO_CopySurface(pLower, &srcrect, gpScreen, &dstrect);
  271. srcrect.y = 200 - i / 2;
  272. srcrect.h = i / 2;
  273. dstrect.y = 0;
  274. dstrect.h = i / 2;
  275. VIDEO_CopySurface(pUpper, &srcrect, gpScreen, &dstrect);
  276. PAL_ApplyWave(gpScreen);
  277. //
  278. // Draw the beast
  279. //
  280. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 0), gpScreen, PAL_XY(0, -400 + i));
  281. PAL_RLEBlitToSurface(gConfig.fIsWIN95 ? buf + 0x8444 : PAL_SpriteGetFrame(buf, 1), gpScreen, PAL_XY(0, -200 + i));
  282. //
  283. // Draw the girl
  284. //
  285. yPosGirl -= i & 1;
  286. if (yPosGirl < 80)
  287. {
  288. yPosGirl = 80;
  289. }
  290. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufGirl, (SDL_GetTicks() / 50) % 4),
  291. gpScreen, PAL_XY(220, yPosGirl));
  292. //
  293. // Update the screen
  294. //
  295. VIDEO_UpdateScreen(NULL);
  296. if (gpGlobals->fNeedToFadeIn)
  297. {
  298. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  299. gpGlobals->fNeedToFadeIn = FALSE;
  300. #if SDL_VERSION_ATLEAST(2, 0, 0)
  301. SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
  302. SDL_SetSurfacePalette(pLower, gpScreen->format->palette);
  303. #else
  304. SDL_SetPalette(pUpper, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256);
  305. SDL_SetPalette(pLower, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256);
  306. #endif
  307. }
  308. UTIL_Delay(50);
  309. }
  310. gpGlobals->wScreenWave = 0;
  311. VIDEO_FreeSurface(pUpper);
  312. VIDEO_FreeSurface(pLower);
  313. free(buf);
  314. free(bufGirl);
  315. }
  316. VOID
  317. PAL_EndingScreen(
  318. VOID
  319. )
  320. {
  321. AUDIO_PlayMusic(0x1a, TRUE, 0);
  322. PAL_RNGPlay(gpGlobals->iCurPlayingRNG, 110, 150, 7);
  323. PAL_RNGPlay(gpGlobals->iCurPlayingRNG, 151, 999, 9);
  324. PAL_FadeOut(2);
  325. AUDIO_PlayMusic(0x19, TRUE, 0);
  326. PAL_ShowFBP(75, 0);
  327. PAL_FadeIn(5, FALSE, 1);
  328. PAL_ScrollFBP(74, 0xf, TRUE);
  329. PAL_FadeOut(1);
  330. SDL_FillRect(gpScreen, NULL, 0);
  331. gpGlobals->wNumPalette = 4;
  332. gpGlobals->fNeedToFadeIn = TRUE;
  333. PAL_EndingAnimation();
  334. AUDIO_PlayMusic(0, FALSE, 2);
  335. PAL_ColorFade(7, 15, FALSE);
  336. if (!AUDIO_PlayCDTrack(2))
  337. {
  338. AUDIO_PlayMusic(0x11, TRUE, 0);
  339. }
  340. SDL_FillRect(gpScreen, NULL, 0);
  341. PAL_SetPalette(0, FALSE);
  342. PAL_RNGPlay(0xb, 0, 999, 7);
  343. PAL_FadeOut(2);
  344. SDL_FillRect(gpScreen, NULL, 0);
  345. gpGlobals->wNumPalette = 8;
  346. gpGlobals->fNeedToFadeIn = TRUE;
  347. PAL_RNGPlay(10, 0, 999, 6);
  348. PAL_EndingSetEffectSprite(0);
  349. PAL_ShowFBP(77, 10);
  350. VIDEO_BackupScreen(gpScreen);
  351. PAL_EndingSetEffectSprite(0x27b);
  352. PAL_ShowFBP(76, 7);
  353. PAL_SetPalette(5, FALSE);
  354. PAL_ShowFBP(73, 7);
  355. PAL_ScrollFBP(72, 0xf, TRUE);
  356. PAL_ShowFBP(71, 7);
  357. PAL_ShowFBP(68, 7);
  358. PAL_EndingSetEffectSprite(0);
  359. PAL_ShowFBP(68, 6);
  360. PAL_WaitForKey(0);
  361. AUDIO_PlayMusic(0, FALSE, 1);
  362. UTIL_Delay(500);
  363. if (!AUDIO_PlayCDTrack(13))
  364. {
  365. AUDIO_PlayMusic(9, TRUE, 0);
  366. }
  367. PAL_ScrollFBP(67, 0xf, TRUE);
  368. PAL_ScrollFBP(66, 0xf, TRUE);
  369. PAL_ScrollFBP(65, 0xf, TRUE);
  370. PAL_ScrollFBP(64, 0xf, TRUE);
  371. PAL_ScrollFBP(63, 0xf, TRUE);
  372. PAL_ScrollFBP(62, 0xf, TRUE);
  373. PAL_ScrollFBP(61, 0xf, TRUE);
  374. PAL_ScrollFBP(60, 0xf, TRUE);
  375. PAL_ScrollFBP(59, 0xf, TRUE);
  376. AUDIO_PlayMusic(0, FALSE, 6);
  377. PAL_FadeOut(3);
  378. }