ending.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. VIDEO_BackupScreen();
  161. PAL_FBPBlitToSurface(buf, p);
  162. if (wScrollSpeed == 0)
  163. {
  164. wScrollSpeed = 1;
  165. }
  166. rect.x = 0;
  167. rect.w = 320;
  168. dstrect.x = 0;
  169. dstrect.w = 320;
  170. for (l = 0; l < 220; l++)
  171. {
  172. i = l;
  173. if (i > 200)
  174. {
  175. i = 200;
  176. }
  177. if (fScrollDown)
  178. {
  179. rect.y = 0;
  180. dstrect.y = i;
  181. rect.h = 200 - i;
  182. dstrect.h = 200 - i;
  183. }
  184. else
  185. {
  186. rect.y = i;
  187. dstrect.y = 0;
  188. rect.h = 200 - i;
  189. dstrect.h = 200 - i;
  190. }
  191. SDL_BlitSurface(gpScreenBak, &rect, gpScreen, &dstrect);
  192. if (fScrollDown)
  193. {
  194. rect.y = 200 - i;
  195. dstrect.y = 0;
  196. rect.h = i;
  197. dstrect.h = i;
  198. }
  199. else
  200. {
  201. rect.y = 0;
  202. dstrect.y = 200 - i;
  203. rect.h = i;
  204. dstrect.h = i;
  205. }
  206. SDL_BlitSurface(p, &rect, gpScreen, &dstrect);
  207. PAL_ApplyWave(gpScreen);
  208. if (g_wCurEffectSprite != 0)
  209. {
  210. int f = SDL_GetTicks() / 150;
  211. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)),
  212. gpScreen, PAL_XY(0, 0));
  213. }
  214. VIDEO_UpdateScreen(NULL);
  215. if (gpGlobals->fNeedToFadeIn)
  216. {
  217. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  218. gpGlobals->fNeedToFadeIn = FALSE;
  219. }
  220. UTIL_Delay(800 / wScrollSpeed);
  221. }
  222. SDL_BlitSurface(p, NULL, gpScreen, NULL);
  223. SDL_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 = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  249. gpScreen->format->Rmask, gpScreen->format->Gmask,
  250. gpScreen->format->Bmask, gpScreen->format->Amask);
  251. pLower = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8,
  252. gpScreen->format->Rmask, gpScreen->format->Gmask,
  253. gpScreen->format->Bmask, gpScreen->format->Amask);
  254. PAL_MKFDecompressChunk(buf, 64000, 61, gpGlobals->f.fpFBP);
  255. PAL_FBPBlitToSurface(buf, pUpper);
  256. PAL_MKFDecompressChunk(buf, 64000, 62, gpGlobals->f.fpFBP);
  257. PAL_FBPBlitToSurface(buf, pLower);
  258. PAL_MKFDecompressChunk(buf, 64000, 571, gpGlobals->f.fpMGO);
  259. PAL_MKFDecompressChunk(bufGirl, 6000, 572, gpGlobals->f.fpMGO);
  260. srcrect.x = 0;
  261. dstrect.x = 0;
  262. srcrect.w = 320;
  263. dstrect.w = 320;
  264. gpGlobals->wScreenWave = 2;
  265. for (i = 0; i < 400; i++)
  266. {
  267. //
  268. // Draw the background
  269. //
  270. srcrect.y = 0;
  271. srcrect.h = 200 - i / 2;
  272. dstrect.y = i / 2;
  273. dstrect.h = 200 - i / 2;
  274. SDL_BlitSurface(pLower, &srcrect, gpScreen, &dstrect);
  275. srcrect.y = 200 - i / 2;
  276. srcrect.h = i / 2;
  277. dstrect.y = 0;
  278. dstrect.h = i / 2;
  279. SDL_BlitSurface(pUpper, &srcrect, gpScreen, &dstrect);
  280. PAL_ApplyWave(gpScreen);
  281. //
  282. // Draw the beast
  283. //
  284. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 0), gpScreen, PAL_XY(0, -400 + i));
  285. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 1), gpScreen, PAL_XY(0, -200 + i));
  286. //
  287. // Draw the girl
  288. //
  289. yPosGirl -= i & 1;
  290. if (yPosGirl < 80)
  291. {
  292. yPosGirl = 80;
  293. }
  294. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufGirl, (SDL_GetTicks() / 50) % 4),
  295. gpScreen, PAL_XY(220, yPosGirl));
  296. //
  297. // Update the screen
  298. //
  299. VIDEO_UpdateScreen(NULL);
  300. if (gpGlobals->fNeedToFadeIn)
  301. {
  302. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  303. gpGlobals->fNeedToFadeIn = FALSE;
  304. }
  305. UTIL_Delay(50);
  306. }
  307. gpGlobals->wScreenWave = 0;
  308. SDL_FreeSurface(pUpper);
  309. SDL_FreeSurface(pLower);
  310. free(buf);
  311. free(bufGirl);
  312. }