ending.c 9.2 KB

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