home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / demos / skyscrap / build / scroller.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-13  |  4.8 KB  |  139 lines

  1. #ifndef __ImageScroller_h
  2. #define __ImageScroller_h
  3.  
  4. #include <theatrix.h>
  5.  
  6. //--------------------------------------
  7. // Direction
  8. // tells scroller which way to move
  9. //--------------------------------------
  10. enum Direction
  11. {
  12.   NORTHWEST, NORTH, NORTHEAST,
  13.   WEST, EAST,
  14.   SOUTHWEST, SOUTH, SOUTHEAST
  15. };
  16.  
  17. //--------------------------------------
  18. // Scroller
  19. // manages a scrolling background
  20. // allows movement in 8 directions
  21. //--------------------------------------
  22. class ImageScroller : public Performer
  23. {
  24.   // data
  25.   private:
  26.   protected:
  27.     boolean AtNorthMost,  // are we at the north most position
  28.             AtSouthMost,  // are we at the south most position
  29.             AtEastMost,   // are we at the east most position
  30.             AtWestMost;   // are we at the west most position
  31.     int x, y,             // the top,left pos we are in the world
  32.         WorldWidth,       // the max width of this world
  33.         WorldHeight,      // the max height of this world
  34.         PixelIncrement,   // how many pixels to move in bitmap each screen update
  35.         ImageWidth,       // the width of each image
  36.         ImageHeight,      // the height of each image
  37.         ScreenWidth,      // the width of the screen
  38.         ScreenHeight,     // the height of the screen
  39.         NumImages;        // number of images in image array
  40.     int* image;           // pointer to 2D array of image indexes
  41.   public:
  42.  
  43.   // functions
  44.   private:
  45.   protected:
  46.   public:
  47.     ImageScroller();
  48.     void Setup( Director* director );
  49.     boolean AtMost( Direction dir ); // are we at the <dir> most position
  50.     virtual void draw(void);
  51.  
  52.     void MoveNorthEast(void);
  53.     void MoveNorth(void);
  54.     void MoveNorthWest(void);
  55.     void MoveEast(void);
  56.     void MoveWest(void);
  57.     void MoveSouthEast(void);
  58.     void MoveSouth(void);
  59.     void MoveSouthWest(void);
  60.  
  61.     void SetAtNorthEastMost(void);
  62.     void SetAtNorthMost(void);
  63.     void SetAtNorthWestMost(void);
  64.     void SetAtEastMost(void);
  65.     void SetAtWestMost(void);
  66.     void SetAtSouthEastMost(void);
  67.     void SetAtSouthMost(void);
  68.     void SetAtSouthWestMost(void);
  69.  
  70.     void SetXY( int X, int Y );
  71.     void SetPixelIncrement( int inc );
  72.     int  GetPixelIncrement(void);
  73.     void SetImageWidthHeight( int width, int height );
  74.     void SetWorldWidthHeight( int width, int height );
  75.     void SetScreenWidthHeight( int width, int height );
  76. };
  77.  
  78. inline void ImageScroller::MoveNorthEast(void)
  79. {
  80.   x+=(x+PixelIncrement<=(WorldWidth-ScreenWidth)) ? PixelIncrement:0;
  81.   y-=(y-PixelIncrement>=0) ? PixelIncrement:0;
  82. }
  83.  
  84. inline void ImageScroller::MoveNorth(void)
  85. {
  86.   y-=(y-PixelIncrement>=0) ? PixelIncrement:0;
  87. }
  88.  
  89. inline void ImageScroller::MoveNorthWest(void)
  90. {
  91.   x-=(x-PixelIncrement>=0) ? PixelIncrement:0;
  92.   y-=(y-PixelIncrement>=0) ? PixelIncrement:0;
  93. }
  94.  
  95. inline void ImageScroller::MoveEast(void)
  96. {
  97.   x+=(x+PixelIncrement<=(WorldWidth-ScreenWidth)) ? PixelIncrement:0;
  98. }
  99.  
  100. inline void ImageScroller::MoveWest(void)
  101. {
  102.   x-=(x-PixelIncrement>=0) ? PixelIncrement:0;
  103. }
  104.  
  105. inline void ImageScroller::MoveSouthEast(void)
  106. {
  107.   x+=(x+PixelIncrement>=(WorldWidth-ScreenWidth)) ? PixelIncrement:0;
  108.   y+=(y+PixelIncrement<=(WorldHeight-ScreenHeight)) ? PixelIncrement:0;
  109. }
  110.  
  111. inline void ImageScroller::MoveSouth(void)
  112. {
  113.   y+=(y+PixelIncrement<=(WorldHeight-ScreenHeight)) ? PixelIncrement:0;
  114. }
  115.  
  116. inline void ImageScroller::MoveSouthWest(void)
  117. {
  118.   x-=(x-PixelIncrement>=0) ? PixelIncrement:0;
  119.   y+=(y+PixelIncrement<=(WorldHeight-ScreenHeight)) ? PixelIncrement:0;
  120. }
  121.  
  122. inline void ImageScroller::SetAtNorthEastMost(void) { y=0, x=WorldWidth-ScreenWidth; }
  123. inline void ImageScroller::SetAtNorthMost(void)     { y=0; }
  124. inline void ImageScroller::SetAtNorthWestMost(void) { x=0, y=0; }
  125. inline void ImageScroller::SetAtEastMost(void)      { x=WorldWidth-ScreenWidth; }
  126. inline void ImageScroller::SetAtWestMost(void)      { x=0; }
  127. inline void ImageScroller::SetAtSouthEastMost(void) { y=WorldHeight-ScreenHeight, x=WorldWidth-ScreenWidth; }
  128. inline void ImageScroller::SetAtSouthMost(void)     { y=WorldHeight-ScreenHeight; }
  129. inline void ImageScroller::SetAtSouthWestMost(void) { x=0, y=WorldHeight-ScreenHeight; }
  130.  
  131. inline void ImageScroller::SetXY( int X, int Y )    { x=X, y=Y; }
  132. inline void ImageScroller::SetPixelIncrement( int inc ) { PixelIncrement=inc; }
  133. inline int  ImageScroller::GetPixelIncrement(void) { return PixelIncrement; }
  134. inline void ImageScroller::SetImageWidthHeight( int width, int height )  { ImageHeight=height, ImageWidth=width; }
  135. inline void ImageScroller::SetWorldWidthHeight( int width, int height )  { WorldHeight=height, WorldWidth=width; }
  136. inline void ImageScroller::SetScreenWidthHeight( int width, int height ) { ScreenHeight=height, ScreenWidth=width; }
  137.  
  138. #endif //__ImageScroller_h
  139.