home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / BARNHART / SCENES.CPP < prev    next >
C/C++ Source or Header  |  1993-11-15  |  3KB  |  164 lines

  1.  
  2. // scenes.cpp
  3. // this file sets up the scenes for the game, of which there are currently 
  4. //  only two
  5.  
  6. // Scenes _should_ be an object, but are not for an obscure reason having
  7. //  more to do with time of night it was begun than anything else...
  8.  
  9. #include <so_all.hpp>
  10.  
  11. extern int WinX, WinY, WinSX, WinSY;
  12.  
  13. typedef void INITFUNC( void);
  14. typedef INITFUNC *IFPTR;
  15.  
  16. #define NUMSCENES 2
  17.  
  18. void Scene1( void);
  19. void Scene2( void);
  20.  
  21. // An array of function pointers, one per scene
  22.  
  23. static IFPTR ifptrs[NUMSCENES] =
  24.     {
  25.     Scene1,
  26.     Scene2
  27.     };
  28.  
  29. static BOOL SceneShown = FALSE;
  30.  
  31.  
  32. // An array is kept for each type with a count of current created
  33.  
  34. static int nWalls = 0;
  35. static int cWall = 0;
  36. static Wall * walls[64];
  37.  
  38. static int nRungs = 0;
  39. static Rungs * rungs[64];
  40.  
  41. static int nCreepers = 0;
  42. static Creeper * creepers[16];
  43.  
  44. static int nMotions = 0;
  45. static StillMotion * motions[32];
  46.  
  47. static int nDoors = 0;
  48. static Door * doors[8];
  49.  
  50. static int nPrizes = 0;
  51. static Prize * prizes[32];
  52.  
  53. // Initialize the scene, cleaning up after last if necessary
  54.  
  55. BOOL InitScene( int scene)
  56.     {
  57.     if( scene > NUMSCENES ) return FALSE;
  58.     if( SceneShown) DeleteScene();
  59.     SceneShown = TRUE;
  60.     ifptrs[scene - 1]();
  61.     return TRUE;
  62.     }
  63.  
  64. // Show all items in the scene except the missiles
  65.  
  66. void ShowScene( void)
  67.     {
  68.     ScreenObj * nso;
  69.     InvalidateRect( ScreenObj::hWnd, NULL, FALSE);
  70.     WinSX = 0;
  71.     WinSY = 0;
  72.     SetWindowOrg( ScreenObj::hDC, WinSX, WinSY);
  73.     for( nso = ScreenObj::Background; nso != NULL; nso = nso->Next())
  74.         if( nso->SOType != TYPE_MISSILE)
  75.             nso->Show( TRUE);
  76.     }
  77.  
  78. // Delete all the ScreenItems
  79.  
  80. void DeleteScene( void)
  81.     {
  82.     while(nWalls)
  83.         delete walls[--nWalls];
  84.  
  85.     while(nRungs)
  86.         delete rungs[--nRungs];
  87.  
  88.     while(nCreepers)
  89.         delete creepers[--nCreepers];
  90.  
  91.     while(nMotions)
  92.         delete motions[--nMotions];
  93.  
  94.     while(nDoors)
  95.         delete doors[--nDoors];
  96.  
  97.     while(nPrizes)
  98.         delete prizes[--nPrizes];
  99.     }
  100.  
  101. // Create objects - these are not just convenient, but required in our
  102. //   current scheme
  103.  
  104. StillMotion * AddMotion( char *res, int ix, int iy, int nframes, int per)
  105.     {
  106.     StillMotion * sm;
  107.     sm = new StillMotion( res, ix, iy, nframes, per);
  108.     motions[nMotions++] = sm;
  109.     return( sm);
  110.     }
  111.  
  112. Wall * AddWall( char *res, int ix, int iy, int len, int vert)
  113.     {
  114.     Wall *w;
  115.     w = new Wall( res, ix, iy, len, vert);
  116.     walls[nWalls++] = w;
  117.     return( w);
  118.     }
  119.  
  120. Wall * FirstWall( void)
  121.     {
  122.     cWall = -1;
  123.     return( NextWall());
  124.     }
  125.  
  126. Wall * NextWall( void)
  127.     {
  128.     cWall++;
  129.     if( (cWall < 0) || (cWall >= nWalls) ) return( NULL);
  130.     else return (walls[cWall]);
  131.     }
  132.  
  133. Rungs * AddRungs( char *res, int ix, int iy, int len, int vert)
  134.     {
  135.     Rungs * r;
  136.     r = new Rungs( res, ix, iy, len, vert);
  137.     rungs[nRungs++] = r;
  138.     return( r);
  139.     }
  140.  
  141. Creeper * AddCreeper( char *res, Wall *wall, int ibx, int iex)
  142.      {
  143.      Creeper *c;
  144.      c = new Creeper( res, wall, ibx, iex);
  145.      creepers[nCreepers++] = c;
  146.      return( c);
  147.      }
  148.  
  149. Door * AddDoor( char *res, int ix, int iy, long nfo)
  150.      {
  151.      Door *d;
  152.      d = new Door( res, ix, iy, nfo);
  153.      doors[nDoors++] = d;
  154.      return( d);
  155.      }
  156.  
  157. Prize * AddPrize( char *res, int ix, int iy, long nfo)
  158.      {
  159.      Prize *p;
  160.      p = new Prize( res, ix, iy, nfo);
  161.      prizes[nPrizes++] = p;
  162.      return ( p);
  163.      }
  164.