Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1384 lines
41 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (c) 1995 - 1997 Microsoft Corporation. All Rights Reserved.
  4. * Copyright (C) 1994-1995 ATI Technologies Inc. All Rights Reserved.
  5. *
  6. * File: gameproc.c
  7. * Content: Game processing routines
  8. *
  9. ***************************************************************************/
  10. #include "foxbear.h"
  11. GFX_HBM hBuffer;
  12. HBITMAPLIST *hBitmapList;
  13. HBITMAPLIST *hTileList;
  14. HPOSLIST *hForePosList;
  15. HPOSLIST *hMidPosList;
  16. HPOSLIST *hBackPosList;
  17. HSURFACELIST *hSurfaceList;
  18. HPLANE *hForeground;
  19. HPLANE *hMidground;
  20. HPLANE *hBackground;
  21. HSPRITE *hFox;
  22. HSPRITE *hBear;
  23. HSPRITE *hApple;
  24. USHORT chewCount;
  25. LONG chewDif;
  26. IDirectDrawStreamSample *g_pMovieSource = NULL;
  27. /*
  28. * ErrorMessage
  29. */
  30. void ErrorMessage( CHAR *pText )
  31. {
  32. char ach[128];
  33. wsprintf( ach, "FOXBEAR FATAL ERROR: %s\r\n", pText );
  34. OutputDebugString(ach);
  35. gfxEnd( hBuffer );
  36. exit( 0 );
  37. } /* ErrorMessage */
  38. /*
  39. * InitBuffer
  40. */
  41. BOOL InitBuffer( GFX_HBM *hBuffer )
  42. {
  43. *hBuffer = gfxBegin();
  44. if( *hBuffer == NULL )
  45. {
  46. ErrorMessage( "gfxBegin failed" );
  47. return FALSE;
  48. }
  49. return TRUE;
  50. } /* InitBuffer */
  51. /*
  52. * DestroyBuffer
  53. */
  54. void DestroyBuffer ( GFX_HBM hBuffer )
  55. {
  56. if( gfxEnd( hBuffer ) == FALSE )
  57. {
  58. ErrorMessage( "gfxEnd in DestroyBuffer" );
  59. }
  60. } /* DestroyBuffer */
  61. /*
  62. * LoadBitmaps
  63. */
  64. HBITMAPLIST *LoadBitmaps( void )
  65. {
  66. HBITMAPLIST *hBitmapList;
  67. CHAR fileName[32];
  68. USHORT i;
  69. USHORT n;
  70. if( !FastFileInit( "foxbear.art", 5 ) )
  71. {
  72. Msg( "Could not load art file err=%08lX" , GetLastError());
  73. return NULL;
  74. }
  75. hBitmapList = CMemAlloc( C_TILETOTAL + C_FBT + C_BBT, sizeof (HBITMAPLIST) );
  76. Msg( "Loading tiles" );
  77. for( i = 0; i < C_TILETOTAL; ++i )
  78. {
  79. wsprintf( fileName, "%03u.BMP", i + 1 );
  80. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  81. }
  82. n = C_TILETOTAL;
  83. Msg( "Loading FoxWalk" );
  84. for( i = n; i < n + C_FOXWALK; ++i )
  85. {
  86. wsprintf( fileName, "FW%02uR.BMP", i - n + 1 );
  87. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  88. }
  89. n += C_FOXWALK;
  90. Msg( "Loading FoxWalk2" );
  91. for( i = n; i < n + C_FOXWALK; ++i )
  92. {
  93. wsprintf( fileName, "FW%02uL.BMP", i - n + 1 );
  94. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  95. }
  96. n += C_FOXWALK;
  97. Msg( "Loading FoxRun" );
  98. for( i = n; i < n + C_FOXRUN; ++i )
  99. {
  100. wsprintf( fileName, "FR%02uR.BMP", i - n + 1 );
  101. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  102. }
  103. n += C_FOXRUN;
  104. Msg( "Loading FoxRun2" );
  105. for( i = n; i < n + C_FOXRUN; ++i )
  106. {
  107. wsprintf( fileName, "FR%02uL.BMP", i - n + 1 );
  108. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  109. }
  110. n += C_FOXRUN;
  111. Msg( "Loading FoxStill" );
  112. for( i = n; i < n + C_FOXSTILL; ++i )
  113. {
  114. wsprintf( fileName, "FS%1uR.BMP", i - n + 1 );
  115. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  116. }
  117. n += C_FOXSTILL;
  118. Msg( "Loading FoxStill2" );
  119. for( i = n; i < n + C_FOXSTILL; ++i )
  120. {
  121. wsprintf( fileName, "FS%1uL.BMP", i - n + 1 );
  122. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  123. }
  124. n += C_FOXSTILL;
  125. Msg( "Loading FoxStunned" );
  126. for( i = n; i < n + C_FOXSTUNNED; ++i )
  127. {
  128. wsprintf( fileName, "FK%1uR.BMP", i - n + 1 );
  129. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  130. }
  131. n += C_FOXSTUNNED;
  132. Msg( "Loading FoxStunned2" );
  133. for( i = n; i < n + C_FOXSTUNNED; ++i )
  134. {
  135. wsprintf( fileName, "FK%1uL.BMP", i - n + 1 );
  136. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  137. }
  138. n += C_FOXSTUNNED;
  139. Msg( "Loading FoxCrouch" );
  140. for( i = n; i < n + C_FOXCROUCH; ++i )
  141. {
  142. wsprintf( fileName, "FC%1uR.BMP", i - n + 1 );
  143. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  144. }
  145. n += C_FOXCROUCH;
  146. Msg( "Loading FoxCrouch2" );
  147. for( i = n; i < n + C_FOXCROUCH; ++i )
  148. {
  149. wsprintf( fileName, "FC%1uL.BMP", i - n + 1 );
  150. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  151. }
  152. n += C_FOXCROUCH;
  153. Msg( "Loading FoxStop" );
  154. for( i = n; i < n + C_FOXSTOP; ++i )
  155. {
  156. wsprintf( fileName, "FCD%1uR.BMP", i - n + 1 );
  157. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  158. }
  159. n += C_FOXSTOP;
  160. Msg( "Loading FoxStop2" );
  161. for( i = n; i < n + C_FOXSTOP; ++i )
  162. {
  163. wsprintf( fileName, "FCD%1uL.BMP", i - n + 1 );
  164. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  165. }
  166. n += C_FOXSTOP;
  167. Msg( "Loading FoxThrow" );
  168. for( i = n; i < n + C_FOXTHROW; ++i )
  169. {
  170. wsprintf( fileName, "FT%1uR.BMP", i - n + 1 );
  171. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  172. }
  173. n += C_FOXTHROW;
  174. Msg( "Loading FoxThrow2" );
  175. for( i = n; i < n + C_FOXTHROW; ++i )
  176. {
  177. wsprintf( fileName, "FT%1uL.BMP", i - n + 1 );
  178. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  179. }
  180. n += C_FOXTHROW;
  181. Msg( "Loading FoxJumpThrow" );
  182. for( i = n; i < n + C_FOXJUMPTHROW; ++i )
  183. {
  184. wsprintf( fileName, "FJT%1uR.BMP", i - n + 1 );
  185. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  186. }
  187. n += C_FOXJUMPTHROW;
  188. Msg( "Loading FoxJumpThrow2" );
  189. for( i = n; i < n + C_FOXJUMPTHROW; ++i )
  190. {
  191. wsprintf( fileName, "FJT%1uL.BMP", i - n + 1 );
  192. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  193. }
  194. n += C_FOXJUMPTHROW;
  195. Msg( "Loading FoxJump" );
  196. for( i = n; i < n + C_FOXJUMP; ++i )
  197. {
  198. wsprintf( fileName, "FJ%1uR.BMP", i - n + 1 );
  199. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  200. }
  201. n += C_FOXJUMP;
  202. Msg( "Loading FoxJump2" );
  203. for( i = n; i < n + C_FOXJUMP; ++i )
  204. {
  205. wsprintf( fileName, "FJ%1uL.BMP", i - n + 1 );
  206. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  207. }
  208. n += C_FOXJUMP;
  209. Msg( "Loading FoxCrouchWalk" );
  210. for( i = n; i < n + C_FOXCROUCHWALK; ++i )
  211. {
  212. wsprintf( fileName, "FCW%02uR.BMP", i - n + 1 );
  213. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  214. }
  215. n += C_FOXCROUCHWALK;
  216. Msg( "Loading FoxCrouchWalk2" );
  217. for( i = n; i < n + C_FOXCROUCHWALK; ++i )
  218. {
  219. wsprintf( fileName, "FCW%02uL.BMP", i - n + 1 );
  220. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  221. }
  222. n += C_FOXCROUCHWALK;
  223. Msg( "Loading FoxBlurr" );
  224. for( i = n; i < n + C_FOXBLURR; ++i )
  225. {
  226. wsprintf( fileName, "FB%02uR.BMP", i - n + 1 );
  227. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  228. }
  229. n += C_FOXBLURR;
  230. Msg( "Loading FoxBlurr2" );
  231. for( i = n; i < n + C_FOXBLURR; ++i )
  232. {
  233. wsprintf( fileName, "FB%02uL.BMP", i - n + 1 );
  234. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  235. }
  236. n += C_FOXBLURR;
  237. Msg( "Loading BearMiss" );
  238. for( i = n; i < n + C_BEARMISS; ++i )
  239. {
  240. wsprintf( fileName, "BM%1uL.BMP", i - n + 1 );
  241. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  242. }
  243. n += C_BEARMISS;
  244. Msg( "Loading BearStrike" );
  245. for( i = n; i < n + C_BEARSTRIKE; ++i )
  246. {
  247. wsprintf( fileName, "BS%02uL.BMP", i - n + 1 );
  248. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  249. }
  250. n += C_BEARSTRIKE;
  251. Msg( "Loading BearWalk" );
  252. for( i = n; i < n + C_BEARWALK; ++i )
  253. {
  254. wsprintf( fileName, "BW%02uL.BMP", i - n + 1 );
  255. hBitmapList[i].hBM = gfxLoadBitmap( fileName );
  256. }
  257. n += C_BEARWALK;
  258. FastFileFini();
  259. return hBitmapList;
  260. } /* LoadBitmaps */
  261. /*
  262. * InitTiles
  263. */
  264. void InitTiles(
  265. HBITMAPLIST **hTileList,
  266. HBITMAPLIST *hBitmapList,
  267. USHORT tileCount )
  268. {
  269. *hTileList = CreateTiles( hBitmapList, tileCount );
  270. } /* InitTiles */
  271. /*
  272. * InitPlane
  273. */
  274. void InitPlane(
  275. HPLANE **hPlane,
  276. HPOSLIST **hPosList,
  277. LPSTR szFileName,
  278. USHORT width,
  279. USHORT height,
  280. USHORT denom )
  281. {
  282. *hPlane = CreatePlane( width, height, denom );
  283. *hPosList = CreatePosList( szFileName, width, height );
  284. } /* InitPlane */
  285. /*
  286. * InitSurface
  287. */
  288. void InitSurface(
  289. HSURFACELIST **pphSurfaceList,
  290. CHAR *szFileName,
  291. USHORT width,
  292. USHORT height )
  293. {
  294. *pphSurfaceList = CreateSurfaceList( szFileName, width, height );
  295. } /* InitSurface */
  296. /*
  297. * InitFox
  298. */
  299. void InitFox ( HSPRITE **pphFox, HBITMAPLIST *phBitmapList )
  300. {
  301. GFX_HBM hBM;
  302. GFX_HBM hBM_src;
  303. ACTION action;
  304. DIRECTION direction;
  305. USHORT i;
  306. LONG startX = C_FOX_STARTX;
  307. LONG startY = C_FOX_STARTY;
  308. USHORT boundW = 108;
  309. USHORT boundH = 105;
  310. LONG as = 6;
  311. SHORT x[C_FBT] = { 7, 15, 18, 11, 6, 3, 7, 15, 17, 11, 6, 3,
  312. 7, 15, 18, 11, 6, 3, 7, 15, 17, 11, 6, 3,
  313. 10, 3, 5, 16, 9, 13, 31, 24, 9, 3, 5, 16, 10, 13, 33, 23,
  314. 10, 3, 5, 16, 9, 13, 31, 24, 9, 3, 5, 16, 10, 13, 33, 23,
  315. 11, 11, 31, 31, 7, 7, 27, 27, 8, 10, 8, 10,
  316. 26, 6, 26, 6, 17, 21, 21, 24, 17, 21, 21, 24,
  317. 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1,
  318. 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1,
  319. 2, 2, -1, 0, 2, 2, -1, 0 };
  320. SHORT y[C_FBT] = { 20, 24, 26, 25, 27, 19, 20, 25, 26, 25, 29, 21,
  321. 20, 24, 26, 25, 27, 19, 20, 25, 26, 25, 29, 21,
  322. 42, 42, 31, 19, 13, 11, 20, 33, 40, 43, 31, 19, 14, 12, 20, 33,
  323. 42, 42, 31, 19, 13, 11, 20, 33, 40, 43, 31, 19, 14, 12, 20, 33,
  324. 14, 14, 20, 20, 58, 58, 26, 26, 20, 24, 20, 24,
  325. 0, 9, 0, 9, 20, 11, 10, 9, 20, 11, 10, 9,
  326. 61, 61, 61, 61, 60, 60, 61, 61, 61, 61, 60, 60,
  327. 61, 61, 61, 61, 60, 60, 61, 61, 61, 61, 60, 60,
  328. 45, 45, 45, 45, 45, 45, 45, 45 };
  329. USHORT w[C_FBT] = { 75, 73, 73, 82, 92, 84, 74, 74, 73, 81, 91, 84,
  330. 75, 73, 73, 82, 92, 84, 74, 74, 73, 81, 91, 84,
  331. 88, 92, 88, 78, 80, 78, 70, 84, 88, 92, 88, 78, 79, 79, 68, 85,
  332. 88, 92, 88, 78, 80, 78, 70, 84, 88, 92, 88, 78, 79, 79, 68, 85,
  333. 65, 65, 61, 61, 88, 88, 72, 72, 57, 86, 57, 86,
  334. 54, 92, 54, 92, 59, 57, 57, 52, 59, 57, 57, 52,
  335. 98, 99, 99, 99,100,100, 98,101,100, 99,100, 98,
  336. 98, 99, 99, 99,100,100, 98,101,100, 99,100, 98,
  337. 94, 94, 97, 96, 94, 94, 97, 96 };
  338. USHORT h[C_FBT] = { 78, 74, 72, 73, 71, 79, 78, 73, 72, 73, 69, 77,
  339. 78, 74, 72, 73, 71, 79, 78, 73, 72, 73, 69, 77,
  340. 56, 56, 67, 79, 85, 87, 78, 65, 58, 55, 67, 79, 84, 86, 78, 65,
  341. 56, 56, 67, 79, 85, 87, 78, 65, 58, 55, 67, 79, 84, 86, 78, 65,
  342. 84, 84, 85, 85, 40, 40, 72, 72, 78, 74, 78, 74,
  343. 88, 82, 88, 82, 84, 87, 86, 85, 84, 87, 86, 85,
  344. 37, 37, 37, 37, 38, 38, 37, 37, 37, 37, 38, 38,
  345. 37, 37, 37, 37, 38, 38, 37, 37, 37, 37, 38, 38,
  346. 54, 53, 51, 54, 54, 53, 51, 54 };
  347. *pphFox = CreateSprite( C_FBT, startX, startY, boundW, boundH, C_FORE_W * C_TILE_W, C_FORE_H * C_TILE_H, (SHORT) as, TRUE);
  348. for( i = 0; i < C_FBT; ++i )
  349. {
  350. hBM_src = phBitmapList[i + C_TILETOTAL].hBM;
  351. if( i < 12 )
  352. {
  353. action = WALK;
  354. direction = RIGHT;
  355. }
  356. else if( (i >= 12) && (i < 24) )
  357. {
  358. action = WALK;
  359. direction = LEFT;
  360. }
  361. else if( (i >= 24) && (i < 40) )
  362. {
  363. action = RUN;
  364. direction = RIGHT;
  365. }
  366. else if( (i >= 40) && (i < 56) )
  367. {
  368. action = RUN;
  369. direction = LEFT;
  370. }
  371. else if( i == 56 )
  372. {
  373. action = STILL;
  374. direction = RIGHT;
  375. }
  376. else if( i == 57 )
  377. {
  378. action = STILL;
  379. direction = LEFT;
  380. }
  381. else if( i == 58 )
  382. {
  383. action = STUNNED;
  384. direction = RIGHT;
  385. }
  386. else if( i == 59 )
  387. {
  388. action = STUNNED;
  389. direction = LEFT;
  390. }
  391. else if( i == 60 )
  392. {
  393. action = CROUCH;
  394. direction = RIGHT;
  395. }
  396. else if( i == 61 )
  397. {
  398. action = CROUCH;
  399. direction = LEFT;
  400. }
  401. else if( i == 62 )
  402. {
  403. action = STOP;
  404. direction = RIGHT;
  405. }
  406. else if( i == 63 )
  407. {
  408. action = STOP;
  409. direction = LEFT;
  410. }
  411. else if( (i >= 64) && (i < 66) )
  412. {
  413. action = THROW;
  414. direction = RIGHT;
  415. }
  416. else if( (i >= 66) && (i < 68) )
  417. {
  418. action = THROW;
  419. direction = LEFT;
  420. }
  421. else if( (i >= 68) && (i < 70) )
  422. {
  423. action = JUMPTHROW;
  424. direction = RIGHT;
  425. }
  426. else if( (i >= 70) && (i < 72) )
  427. {
  428. action = JUMPTHROW;
  429. direction = LEFT;
  430. }
  431. else if( (i >= 72) && (i < 76) )
  432. {
  433. action = JUMP;
  434. direction = RIGHT;
  435. }
  436. else if( (i >= 76) && (i < 80) )
  437. {
  438. action = JUMP;
  439. direction = LEFT;
  440. }
  441. else if( (i >= 80) && (i < 92) )
  442. {
  443. action = CROUCHWALK;
  444. direction = RIGHT;
  445. }
  446. else if( (i >= 92) && (i < 104) )
  447. {
  448. action = CROUCHWALK;
  449. direction = LEFT;
  450. }
  451. else if( (i >= 104) && (i < 108) )
  452. {
  453. action = BLURR;
  454. direction = RIGHT;
  455. }
  456. else if( (i >= 108) && (i < 112) )
  457. {
  458. action = BLURR;
  459. direction = LEFT;
  460. }
  461. hBM = hBM_src;
  462. BitBltSprite(
  463. *pphFox,
  464. hBM,
  465. action,
  466. direction,
  467. x[i],
  468. y[i],
  469. w[i],
  470. h[i] );
  471. }
  472. SetSpriteAction( *pphFox, STILL, RIGHT );
  473. } /* InitFox */
  474. /*
  475. * InitBear
  476. */
  477. void InitBear( HSPRITE **pphBear, HBITMAPLIST *phBitmapList )
  478. {
  479. GFX_HBM hBM_src;
  480. ACTION action;
  481. DIRECTION direction;
  482. USHORT i;
  483. LONG startX = C_BEAR_STARTX;
  484. LONG startY = C_BEAR_STARTY;
  485. USHORT boundW = 196;
  486. USHORT boundH = 88;
  487. LONG as = 6;
  488. USHORT x[C_BBT] = { 14, 10,
  489. 8, 12, 13, 14, 10, 10, 9, 9, 9, 9, 8, 9,
  490. 11, 6, 1, 0, 3, 13, 11, 7, 1, 1, 3, 14 };
  491. USHORT y[C_BBT] = { 7, 7,
  492. 3, 8, 9, 7, 7, 3, 3, 3, 3, 3, 3, 3,
  493. 1, 1, 2, 2, 3, 1, 0, 1, 1, 2, 3, 2 };
  494. USHORT w[C_BBT] = {127,129,
  495. 127,153,183,153,129,138,146,150,152,151,143,139,
  496. 131,136,140,141,136,125,131,135,140,140,136,126 };
  497. USHORT h[C_BBT] = { 80, 80,
  498. 84, 79, 78, 80, 80, 84, 84, 84, 84, 84, 84, 84,
  499. 86, 86, 86, 85, 84, 86, 87, 86, 87, 85, 84, 86 };
  500. *pphBear = CreateSprite( C_BBT, startX, startY, boundW, boundH, C_FORE_W * C_TILE_W, C_FORE_H * C_TILE_H, (SHORT) as, TRUE);
  501. for( i = 0; i < C_BBT; ++i )
  502. {
  503. hBM_src = phBitmapList[i + C_TILETOTAL + C_FBT].hBM;
  504. if( i < 2 )
  505. {
  506. action = MISS;
  507. direction = LEFT;
  508. }
  509. else if( (i >= 2) && (i < 8) )
  510. {
  511. action = STRIKE;
  512. direction = LEFT;
  513. }
  514. else if( (i >= 8) && (i < 14) )
  515. {
  516. action = CHEW;
  517. direction = LEFT;
  518. }
  519. else if( (i >= 14) && (i < 26) )
  520. {
  521. action = WALK;
  522. direction = LEFT;
  523. }
  524. BitBltSprite (
  525. *pphBear,
  526. hBM_src,
  527. action,
  528. direction,
  529. x[i],
  530. y[i],
  531. w[i],
  532. h[i] );
  533. }
  534. SetSpriteAction( *pphBear, WALK, LEFT );
  535. SetSpriteVelX( *pphBear, -C_BEAR_WALKMOVE, P_ABSOLUTE );
  536. SetSpriteSwitch( *pphBear, C_BEAR_WALKSWITCH, P_ABSOLUTE );
  537. } /* InitBear */
  538. /*
  539. * InitApple
  540. */
  541. VOID InitApple ( HSPRITE **pphApple, HBITMAPLIST *phBitmapList )
  542. {
  543. // CREATE THE DIRECTDRAW SOURCE HERE!!! AND REPLACE FINAL NULL WITH POITNER!
  544. *pphApple = CreateSprite( 1, 50 * C_UNIT, 390 * C_UNIT, 32, 32, C_FORE_W * C_TILE_W, C_FORE_H * C_TILE_H, 0, FALSE);
  545. BitBltSprite( *pphApple, phBitmapList[61].hBM, NONE, RIGHT, 0, 0, 32, 32 );
  546. SetSpriteAction( *pphApple, NONE, RIGHT );
  547. } /* InitApple */
  548. /*
  549. * PreInitializeGame
  550. */
  551. BOOL PreInitializeGame( void )
  552. {
  553. return InitBuffer( &hBuffer);
  554. } /* PreInitializeGame */
  555. /*
  556. * InitializeGame
  557. */
  558. BOOL InitializeGame ( void )
  559. {
  560. CoInitialize(NULL);
  561. Splash();
  562. hBitmapList = LoadBitmaps();
  563. if( hBitmapList == NULL )
  564. {
  565. return FALSE;
  566. }
  567. InitTiles( &hTileList, hBitmapList, C_TILETOTAL );
  568. InitPlane( &hForeground, &hForePosList, "FORELIST", C_FORE_W, C_FORE_H, C_FORE_DENOM );
  569. TilePlane( hForeground, hTileList, hForePosList );
  570. InitPlane( &hMidground, &hMidPosList, "MIDLIST", C_MID_W, C_MID_H, C_MID_DENOM );
  571. TilePlane( hMidground, hTileList, hMidPosList );
  572. InitPlane( &hBackground, &hBackPosList, "BACKLIST", C_BACK_W, C_BACK_H, C_BACK_DENOM );
  573. TilePlane( hBackground, hTileList, hBackPosList );
  574. InitSurface( &hSurfaceList, "SURFLIST", C_FORE_W, C_FORE_H );
  575. SurfacePlane( hForeground, hSurfaceList );
  576. InitFox( &hFox, hBitmapList );
  577. InitBear( &hBear, hBitmapList );
  578. InitApple( &hApple, hBitmapList );
  579. CreateVideoSource (&g_pMovieSource, L"\\msamovdk\\movies\\aninm.mpg");
  580. DDClear(); // clear all the backbuffers.
  581. return TRUE;
  582. } /* InitializeGame */
  583. extern void DisplayFrameRate( void );
  584. /*
  585. * NewGameFrame
  586. */
  587. int NewGameFrame( void )
  588. {
  589. SetSpriteX( hFox, 0, P_AUTOMATIC );
  590. SetSpriteY( hFox, 0, P_AUTOMATIC );
  591. SetPlaneVelX( hBackground, GetSpriteVelX(hFox), P_ABSOLUTE );
  592. SetPlaneVelX( hMidground, GetSpriteVelX(hFox), P_ABSOLUTE );
  593. SetPlaneVelX( hForeground, GetSpriteVelX(hFox), P_ABSOLUTE );
  594. SetPlaneX( hBackground, 0, P_AUTOMATIC );
  595. SetPlaneX( hMidground, 0, P_AUTOMATIC );
  596. SetPlaneX( hForeground, 0, P_AUTOMATIC );
  597. SetSpriteX( hBear, 0, P_AUTOMATIC );
  598. SetSpriteX( hApple, 0, P_AUTOMATIC );
  599. SetSpriteY( hApple, 0, P_AUTOMATIC );
  600. /*
  601. * once all sprites are processed, display them
  602. *
  603. * If we are using destination transparency instead of source
  604. * transparency, we need to paint the background with the color key
  605. * and then paint our sprites and planes in reverse order.
  606. *
  607. * Since destination transparency will allow you to only write pixels
  608. * on the destination if the transparent color is present, reversing
  609. * the order (so that the topmost bitmaps are drawn first instead of
  610. * list) causes everything to come out ok.
  611. */
  612. if( bTransDest )
  613. {
  614. gfxFillBack( dwColorKey );
  615. DisplayFrameRate();
  616. DisplaySprite( hBuffer, hApple, GetPlaneX(hForeground) );
  617. DisplaySprite( hBuffer, hBear, GetPlaneX(hForeground) );
  618. DisplaySprite( hBuffer, hFox, GetPlaneX(hForeground) );
  619. DisplayPlane( hBuffer, hForeground );
  620. DisplayPlane( hBuffer, hMidground );
  621. DisplayPlane( hBuffer, hBackground );
  622. }
  623. else
  624. {
  625. DisplayPlane( hBuffer, hBackground );
  626. DisplayPlane( hBuffer, hMidground );
  627. DisplayVideoSource(g_pMovieSource);
  628. DisplayPlane( hBuffer, hForeground );
  629. DisplaySprite( hBuffer, hFox, GetPlaneX(hForeground) );
  630. DisplaySprite( hBuffer, hBear, GetPlaneX(hForeground) );
  631. DisplaySprite( hBuffer, hApple, GetPlaneX(hForeground) );
  632. DisplayFrameRate();
  633. }
  634. gfxSwapBuffers();
  635. return 0;
  636. } /* NewGameFrame */
  637. /*
  638. * DestroyGame
  639. */
  640. void DestroyGame()
  641. {
  642. if (hBuffer)
  643. {
  644. DestroyTiles( hTileList );
  645. DestroyPlane( hForeground );
  646. DestroyPlane( hMidground );
  647. DestroyPlane( hBackground );
  648. DestroyBuffer( hBuffer );
  649. DestroySound();
  650. if (g_pMovieSource) {
  651. IDirectDrawStreamSample_Release(g_pMovieSource);
  652. g_pMovieSource = NULL;
  653. }
  654. hTileList = NULL;
  655. hForeground = NULL;
  656. hMidground = NULL;
  657. hBackground = NULL;
  658. hBuffer = NULL;
  659. }
  660. } /* DestroyGame */
  661. /*
  662. * ProcessInput
  663. */
  664. BOOL ProcessInput( SHORT input )
  665. {
  666. static BOOL fBearPlaying = FALSE;
  667. LONG foxSpeedX;
  668. LONG foxSpeedY;
  669. LONG foxX;
  670. LONG foxY;
  671. LONG bearX;
  672. LONG bearY;
  673. LONG appleX;
  674. LONG appleY;
  675. ACTION foxAction;
  676. DIRECTION foxDir;
  677. BOOL cont = TRUE;
  678. foxSpeedX = GetSpriteVelX( hFox );
  679. foxAction = GetSpriteAction( hFox );
  680. foxDir = GetSpriteDirection( hFox );
  681. if( (GetSpriteActive(hFox) == FALSE) && (input != 4209) )
  682. {
  683. input = 0;
  684. }
  685. switch( input )
  686. {
  687. case KEY_DOWN:
  688. if( foxAction == STOP )
  689. {
  690. break;
  691. }
  692. else if( foxAction == STILL )
  693. {
  694. SetSpriteAction( hFox, CROUCH, SAME );
  695. }
  696. else if( foxAction == WALK )
  697. {
  698. SetSpriteAction( hFox, CROUCHWALK, SAME );
  699. }
  700. break;
  701. case KEY_LEFT:
  702. if( foxAction == STOP )
  703. {
  704. break;
  705. }
  706. else if( foxSpeedX == 0 )
  707. {
  708. if( foxAction == STILL )
  709. {
  710. if( foxDir == RIGHT )
  711. {
  712. ChangeSpriteDirection( hFox );
  713. SetPlaneSlideX( hForeground, -C_BOUNDDIF, P_RELATIVE );
  714. SetPlaneSlideX( hMidground, -C_BOUNDDIF, P_RELATIVE );
  715. SetPlaneSlideX( hBackground, -C_BOUNDDIF, P_RELATIVE );
  716. SetPlaneIncremX( hForeground, C_BOUNDINCREM, P_ABSOLUTE );
  717. SetPlaneIncremX( hBackground, C_BOUNDINCREM, P_ABSOLUTE );
  718. SetPlaneIncremX( hMidground, C_BOUNDINCREM, P_ABSOLUTE );
  719. }
  720. else
  721. {
  722. SetSpriteAction( hFox, WALK, LEFT );
  723. SetSpriteSwitch( hFox, C_FOX_WALKSWITCH, P_ABSOLUTE );
  724. SetSpriteVelX( hFox, -C_FOX_XMOVE, P_RELATIVE );
  725. }
  726. }
  727. else if( foxAction == CROUCH )
  728. {
  729. if( foxDir == RIGHT )
  730. {
  731. ChangeSpriteDirection( hFox );
  732. SetPlaneSlideX( hForeground, -C_BOUNDDIF, P_RELATIVE );
  733. SetPlaneSlideX( hMidground, -C_BOUNDDIF, P_RELATIVE );
  734. SetPlaneSlideX( hBackground, -C_BOUNDDIF, P_RELATIVE );
  735. SetPlaneIncremX( hForeground, C_BOUNDINCREM, P_ABSOLUTE );
  736. SetPlaneIncremX( hBackground, C_BOUNDINCREM, P_ABSOLUTE );
  737. SetPlaneIncremX( hMidground, C_BOUNDINCREM, P_ABSOLUTE );
  738. }
  739. else
  740. {
  741. SetSpriteAction( hFox, CROUCHWALK, LEFT );
  742. SetSpriteSwitch( hFox, C_FOX_WALKSWITCH, P_ABSOLUTE );
  743. SetSpriteVelX( hFox, -C_FOX_XMOVE, P_RELATIVE );
  744. }
  745. }
  746. else
  747. {
  748. SetSpriteVelX( hFox, -C_FOX_XMOVE, P_RELATIVE );
  749. }
  750. } else {
  751. SetSpriteVelX( hFox, -C_FOX_XMOVE, P_RELATIVE );
  752. }
  753. break;
  754. case KEY_RIGHT:
  755. if( foxAction == STOP )
  756. {
  757. break;
  758. }
  759. else if( foxSpeedX == 0 )
  760. {
  761. if( foxAction == STILL )
  762. {
  763. if( foxDir == LEFT )
  764. {
  765. ChangeSpriteDirection( hFox );
  766. SetPlaneSlideX( hForeground, C_BOUNDDIF, P_RELATIVE );
  767. SetPlaneSlideX( hMidground, C_BOUNDDIF, P_RELATIVE );
  768. SetPlaneSlideX( hBackground, C_BOUNDDIF, P_RELATIVE );
  769. SetPlaneIncremX( hForeground, C_BOUNDINCREM, P_ABSOLUTE );
  770. SetPlaneIncremX( hBackground, C_BOUNDINCREM, P_ABSOLUTE );
  771. SetPlaneIncremX( hMidground, C_BOUNDINCREM, P_ABSOLUTE );
  772. }
  773. else
  774. {
  775. SetSpriteAction( hFox, WALK, RIGHT );
  776. SetSpriteSwitch( hFox, C_FOX_WALKSWITCH, P_ABSOLUTE );
  777. SetSpriteVelX( hFox, C_FOX_XMOVE, P_RELATIVE );
  778. }
  779. }
  780. else if( foxAction == CROUCH )
  781. {
  782. if( foxDir == LEFT )
  783. {
  784. ChangeSpriteDirection( hFox );
  785. SetPlaneSlideX( hForeground, C_BOUNDDIF, P_RELATIVE );
  786. SetPlaneSlideX( hMidground, C_BOUNDDIF, P_RELATIVE );
  787. SetPlaneSlideX( hBackground, C_BOUNDDIF, P_RELATIVE );
  788. SetPlaneIncremX( hForeground, C_BOUNDINCREM, P_ABSOLUTE );
  789. SetPlaneIncremX( hBackground, C_BOUNDINCREM, P_ABSOLUTE );
  790. SetPlaneIncremX( hMidground, C_BOUNDINCREM, P_ABSOLUTE );
  791. }
  792. else
  793. {
  794. SetSpriteAction( hFox, CROUCHWALK, RIGHT );
  795. SetSpriteSwitch( hFox, C_FOX_WALKSWITCH, P_ABSOLUTE );
  796. SetSpriteVelX( hFox, C_FOX_XMOVE, P_RELATIVE );
  797. }
  798. }
  799. else
  800. {
  801. SetSpriteVelX( hFox, C_FOX_XMOVE, P_RELATIVE );
  802. }
  803. }
  804. else
  805. {
  806. SetSpriteVelX( hFox, C_FOX_XMOVE, P_RELATIVE );
  807. }
  808. break;
  809. case KEY_STOP:
  810. if( foxAction == STOP )
  811. {
  812. break;
  813. }
  814. else if( (foxAction == RUN) || (foxAction == BLURR) )
  815. {
  816. SetSpriteAction( hFox, STOP, SAME );
  817. SetSpriteAccX( hFox, -foxSpeedX / 25, P_ABSOLUTE );
  818. SoundPlayEffect( SOUND_STOP );
  819. } else {
  820. SetSpriteVelX( hFox, 0, P_ABSOLUTE );
  821. }
  822. break;
  823. case KEY_UP:
  824. if( foxAction == STOP )
  825. {
  826. break;
  827. }
  828. else if( foxAction == CROUCH )
  829. {
  830. SetSpriteAction( hFox, STILL, SAME );
  831. }
  832. else if( foxAction == CROUCHWALK )
  833. {
  834. SetSpriteAction( hFox, WALK, SAME );
  835. }
  836. break;
  837. case KEY_JUMP:
  838. if( foxAction == STOP )
  839. {
  840. break;
  841. }
  842. else
  843. if( (foxAction == STILL) || (foxAction == WALK) ||
  844. (foxAction == RUN) || (foxAction == CROUCH) ||
  845. (foxAction == CROUCHWALK) )
  846. {
  847. SetSpriteAction( hFox, JUMP, SAME );
  848. SetSpriteSwitchType( hFox, TIMESWITCH );
  849. SetSpriteSwitch( hFox, C_FOX_JUMPSWITCH, P_ABSOLUTE );
  850. SetSpriteVelY( hFox, -C_FOX_JUMPMOVE, P_ABSOLUTE );
  851. SetSpriteAccY( hFox, C_UNIT / 2, P_ABSOLUTE );
  852. SoundPlayEffect( SOUND_JUMP );
  853. }
  854. break;
  855. case KEY_THROW:
  856. if( foxAction == STOP )
  857. {
  858. break;
  859. }
  860. else if( (foxAction == STILL) || (foxAction == WALK) ||
  861. (foxAction == RUN) || (foxAction == CROUCH) ||
  862. (foxAction == CROUCHWALK) )
  863. {
  864. SetSpriteAction( hFox, THROW, SAME );
  865. SetSpriteSwitch( hFox, C_FOX_THROWSWITCH, P_ABSOLUTE );
  866. SetSpriteVelX( hFox, 0, P_ABSOLUTE );
  867. SetSpriteSwitchType( hFox, TIMESWITCH );
  868. }
  869. else if( foxAction == JUMP )
  870. {
  871. SetSpriteAccY( hFox, 0, P_ABSOLUTE );
  872. SetSpriteSwitch( hFox, C_FOX_THROWSWITCH, P_ABSOLUTE );
  873. SetSpriteAction( hFox, JUMPTHROW, SAME );
  874. SetSpriteVelY( hFox, 0, P_ABSOLUTE );
  875. SetSpriteSwitchDone( hFox, FALSE );
  876. SetSpriteSwitchForward( hFox, TRUE );
  877. }
  878. break;
  879. default:
  880. break;
  881. }
  882. /*
  883. * Fox actions follow...
  884. */
  885. if( GetSpriteActive(hFox) == FALSE )
  886. {
  887. goto bearActions;
  888. }
  889. if( abs(GetSpriteVelX( hFox )) < C_FOX_XMOVE )
  890. {
  891. SetSpriteVelX( hFox, 0, P_ABSOLUTE );
  892. }
  893. foxAction = GetSpriteAction( hFox );
  894. if( GetSpriteVelY(hFox) == 0 )
  895. {
  896. if( GetSurface( hForeground, hFox ) == FALSE )
  897. {
  898. if( (foxAction == WALK) || (foxAction == RUN) ||
  899. (foxAction == CROUCHWALK) )
  900. {
  901. SetSpriteAccY( hFox, C_UNIT / 2, P_ABSOLUTE );
  902. }
  903. else if( foxAction == STOP )
  904. {
  905. SetSpriteAccY( hFox, C_UNIT / 2, P_ABSOLUTE );
  906. SetSpriteAccX( hFox, 0, P_ABSOLUTE );
  907. }
  908. }
  909. }
  910. else if( GetSpriteVelY(hFox) > 2 * C_UNIT )
  911. {
  912. if( (foxAction == WALK) || (foxAction == RUN) ||
  913. (foxAction == CROUCHWALK) )
  914. {
  915. SetSpriteSwitchForward( hFox, FALSE );
  916. SetSpriteAction( hFox, JUMP, SAME );
  917. SetSpriteSwitchType( hFox, TIMESWITCH );
  918. SetSpriteSwitch( hFox, C_FOX_JUMPSWITCH, P_ABSOLUTE );
  919. }
  920. if( foxAction == STOP )
  921. {
  922. SetSpriteAction( hFox, STUNNED, SAME );
  923. SetSpriteAccX( hFox, -GetSpriteVelX(hFox) / 25, P_ABSOLUTE );
  924. SoundPlayEffect( SOUND_STUNNED );
  925. }
  926. }
  927. foxSpeedX = GetSpriteVelX( hFox );
  928. foxSpeedY = GetSpriteVelY( hFox );
  929. foxAction = GetSpriteAction( hFox );
  930. foxDir = GetSpriteDirection( hFox );
  931. switch( foxAction ) {
  932. case STUNNED:
  933. if( (GetSpriteVelY(hFox) >= 0) &&
  934. (!GetSurface( hForeground, hFox ) == FALSE) )
  935. {
  936. SetSpriteAccY( hFox, 0, P_ABSOLUTE );
  937. SetSpriteAction( hFox, STOP, SAME );
  938. SetSpriteVelY( hFox, 0, P_ABSOLUTE );
  939. SetSpriteAccX( hFox, -foxSpeedX / 25, P_ABSOLUTE );
  940. // SetSurface( hForeground, hFox );
  941. SoundPlayEffect( SOUND_STOP );
  942. }
  943. break;
  944. case CROUCHWALK:
  945. if( foxSpeedX == 0 )
  946. {
  947. SetSpriteAction( hFox, CROUCH, SAME );
  948. }
  949. else if( foxSpeedX > C_FOX_WALKMOVE )
  950. {
  951. SetSpriteVelX( hFox, C_FOX_WALKMOVE, P_ABSOLUTE );
  952. }
  953. else if( foxSpeedX < -C_FOX_WALKMOVE )
  954. {
  955. SetSpriteVelX( hFox, -C_FOX_WALKMOVE, P_ABSOLUTE );
  956. }
  957. break;
  958. case STOP:
  959. if( foxSpeedX == 0 )
  960. {
  961. SetSpriteAction( hFox, STILL, SAME );
  962. SetSpriteAccX( hFox, 0, P_ABSOLUTE );
  963. }
  964. break;
  965. case RUN:
  966. if( (foxSpeedX < C_FOX_WALKTORUN ) && (foxSpeedX > 0) )
  967. {
  968. SetSpriteAction( hFox, WALK, RIGHT );
  969. SetSpriteSwitch( hFox, C_FOX_WALKSWITCH, P_ABSOLUTE );
  970. }
  971. else if( foxSpeedX > C_FOX_RUNTOBLURR )
  972. {
  973. SetSpriteAction( hFox, BLURR, RIGHT );
  974. SetSpriteSwitch( hFox, C_FOX_BLURRSWITCH, P_ABSOLUTE );
  975. }
  976. else if( (foxSpeedX > -C_FOX_WALKTORUN ) && (foxSpeedX < 0) )
  977. {
  978. SetSpriteAction( hFox, WALK, LEFT );
  979. SetSpriteSwitch( hFox, C_FOX_WALKSWITCH, P_ABSOLUTE );
  980. }
  981. else if( foxSpeedX < -C_FOX_RUNTOBLURR )
  982. {
  983. SetSpriteAction( hFox, BLURR, LEFT );
  984. SetSpriteSwitch( hFox, C_FOX_BLURRSWITCH, P_ABSOLUTE );
  985. }
  986. break;
  987. case WALK:
  988. if( foxSpeedX == 0 )
  989. {
  990. SetSpriteAction( hFox, STILL, SAME );
  991. }
  992. else if( foxSpeedX > C_FOX_WALKTORUN )
  993. {
  994. SetSpriteAction( hFox, RUN, RIGHT );
  995. SetSpriteSwitch( hFox, C_FOX_RUNSWITCH, P_ABSOLUTE );
  996. }
  997. else if( foxSpeedX < -C_FOX_WALKTORUN )
  998. {
  999. SetSpriteAction( hFox, RUN, LEFT );
  1000. SetSpriteSwitch( hFox, C_FOX_RUNSWITCH, P_ABSOLUTE );
  1001. }
  1002. break;
  1003. case BLURR:
  1004. if( (foxSpeedX < C_FOX_RUNTOBLURR ) && (foxSpeedX > C_FOX_WALKTORUN) )
  1005. {
  1006. SetSpriteAction( hFox, RUN, RIGHT );
  1007. SetSpriteSwitch( hFox, C_FOX_RUNSWITCH, P_ABSOLUTE );
  1008. }
  1009. else if( (foxSpeedX > -C_FOX_RUNTOBLURR ) && (foxSpeedX < -C_FOX_WALKTORUN) )
  1010. {
  1011. SetSpriteAction( hFox, RUN, LEFT );
  1012. SetSpriteSwitch( hFox, C_FOX_RUNSWITCH, P_ABSOLUTE );
  1013. }
  1014. break;
  1015. case JUMPTHROW:
  1016. if( !GetSpriteSwitchDone(hFox) == FALSE )
  1017. {
  1018. SetSpriteSwitchForward( hFox, FALSE );
  1019. SetSpriteAction( hFox, JUMP, SAME );
  1020. SetSpriteSwitch( hFox, C_FOX_JUMPSWITCH, P_ABSOLUTE );
  1021. SetSpriteSwitchDone( hFox, FALSE );
  1022. SetSpriteAccY( hFox, C_UNIT / 2, P_ABSOLUTE );
  1023. SoundPlayEffect( SOUND_THROW );
  1024. }
  1025. else
  1026. if( (GetSpriteBitmap(hFox) == 1) &&
  1027. (GetSpriteDirection(hFox) == RIGHT) )
  1028. {
  1029. SetSpriteActive( hApple, TRUE );
  1030. SetSpriteX( hApple, GetSpriteX(hFox) + 60 * C_UNIT, P_ABSOLUTE );
  1031. SetSpriteY( hApple, GetSpriteY(hFox) + 30 * C_UNIT, P_ABSOLUTE );
  1032. SetSpriteVelX( hApple, 8 * C_UNIT, P_ABSOLUTE );
  1033. SetSpriteVelY( hApple, -4 * C_UNIT, P_ABSOLUTE );
  1034. SetSpriteAccX( hApple, 0, P_ABSOLUTE );
  1035. SetSpriteAccY( hApple, C_UNIT / 4, P_ABSOLUTE );
  1036. }
  1037. else if( (GetSpriteBitmap(hFox) == 1) &&
  1038. (GetSpriteDirection(hFox) == LEFT) )
  1039. {
  1040. SetSpriteActive( hApple, TRUE );
  1041. SetSpriteX( hApple, GetSpriteX(hFox) + 15 * C_UNIT, P_ABSOLUTE );
  1042. SetSpriteY( hApple, GetSpriteY(hFox) + 30 * C_UNIT, P_ABSOLUTE );
  1043. SetSpriteVelX( hApple, -8 * C_UNIT, P_ABSOLUTE );
  1044. SetSpriteVelY( hApple, -4 * C_UNIT, P_ABSOLUTE );
  1045. SetSpriteAccX( hApple, 0, P_ABSOLUTE );
  1046. SetSpriteAccY( hApple, C_UNIT / 4, P_ABSOLUTE );
  1047. }
  1048. break;
  1049. case THROW:
  1050. if( !GetSpriteSwitchDone(hFox) == FALSE )
  1051. {
  1052. SetSpriteAction( hFox, STILL, SAME );
  1053. SetSpriteSwitchType( hFox, HOR );
  1054. SetSpriteSwitch( hFox, 0, P_ABSOLUTE );
  1055. SetSpriteSwitchDone( hFox, FALSE );
  1056. SoundPlayEffect( SOUND_THROW );
  1057. }
  1058. else if( (GetSpriteBitmap(hFox) == 1) &&
  1059. (GetSpriteDirection(hFox) == RIGHT) )
  1060. {
  1061. SetSpriteActive( hApple, TRUE );
  1062. SetSpriteX( hApple, GetSpriteX(hFox) + 60 * C_UNIT, P_ABSOLUTE );
  1063. SetSpriteY( hApple, GetSpriteY(hFox) + 50 * C_UNIT, P_ABSOLUTE );
  1064. SetSpriteVelX( hApple, 8 * C_UNIT, P_ABSOLUTE );
  1065. SetSpriteVelY( hApple, -4 * C_UNIT, P_ABSOLUTE );
  1066. SetSpriteAccX( hApple, 0, P_ABSOLUTE );
  1067. SetSpriteAccY( hApple, C_UNIT / 4, P_ABSOLUTE );
  1068. }
  1069. else if( (GetSpriteBitmap(hFox) == 1) &&
  1070. (GetSpriteDirection(hFox) == LEFT) )
  1071. {
  1072. SetSpriteActive( hApple, TRUE );
  1073. SetSpriteX( hApple, GetSpriteX(hFox) + 20 * C_UNIT, P_ABSOLUTE );
  1074. SetSpriteY( hApple, GetSpriteY(hFox) + 50 * C_UNIT, P_ABSOLUTE );
  1075. SetSpriteVelX( hApple, -8 * C_UNIT, P_ABSOLUTE );
  1076. SetSpriteVelY( hApple, -4 * C_UNIT, P_ABSOLUTE );
  1077. SetSpriteAccX( hApple, 0, P_ABSOLUTE );
  1078. SetSpriteAccY( hApple, C_UNIT / 4, P_ABSOLUTE );
  1079. }
  1080. break;
  1081. case JUMP:
  1082. if( (foxSpeedY >= 0) && (!GetSpriteSwitchForward( hFox ) == FALSE) )
  1083. {
  1084. SetSpriteSwitchForward( hFox, FALSE );
  1085. }
  1086. else if( GetSpriteSwitchForward( hFox ) == FALSE )
  1087. {
  1088. if( (!GetSurface( hForeground, hFox ) == FALSE) ||
  1089. (!GetSurface( hForeground, hFox ) == FALSE) )
  1090. {
  1091. if( foxSpeedX >= C_FOX_RUNMOVE )
  1092. {
  1093. SetSpriteAction( hFox, RUN, SAME );
  1094. SetSpriteSwitch( hFox, C_FOX_RUNSWITCH, P_ABSOLUTE );
  1095. }
  1096. else if( foxSpeedX == 0 )
  1097. {
  1098. SetSpriteAction( hFox, STILL, SAME );
  1099. SetSpriteSwitch( hFox, C_FOX_WALKSWITCH, P_ABSOLUTE );
  1100. }
  1101. else
  1102. {
  1103. SetSpriteAction( hFox, WALK, SAME );
  1104. SetSpriteSwitch( hFox, C_FOX_WALKSWITCH, P_ABSOLUTE );
  1105. }
  1106. SetSpriteAccY( hFox, 0, P_ABSOLUTE );
  1107. SetSpriteVelY( hFox, 0, P_ABSOLUTE );
  1108. SetSpriteSwitchType( hFox, HOR );
  1109. SetSpriteSwitchForward( hFox, TRUE );
  1110. // SetSurface( hForeground, hFox );
  1111. SetSpriteSwitchDone( hFox, FALSE );
  1112. }
  1113. }
  1114. break;
  1115. }
  1116. /*
  1117. * Bear Actions
  1118. */
  1119. bearActions:
  1120. foxX = GetSpriteX( hFox );
  1121. foxY = GetSpriteY( hFox );
  1122. bearX = GetSpriteX( hBear );
  1123. bearY = GetSpriteY( hBear );
  1124. appleX = GetSpriteX( hApple );
  1125. appleY = GetSpriteY( hApple );
  1126. switch( GetSpriteAction( hBear ) ) {
  1127. case STRIKE:
  1128. if( GetSpriteBitmap( hBear ) == 2 )
  1129. {
  1130. if( (bearX > foxX - C_UNIT * 30) && (bearX < foxX + C_UNIT * 40) &&
  1131. (bearY < foxY + C_UNIT * 60) )
  1132. {
  1133. SetSpriteActive( hFox, FALSE );
  1134. if( !fBearPlaying )
  1135. {
  1136. SoundPlayEffect( SOUND_BEARSTRIKE );
  1137. fBearPlaying = TRUE;
  1138. }
  1139. }
  1140. else
  1141. {
  1142. SetSpriteAction( hBear, MISS, SAME );
  1143. SetSpriteSwitch( hBear, C_BEAR_MISSSWITCH, P_ABSOLUTE );
  1144. SetSpriteSwitchDone( hBear, FALSE );
  1145. }
  1146. }
  1147. else if( !GetSpriteSwitchDone( hBear ) == FALSE )
  1148. {
  1149. SetSpriteAction( hBear, CHEW, SAME );
  1150. SetSpriteSwitchDone( hBear, FALSE );
  1151. chewCount = 0;
  1152. fBearPlaying = FALSE;
  1153. }
  1154. break;
  1155. case MISS:
  1156. if( !fBearPlaying )
  1157. {
  1158. SoundPlayEffect( SOUND_BEARMISS );
  1159. fBearPlaying = TRUE;
  1160. }
  1161. if( !GetSpriteSwitchDone( hBear ) == FALSE )
  1162. {
  1163. SetSpriteAction( hBear, WALK, SAME );
  1164. SetSpriteVelX( hBear, -C_BEAR_WALKMOVE, P_ABSOLUTE );
  1165. SetSpriteSwitch( hBear, C_BEAR_WALKSWITCH, P_ABSOLUTE );
  1166. SetSpriteSwitchType( hBear, HOR );
  1167. fBearPlaying = FALSE;
  1168. }
  1169. break;
  1170. case WALK:
  1171. if( (!GetSpriteActive(hApple) == FALSE) && (appleX > bearX) &&
  1172. (appleX > bearX + 80 * C_UNIT) && (appleY > bearY + 30 * C_UNIT) )
  1173. {
  1174. SetSpriteAction( hBear, STRIKE, SAME );
  1175. SetSpriteVelX( hBear, 0, P_ABSOLUTE );
  1176. SetSpriteSwitchType( hBear, TIMESWITCH );
  1177. SetSpriteSwitch( hBear, C_BEAR_STRIKESWITCH, P_ABSOLUTE );
  1178. SetSpriteSwitchDone( hBear, FALSE );
  1179. }
  1180. else if( (bearX > foxX - C_UNIT * 30) &&
  1181. (bearX < foxX + C_UNIT * 30) &&
  1182. (bearY < foxY + C_UNIT * 60) )
  1183. {
  1184. SetSpriteAction( hBear, STRIKE, SAME );
  1185. SetSpriteVelX( hBear, 0, P_ABSOLUTE );
  1186. SetSpriteSwitchType( hBear, TIMESWITCH );
  1187. SetSpriteSwitch( hBear, C_BEAR_STRIKESWITCH, P_ABSOLUTE );
  1188. SetSpriteSwitchDone( hBear, FALSE );
  1189. }
  1190. break;
  1191. case CHEW:
  1192. ++chewCount;
  1193. if( chewCount >= 200 )
  1194. {
  1195. SetSpriteAction( hBear, STRIKE, SAME );
  1196. SetSpriteSwitch( hBear, C_BEAR_STRIKESWITCH, P_ABSOLUTE );
  1197. SetSpriteVelX( hBear, 0, P_ABSOLUTE );
  1198. SetSpriteSwitchDone( hBear, FALSE );
  1199. if( GetSpriteDirection(hFox) == RIGHT )
  1200. {
  1201. SetPlaneSlideX( hForeground, -C_BOUNDDIF, P_RELATIVE );
  1202. SetPlaneSlideX( hMidground, -C_BOUNDDIF, P_RELATIVE );
  1203. SetPlaneSlideX( hBackground, -C_BOUNDDIF, P_RELATIVE );
  1204. }
  1205. chewDif = GetSpriteX(hFox);
  1206. SetSpriteActive( hFox, TRUE );
  1207. SetSpriteAction( hFox, STUNNED, LEFT );
  1208. SetSpriteX( hFox, GetSpriteX(hBear), P_ABSOLUTE );
  1209. SetSpriteY( hFox, GetSpriteY(hBear), P_ABSOLUTE );
  1210. SetSpriteAccX( hFox, 0, P_ABSOLUTE );
  1211. SetSpriteAccY( hFox, C_UNIT / 2, P_ABSOLUTE );
  1212. SetSpriteVelX( hFox, -8 * C_UNIT, P_ABSOLUTE );
  1213. SetSpriteVelY( hFox, -10 * C_UNIT, P_ABSOLUTE );
  1214. SetSpriteSwitch( hFox, 0, P_ABSOLUTE );
  1215. SoundPlayEffect( SOUND_STUNNED );
  1216. chewDif -= GetSpriteX(hFox);
  1217. SetPlaneSlideX( hForeground, -chewDif, P_RELATIVE );
  1218. SetPlaneSlideX( hMidground, -chewDif, P_RELATIVE );
  1219. SetPlaneSlideX( hBackground, -chewDif, P_RELATIVE );
  1220. SetPlaneIncremX( hForeground, C_BOUNDINCREM, P_ABSOLUTE );
  1221. SetPlaneIncremX( hMidground, C_BOUNDINCREM, P_ABSOLUTE );
  1222. SetPlaneIncremX( hBackground, C_BOUNDINCREM, P_ABSOLUTE );
  1223. }
  1224. break;
  1225. }
  1226. /*
  1227. * Apple actions...
  1228. */
  1229. if( (GetSpriteVelY(hApple) != 0) && (GetSpriteY(hApple) >= 420 * C_UNIT) )
  1230. {
  1231. SetSpriteX( hApple, 0, P_ABSOLUTE );
  1232. SetSpriteY( hApple, 0, P_ABSOLUTE );
  1233. SetSpriteAccX( hApple, 0, P_ABSOLUTE );
  1234. SetSpriteAccY( hApple, 0, P_ABSOLUTE );
  1235. SetSpriteVelX( hApple, 0, P_ABSOLUTE );
  1236. SetSpriteVelY( hApple, 0, P_ABSOLUTE );
  1237. SetSpriteActive( hApple, FALSE );
  1238. }
  1239. return cont;
  1240. } /* ProcessInput */