qafBGLayer.h

00001 /* 
00002 ** Qaf Framework 1.2
00003 ** June 2006
00004 ** 
00005 ** Pedro Luchini de Moraes, Public Domain - Free Lunch Code
00006 */
00007 
00008 #ifndef QAF_BGLAYER_H
00009 #define QAF_BGLAYER_H
00010 
00011 #include <hge.h>
00012 #include "qafutil/qafBigTexture.h"
00013 #include "qafutil/qafMatrix.h"
00014 #include <string>
00015 
00016 #define QAF_TILE_PURE_ID_MASK   0x0000FFFF
00017 #define QAF_TILE_FLIPPED_X_MASK 0x80000000
00018 #define QAF_TILE_FLIPPED_Y_MASK 0x40000000
00019 #define QAF_TILE_COLORED_MASK   0x20000000
00020 
00021 
00022 namespace qaf {
00023     
00024     #ifndef QAF_ENVIRONMENT_H
00025     class Environment;
00026     #endif
00027     
00028     #ifndef QAF_ROOM_H
00029     class Room;
00030     #endif
00031     
00045     class BGLayer {
00046     public:
00047         
00049         const int tileWidth;
00050         
00052         const int tileHeight;
00053         
00055 
00064         const float parallaxFactorX;
00065         const float parallaxFactorY;
00067         
00069 
00073         int translateX;
00074         int translateY;
00076         
00077         
00078         
00079     private:
00080         const BigTexture * libTexture;
00081         
00082         friend class Environment;
00083         friend class Room;
00084         
00085         // The constructor will load the source image and use it as a tile
00086         // library.
00087         // 
00088         // The parameters <tt>rows</tt> and <tt>columns</tt> refer to the data
00089         // matrix's dimensions.
00090         BGLayer ( std::string sourceImagePath,
00091                   int tileWidth, int tileHeight,
00092                   float parallaxFactorX, float parallaxFactorY,
00093                   int translateX, int translateY,
00094                   int rows, int columns );
00095         
00096         
00097         // Draws the layer using HGE functions. The supplied coordinates
00098         // (<tt>x</tt>, <tt>y</tt>) are interpreted as the room's top-left
00099         // corner (in <tt>Environment</tt> terms, they're the scrolling point,
00100         // but with its sign reversed).
00101         // 
00102         // What this means is that if the layer's parallax factor is not 1.0,
00103         // its top-left corner will not be drawn exactly at (<tt>x</tt>,
00104         // <tt>y</tt>), but will be scaled so that the parallax is consistent.
00105         void render ( int x, int y );
00106         
00107         // Deletes the data matrix and frees the tile library.
00108         virtual ~BGLayer ();
00109         
00110         struct ColorTile {
00111             DWORD blend;
00112             DWORD colors[4];
00113             
00114             inline ColorTile ( DWORD _blend, DWORD _argb0, DWORD _argb1, DWORD _argb2, DWORD _argb3 ) {
00115                 blend = _blend;
00116                 colors[0] = _argb0;
00117                 colors[1] = _argb1;
00118                 colors[2] = _argb2;
00119                 colors[3] = _argb3;
00120             }
00121         };
00122         
00123         Matrix<int> bgData;
00124         Matrix<ColorTile *> bgColorData;
00125     };
00126 
00127 }
00128 
00129 
00130 #endif

Generated on Sun Mar 25 12:32:12 2007 for Qaf Framework by  doxygen 1.5.1-p1