home *** CD-ROM | disk | FTP | other *** search
/ NEXT Generation 27 / NEXT27.iso / pc / demos / emperor / dx3.exe / SDK / SAMPLES / FOXBEAR / GAMEPROC.C < prev    next >
C/C++ Source or Header  |  1996-08-28  |  44KB  |  1,371 lines

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