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

  1. #include "scroller.h"
  2.  
  3. ImageScroller::ImageScroller()
  4. {
  5.   AtNorthMost=AtSouthMost=AtEastMost=AtWestMost=FALSE;
  6.   ImageWidth=ImageHeight=x=y=WorldWidth=WorldHeight=ScreenWidth=ScreenHeight=0;
  7.   PixelIncrement=4;
  8.   image=0;
  9.   NumImages=0;
  10. }
  11.  
  12. void ImageScroller::Setup( Director* director )
  13. {
  14.   set_director( director );
  15. }
  16.  
  17. boolean ImageScroller::AtMost( Direction dir )
  18. {
  19.   boolean RetVal=NO;
  20.  
  21.   switch( dir )
  22.   {
  23.     case NORTHWEST:
  24.       RetVal=( x<PixelIncrement && y<PixelIncrement ) ? YES:NO;
  25.       break;
  26.     case NORTH:
  27.       RetVal=(y<PixelIncrement) ? YES:NO;
  28.       break;
  29.     case NORTHEAST:
  30.       RetVal=(y<PixelIncrement && x==WorldWidth-ScreenWidth) ? YES:NO;
  31.       break;
  32.     case WEST:
  33.       RetVal=(x<PixelIncrement) ? YES:NO;
  34.       break;
  35.     case EAST:
  36.       RetVal=(x==WorldWidth-ScreenWidth) ? YES:NO;
  37.       break;
  38.     case SOUTHWEST:
  39.       RetVal=(x<PixelIncrement && y==WorldHeight-ScreenHeight) ? YES:NO;
  40.       break;
  41.     case SOUTH:
  42.       RetVal=(y==WorldHeight-ScreenHeight) ? YES:NO;
  43.       break;
  44.     case SOUTHEAST:
  45.       RetVal=(y==WorldHeight-ScreenHeight && x==WorldWidth-ScreenWidth) ? YES:NO;
  46.       break;
  47.   }
  48.   return RetVal;
  49. }
  50.  
  51. void ImageScroller::draw(void)
  52. {
  53.   // figure the index to the image
  54.   int xIndex=x/ImageWidth;
  55.   int yIndex=y/ImageHeight;
  56.   // figure the remainder of pixels
  57.   int xRemainder=x%ImageWidth;
  58.   int yRemainder=y%ImageHeight;
  59.   // figure number of images to draw
  60.   int hImages=(ScreenWidth+xRemainder)/ImageWidth;
  61.   hImages+=((ScreenWidth+xRemainder)%ImageWidth)!=0 ? 1:0;
  62.   int vImages=(ScreenHeight+yRemainder)/ImageHeight;
  63.   vImages+=((ScreenHeight+yRemainder)%ImageHeight)!=0 ? 1:0;
  64.   // draw them
  65.   int TotalHImages=WorldWidth/ImageWidth;
  66.   int dy=0-yRemainder;
  67.   for( int i=0; i<vImages; i++ )
  68.   {
  69.     int dx=0-xRemainder;
  70.     for( int j=0; j<hImages; j++ )
  71.     {
  72.       show_clipped_image( dx, dy, image[((yIndex+i)*TotalHImages)+xIndex+j] );
  73.       dx+=ImageWidth;
  74.     }
  75.     dy+=ImageHeight;
  76.   }
  77. }
  78.