From: Ivan Hernandez Date: Sun, 17 Oct 2010 06:50:13 +0000 (-0500) Subject: Background now wraps horizontally X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=79ad7ee39980361bfc04f3338e40c929b8cc2909;p=IvanGame.git Background now wraps horizontally --- diff --git a/Background.cpp b/Background.cpp index 34ab49b..a90a4b8 100644 --- a/Background.cpp +++ b/Background.cpp @@ -6,52 +6,72 @@ Background::Background(SDL_Surface *screen, std::string name, std::string filena /// \todo refactor all width as w height as h X as x Y as y so on and so forth for everything. different things are annoying mScreenSize.width = screen->w; mScreenSize.height = screen->h; + source.w = bgSize.width; source.h = bgSize.height; source.x = bgSamplePos.X; source.y = bgSamplePos.Y; - load(filename); + MaxTexWidth = 512; + MaxTexHeight = 512; + load(filename); + + // Number of sections each dimension, rounded up + _sections.width = (_imageSize.width - 1) / MaxTexWidth + 1; + _sections.height = (_imageSize.height - 1) / MaxTexHeight + 1; cout<<"background \""<<_name<<"\" created"< 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; + if(wrapping){ SDL_Rect extraX;/// 0 || mPos.Y > 0 /*+ _imageSize.width > mScreenSize.width*/){ - extraX.x = 0; - extraX.y = 0; - extraX.w = mPos.X; - extraX.h = mScreenSize.height - mPos.Y; - SDL_BlitSurface(mBackground, &extraX, mScreen, &dests); + + //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); } - ///hanging off the left side - if(mPos.X + _imageSize.width < mScreenSize.width){ + /* + if(x + _imageSize.width < mScreenSize.width){ extraX.x = 0; extraX.y = 0; - extraX.w = -mPos.X; + extraX.w = -x; extraX.h = mScreenSize.height; - SDL_BlitSurface(mBackground, &extraX, mScreen, &dests); - } - - - - } - else{ - SDL_Rect dest; - dest.x = mPos.X; - dest.y = mPos.Y; - - SDL_BlitSurface(mBackground, &source, mScreen, &dest); + SDL_BlitSurface(mBackground, &extraX, mScreen, &dest); + }//*/ } + dest.x = x; + dest.y = y; + SDL_BlitSurface(mBackground, &source, mScreen, &dest); + } SDL_Surface* Background::load(std::string filename){ @@ -71,3 +91,5 @@ void Background::setWrap(bool tf){ bool Background::getWrap(){ return wrapping; } + + diff --git a/Background.h b/Background.h index fceb014..e0ac618 100644 --- a/Background.h +++ b/Background.h @@ -15,6 +15,10 @@ class Background{ private: std::string _name;///>>"; - if ( keys[SDLK_LEFT] ) { mSprites[0]->xadd(-1); } + Uint8 *keys = SDL_GetKeyState(NULL); + if ( keys[SDLK_LEFT] ) { mSprites[0]->xadd(-1); } if ( keys[SDLK_RIGHT] ) { mSprites[0]->xadd(1); } if ( keys[SDLK_UP] ) { mSprites[0]->yadd(-1); } if ( keys[SDLK_DOWN] ) { mSprites[0]->yadd(1); } + if ( keys[SDLK_a] ) { mBackground->xadd(-1); } + if ( keys[SDLK_d] ) { mBackground->xadd(1); } + if ( keys[SDLK_w] ) { mBackground->yadd(-1); } + if ( keys[SDLK_s] ) { mBackground->yadd(1); } + }