Fixed the background code.
authorMatt Mullins <mokomull@gmail.com>
Sun, 31 Oct 2010 02:11:46 +0000 (21:11 -0500)
committerMatt Mullins <mokomull@gmail.com>
Sun, 31 Oct 2010 02:11:46 +0000 (21:11 -0500)
Background.cpp

index a90a4b8..7af7dd5 100644 (file)
@@ -27,51 +27,59 @@ void Background::draw(){
        /** \todo decide if wrapping should be a good default.*/
        ///destination rectangle only position is used and describes where the output is drawn.
        SDL_Rect dest;///<the place where the sample will be drawn (can be reused)
-       dest.x=0;
-       dest.y=0;
        double x = mPos.X, y = mPos.Y;
-       while(x > mScreenSize.width)//move it to the left til it's 0 or less
-               x-=mScreenSize.width;
-       while(y > mScreenSize.height)//move it down til it's 0 or less
-               y-=mScreenSize.height;
-       while(x < 0)//move it to the right until it's in the drawable area
-               x+=mScreenSize.width;
-       while(y < 0)//move it up til it's 
-               y+=mScreenSize.height;
+       while (x > mScreenSize.width) // move it to the left til it's on the screen
+               x -= mScreenSize.width;
+       while (y > mScreenSize.height) // move it up til it's on the screen
+               y -= mScreenSize.height;
+       while (x < 0) // move it to the right until it's in the drawable area
+               x += mScreenSize.width;
+       while (y < 0) // move it down til it's on the screen
+               y += mScreenSize.height;
 
-       if(wrapping){
-               SDL_Rect extraX;///<keeps track of pos and size of the sample that hangs off the x
-               SDL_Rect extraY;///<keeps track of pos and size of the sampel hanging off y
+       if (wrapping) {
+               SDL_Rect source;
 
-               //horizontal wrapping
-               if(x > 0 ){
-                       extraX.x = mScreenSize.width - x;       
-                       extraX.y = y;   
-                       extraX.w = x;
-                       extraX.h = mScreenSize.height - y;      
-                       SDL_BlitSurface(mBackground, &extraX, mScreen, &dest);
-               }
-               /// \todo vertical wrapping
-               if(y > 0){
-                       extraX.x = x;
-                       extraX.y = mScreenSize.height + y;      
-                       extraX.w = mScreenSize.width + x;
-                       extraX.h = y;   
-                       SDL_BlitSurface(mBackground, &extraX, mScreen, &dest);
-               }
-               /*
-               if(x + _imageSize.width < mScreenSize.width){
-                       extraX.x = 0;
-                       extraX.y = 0;
-                       extraX.w = -x;
-                       extraX.h = mScreenSize.height;  
-                       SDL_BlitSurface(mBackground, &extraX, mScreen, &dest);
-               }//*/
-       }
-       dest.x = x;
-       dest.y = y;
-       SDL_BlitSurface(mBackground, &source, mScreen, &dest);
+               // Top-left portion of image
+               dest.x = x;
+               dest.y = y;
+               source.x = 0;
+               source.y = 0;
+               source.w = mScreenSize.width - x;
+               source.h = mScreenSize.height - y;
+               SDL_BlitSurface(mBackground, &source, mScreen, &dest);
+
+               // Top-right portion of image
+               dest.x = 0;
+               dest.y = y;
+               source.x = mScreenSize.width - x;
+               source.y = 0;
+               source.w = x;
+               source.h = mScreenSize.height - y;
+               SDL_BlitSurface(mBackground, &source, mScreen, &dest);
 
+               // Lower-left portion of image
+               dest.x = 0;
+               dest.y = 0;
+               source.x = mScreenSize.width - x;
+               source.y = mScreenSize.height - y;
+               source.w = x;
+               source.h = y;
+               SDL_BlitSurface(mBackground, &source, mScreen, &dest);
+
+               // Lower-right portion of image
+               dest.x = x;
+               dest.y = 0;
+               source.x = 0;
+               source.y = mScreenSize.height - y;
+               source.w = mScreenSize.width - x;
+               source.h = y;
+               SDL_BlitSurface(mBackground, &source, mScreen, &dest);
+       } else {
+               dest.x = mPos.X;
+               dest.y = mPos.Y;
+               // SDL_BlitSurface(mBackground, &source, mScreen, &dest);
+       }
 }
 
 SDL_Surface* Background::load(std::string filename){