home *** CD-ROM | disk | FTP | other *** search
- #ifndef __ImageScroller_h
- #define __ImageScroller_h
-
- #include <theatrix.h>
-
- //--------------------------------------
- // Direction
- // tells scroller which way to move
- //--------------------------------------
- enum Direction
- {
- NORTHWEST, NORTH, NORTHEAST,
- WEST, EAST,
- SOUTHWEST, SOUTH, SOUTHEAST
- };
-
- //--------------------------------------
- // Scroller
- // manages a scrolling background
- // allows movement in 8 directions
- //--------------------------------------
- class ImageScroller : public Performer
- {
- // data
- private:
- protected:
- boolean AtNorthMost, // are we at the north most position
- AtSouthMost, // are we at the south most position
- AtEastMost, // are we at the east most position
- AtWestMost; // are we at the west most position
- int x, y, // the top,left pos we are in the world
- WorldWidth, // the max width of this world
- WorldHeight, // the max height of this world
- PixelIncrement, // how many pixels to move in bitmap each screen update
- ImageWidth, // the width of each image
- ImageHeight, // the height of each image
- ScreenWidth, // the width of the screen
- ScreenHeight, // the height of the screen
- NumImages; // number of images in image array
- int* image; // pointer to 2D array of image indexes
- public:
-
- // functions
- private:
- protected:
- public:
- ImageScroller();
- void Setup( Director* director );
- boolean AtMost( Direction dir ); // are we at the <dir> most position
- virtual void draw(void);
-
- void MoveNorthEast(void);
- void MoveNorth(void);
- void MoveNorthWest(void);
- void MoveEast(void);
- void MoveWest(void);
- void MoveSouthEast(void);
- void MoveSouth(void);
- void MoveSouthWest(void);
-
- void SetAtNorthEastMost(void);
- void SetAtNorthMost(void);
- void SetAtNorthWestMost(void);
- void SetAtEastMost(void);
- void SetAtWestMost(void);
- void SetAtSouthEastMost(void);
- void SetAtSouthMost(void);
- void SetAtSouthWestMost(void);
-
- void SetXY( int X, int Y );
- void SetPixelIncrement( int inc );
- int GetPixelIncrement(void);
- void SetImageWidthHeight( int width, int height );
- void SetWorldWidthHeight( int width, int height );
- void SetScreenWidthHeight( int width, int height );
- };
-
- inline void ImageScroller::MoveNorthEast(void)
- {
- x+=(x+PixelIncrement<=(WorldWidth-ScreenWidth)) ? PixelIncrement:0;
- y-=(y-PixelIncrement>=0) ? PixelIncrement:0;
- }
-
- inline void ImageScroller::MoveNorth(void)
- {
- y-=(y-PixelIncrement>=0) ? PixelIncrement:0;
- }
-
- inline void ImageScroller::MoveNorthWest(void)
- {
- x-=(x-PixelIncrement>=0) ? PixelIncrement:0;
- y-=(y-PixelIncrement>=0) ? PixelIncrement:0;
- }
-
- inline void ImageScroller::MoveEast(void)
- {
- x+=(x+PixelIncrement<=(WorldWidth-ScreenWidth)) ? PixelIncrement:0;
- }
-
- inline void ImageScroller::MoveWest(void)
- {
- x-=(x-PixelIncrement>=0) ? PixelIncrement:0;
- }
-
- inline void ImageScroller::MoveSouthEast(void)
- {
- x+=(x+PixelIncrement>=(WorldWidth-ScreenWidth)) ? PixelIncrement:0;
- y+=(y+PixelIncrement<=(WorldHeight-ScreenHeight)) ? PixelIncrement:0;
- }
-
- inline void ImageScroller::MoveSouth(void)
- {
- y+=(y+PixelIncrement<=(WorldHeight-ScreenHeight)) ? PixelIncrement:0;
- }
-
- inline void ImageScroller::MoveSouthWest(void)
- {
- x-=(x-PixelIncrement>=0) ? PixelIncrement:0;
- y+=(y+PixelIncrement<=(WorldHeight-ScreenHeight)) ? PixelIncrement:0;
- }
-
- inline void ImageScroller::SetAtNorthEastMost(void) { y=0, x=WorldWidth-ScreenWidth; }
- inline void ImageScroller::SetAtNorthMost(void) { y=0; }
- inline void ImageScroller::SetAtNorthWestMost(void) { x=0, y=0; }
- inline void ImageScroller::SetAtEastMost(void) { x=WorldWidth-ScreenWidth; }
- inline void ImageScroller::SetAtWestMost(void) { x=0; }
- inline void ImageScroller::SetAtSouthEastMost(void) { y=WorldHeight-ScreenHeight, x=WorldWidth-ScreenWidth; }
- inline void ImageScroller::SetAtSouthMost(void) { y=WorldHeight-ScreenHeight; }
- inline void ImageScroller::SetAtSouthWestMost(void) { x=0, y=WorldHeight-ScreenHeight; }
-
- inline void ImageScroller::SetXY( int X, int Y ) { x=X, y=Y; }
- inline void ImageScroller::SetPixelIncrement( int inc ) { PixelIncrement=inc; }
- inline int ImageScroller::GetPixelIncrement(void) { return PixelIncrement; }
- inline void ImageScroller::SetImageWidthHeight( int width, int height ) { ImageHeight=height, ImageWidth=width; }
- inline void ImageScroller::SetWorldWidthHeight( int width, int height ) { WorldHeight=height, WorldWidth=width; }
- inline void ImageScroller::SetScreenWidthHeight( int width, int height ) { ScreenHeight=height, ScreenWidth=width; }
-
- #endif //__ImageScroller_h