ending.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. SDL_Surface *p;
  57. int i, j, k;
  58. BYTE a, b;
  59. if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0)
  60. {
  61. memset(buf, 0, sizeof(buf));
  62. }
  63. if (g_wCurEffectSprite != 0)
  64. {
  65. PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO);
  66. }
  67. if (wFade)
  68. {
  69. wFade++;
  70. wFade *= 10;
  71. p = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  72. gpScreen->format->Rmask, gpScreen->format->Gmask,
  73. gpScreen->format->Bmask, gpScreen->format->Amask);
  74. #if SDL_VERSION_ATLEAST(2, 0, 0)
  75. SDL_SetSurfacePalette(p, gpScreen->format->palette);
  76. #else
  77. SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  78. #endif
  79. PAL_FBPBlitToSurface(buf, p);
  80. VIDEO_BackupScreen();
  81. for (i = 0; i < 16; i++)
  82. {
  83. for (j = 0; j < 6; j++)
  84. {
  85. //
  86. // Blend the pixels in the 2 buffers, and put the result into the
  87. // backup buffer
  88. //
  89. for (k = rgIndex[j]; k < gpScreen->pitch * gpScreen->h; k += 6)
  90. {
  91. a = ((LPBYTE)(p->pixels))[k];
  92. b = ((LPBYTE)(gpScreenBak->pixels))[k];
  93. if (i > 0)
  94. {
  95. if ((a & 0x0F) > (b & 0x0F))
  96. {
  97. b++;
  98. }
  99. else if ((a & 0x0F) < (b & 0x0F))
  100. {
  101. b--;
  102. }
  103. }
  104. ((LPBYTE)(gpScreenBak->pixels))[k] = ((a & 0xF0) | (b & 0x0F));
  105. }
  106. SDL_BlitSurface(gpScreenBak, NULL, gpScreen, NULL);
  107. if (g_wCurEffectSprite != 0)
  108. {
  109. int f = SDL_GetTicks() / 150;
  110. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
  111. gpScreen, PAL_XY(0, 0));
  112. }
  113. VIDEO_UpdateScreen(NULL);
  114. UTIL_Delay(wFade);
  115. }
  116. }
  117. SDL_FreeSurface(p);
  118. }
  119. //
  120. // HACKHACK: to make the ending show correctly
  121. //
  122. if (wChunkNum != 49)
  123. {
  124. PAL_FBPBlitToSurface(buf, gpScreen);
  125. }
  126. VIDEO_UpdateScreen(NULL);
  127. }
  128. VOID
  129. PAL_ScrollFBP(
  130. WORD wChunkNum,
  131. WORD wScrollSpeed,
  132. BOOL fScrollDown
  133. )
  134. /*++
  135. Purpose:
  136. Scroll up an FBP picture to the screen.
  137. Parameters:
  138. [IN] wChunkNum - number of chunk in fbp.mkf file.
  139. [IN] wScrollSpeed - scrolling speed of showing the picture.
  140. [IN] fScrollDown - TRUE if scroll down, FALSE if scroll up.
  141. Return value:
  142. None.
  143. --*/
  144. {
  145. SDL_Surface *p;
  146. PAL_LARGE BYTE buf[320 * 200];
  147. PAL_LARGE BYTE bufSprite[320 * 200];
  148. int i, l;
  149. SDL_Rect rect, dstrect;
  150. if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0)
  151. {
  152. return;
  153. }
  154. if (g_wCurEffectSprite != 0)
  155. {
  156. PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO);
  157. }
  158. p = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  159. gpScreen->format->Rmask, gpScreen->format->Gmask,
  160. gpScreen->format->Bmask, gpScreen->format->Amask);
  161. if (p == NULL)
  162. {
  163. return;
  164. }
  165. #if SDL_VERSION_ATLEAST(2, 0, 0)
  166. SDL_SetSurfacePalette(p, gpScreen->format->palette);
  167. #else
  168. SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  169. #endif
  170. VIDEO_BackupScreen();
  171. PAL_FBPBlitToSurface(buf, p);
  172. if (wScrollSpeed == 0)
  173. {
  174. wScrollSpeed = 1;
  175. }
  176. rect.x = 0;
  177. rect.w = 320;
  178. dstrect.x = 0;
  179. dstrect.w = 320;
  180. for (l = 0; l < 220; l++)
  181. {
  182. i = l;
  183. if (i > 200)
  184. {
  185. i = 200;
  186. }
  187. if (fScrollDown)
  188. {
  189. rect.y = 0;
  190. dstrect.y = i;
  191. rect.h = 200 - i;
  192. dstrect.h = 200 - i;
  193. }
  194. else
  195. {
  196. rect.y = i;
  197. dstrect.y = 0;
  198. rect.h = 200 - i;
  199. dstrect.h = 200 - i;
  200. }
  201. SDL_BlitSurface(gpScreenBak, &rect, gpScreen, &dstrect);
  202. if (fScrollDown)
  203. {
  204. rect.y = 200 - i;
  205. dstrect.y = 0;
  206. rect.h = i;
  207. dstrect.h = i;
  208. }
  209. else
  210. {
  211. rect.y = 0;
  212. dstrect.y = 200 - i;
  213. rect.h = i;
  214. dstrect.h = i;
  215. }
  216. SDL_BlitSurface(p, &rect, gpScreen, &dstrect);
  217. PAL_ApplyWave(gpScreen);
  218. if (g_wCurEffectSprite != 0)
  219. {
  220. int f = SDL_GetTicks() / 150;
  221. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
  222. gpScreen, PAL_XY(0, 0));
  223. }
  224. VIDEO_UpdateScreen(NULL);
  225. if (gpGlobals->fNeedToFadeIn)
  226. {
  227. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  228. gpGlobals->fNeedToFadeIn = FALSE;
  229. #if SDL_VERSION_ATLEAST(2, 0, 0)
  230. SDL_SetSurfacePalette(p, gpScreen->format->palette);
  231. #else
  232. SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  233. #endif
  234. }
  235. UTIL_Delay(800 / wScrollSpeed);
  236. }
  237. SDL_BlitSurface(p, NULL, gpScreen, NULL);
  238. SDL_FreeSurface(p);
  239. VIDEO_UpdateScreen(NULL);
  240. }
  241. VOID
  242. PAL_EndingAnimation(
  243. VOID
  244. )
  245. /*++
  246. Purpose:
  247. Show the ending animation.
  248. Parameters:
  249. None.
  250. Return value:
  251. None.
  252. --*/
  253. {
  254. LPBYTE buf;
  255. LPBYTE bufGirl;
  256. SDL_Surface *pUpper;
  257. SDL_Surface *pLower;
  258. SDL_Rect srcrect, dstrect;
  259. int yPosGirl = 180;
  260. int i;
  261. buf = (LPBYTE)UTIL_calloc(1, 64000);
  262. bufGirl = (LPBYTE)UTIL_calloc(1, 6000);
  263. pUpper = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  264. gpScreen->format->Rmask, gpScreen->format->Gmask,
  265. gpScreen->format->Bmask, gpScreen->format->Amask);
  266. pLower = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  267. gpScreen->format->Rmask, gpScreen->format->Gmask,
  268. gpScreen->format->Bmask, gpScreen->format->Amask);
  269. #if SDL_VERSION_ATLEAST(2, 0, 0)
  270. SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
  271. SDL_SetSurfacePalette(pLower, gpScreen->format->palette);
  272. #else
  273. SDL_SetPalette(pUpper, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  274. SDL_SetPalette(pLower, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256);
  275. #endif
  276. PAL_MKFDecompressChunk(buf, 64000, 61, gpGlobals->f.fpFBP);
  277. PAL_FBPBlitToSurface(buf, pUpper);
  278. PAL_MKFDecompressChunk(buf, 64000, 62, gpGlobals->f.fpFBP);
  279. PAL_FBPBlitToSurface(buf, pLower);
  280. PAL_MKFDecompressChunk(buf, 64000, 571, gpGlobals->f.fpMGO);
  281. PAL_MKFDecompressChunk(bufGirl, 6000, 572, gpGlobals->f.fpMGO);
  282. srcrect.x = 0;
  283. dstrect.x = 0;
  284. srcrect.w = 320;
  285. dstrect.w = 320;
  286. gpGlobals->wScreenWave = 2;
  287. for (i = 0; i < 400; i++)
  288. {
  289. //
  290. // Draw the background
  291. //
  292. srcrect.y = 0;
  293. srcrect.h = 200 - i / 2;
  294. dstrect.y = i / 2;
  295. dstrect.h = 200 - i / 2;
  296. SDL_BlitSurface(pLower, &srcrect, gpScreen, &dstrect);
  297. srcrect.y = 200 - i / 2;
  298. srcrect.h = i / 2;
  299. dstrect.y = 0;
  300. dstrect.h = i / 2;
  301. SDL_BlitSurface(pUpper, &srcrect, gpScreen, &dstrect);
  302. PAL_ApplyWave(gpScreen);
  303. //
  304. // Draw the beast
  305. //
  306. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 0), gpScreen, PAL_XY(0, -400 + i));
  307. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 1), gpScreen, PAL_XY(0, -200 + i));
  308. //
  309. // Draw the girl
  310. //
  311. yPosGirl -= i & 1;
  312. if (yPosGirl < 80)
  313. {
  314. yPosGirl = 80;
  315. }
  316. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufGirl, (SDL_GetTicks() / 50) % 4),
  317. gpScreen, PAL_XY(220, yPosGirl));
  318. //
  319. // Update the screen
  320. //
  321. VIDEO_UpdateScreen(NULL);
  322. if (gpGlobals->fNeedToFadeIn)
  323. {
  324. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  325. gpGlobals->fNeedToFadeIn = FALSE;
  326. #if SDL_VERSION_ATLEAST(2, 0, 0)
  327. SDL_SetSurfacePalette(pUpper, gpScreen->format->palette);
  328. SDL_SetSurfacePalette(pLower, gpScreen->format->palette);
  329. #else
  330. SDL_SetPalette(pUpper, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256);
  331. SDL_SetPalette(pLower, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256);
  332. #endif
  333. }
  334. UTIL_Delay(50);
  335. }
  336. gpGlobals->wScreenWave = 0;
  337. SDL_FreeSurface(pUpper);
  338. SDL_FreeSurface(pLower);
  339. free(buf);
  340. free(bufGirl);
  341. }