home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / directx / foxbear / gameproc.c < prev    next >
C/C++ Source or Header  |  1997-07-14  |  45KB  |  1,432 lines

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