ending.c 9.5 KB

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