From c1393ab0516b063cc79fe710660e0950d58853e2 Mon Sep 17 00:00:00 2001 From: Ivan Hernandez Date: Sat, 16 Oct 2010 16:21:20 -0500 Subject: [PATCH] Removed mX,mY from sprite; Changed keyboard input from a push to a get keyboard state; Background functions if the bg hangs off the right side of the window. --- Background.cpp | 24 ++++++++++++------------ Level.cpp | 4 +++- Sprite.h | 13 ++++++------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Background.cpp b/Background.cpp index 18e69b6..34ab49b 100644 --- a/Background.cpp +++ b/Background.cpp @@ -3,7 +3,7 @@ using namespace std; Background::Background(SDL_Surface *screen, std::string name, std::string filename, bool wrap, Point2D ScreenPosition, SizeD ScreenSize, Point2D bgSamplePos, SizeD bgSize):mScreen(screen),_name(name),wrapping(wrap),mPos(ScreenPosition),mScreenSize(ScreenSize){ - +/// \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; @@ -17,7 +17,7 @@ Background::Background(SDL_Surface *screen, std::string name, std::string filena } void Background::draw(){ /** \todo make the drawing for everything be sectioned if that'd make it faster otherwise create tiling for backgrounds smaller than the screen size*/ - /** \todo we need to make this do wrapping if wanted/decide if it should be a good default.*/ + /** \todo decide if wrapping should be a good default.*/ ///destination rectangle only position is used and describes where the output is drawn. if(wrapping){ SDL_Rect extraX;/// mScreenSize){ - extraX.x = _imageSize.width-mPos.x; - extraX.Y = _imageSize.height-mPos.y; - extraX.w = mPos.x; - extrax.h = mScreenSize.height; + if(mPos.X > 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); } ///hanging off the left side - if(mPos+.x_imageSize < mScreenSize){ + if(mPos.X + _imageSize.width < mScreenSize.width){ extraX.x = 0; - extraX.Y = 0; - extraX.w = -mPos.x; - extrax.h = mScreenSize.height; + extraX.y = 0; + extraX.w = -mPos.X; + extraX.h = mScreenSize.height; SDL_BlitSurface(mBackground, &extraX, mScreen, &dests); } @@ -64,7 +64,7 @@ SDL_Surface* Background::load(std::string filename){ return mBackground; } -void Background::setWrapping(bool tf){ +void Background::setWrap(bool tf){ wrapping=tf; } diff --git a/Level.cpp b/Level.cpp index 27d3546..b170cf0 100644 --- a/Level.cpp +++ b/Level.cpp @@ -106,7 +106,9 @@ void Level::postEvent(SDL_Event event) /** Will handle all movement and dynamic triggers. */ void Level::update() { - Uint8 *keys = SDL_GetKeyState(NULL); + /*int* numkeys;*//// \todo Get keyboard as whole input to function correctly. + Uint8 *keys = SDL_GetKeyState(/*numkeys*/NULL); + //std::cout << *numkeys << ">>>"; if ( keys[SDLK_LEFT] ) { mSprites[0]->xadd(-1); } if ( keys[SDLK_RIGHT] ) { mSprites[0]->xadd(1); } if ( keys[SDLK_UP] ) { mSprites[0]->yadd(-1); } diff --git a/Sprite.h b/Sprite.h index dbca2ba..3529973 100644 --- a/Sprite.h +++ b/Sprite.h @@ -29,17 +29,16 @@ class Sprite void startAnim() {mAnimating = 1;}/**< Causes the animation to play. */ void stopAnim() {mAnimating = 0;}/**< Causes the animation to stop. */ void rewind() {mActor.mFrame = 0;}/**< Resets the Sprite's animation to the first frame. */ - void xadd(int num) {mX += num;}/**< Increase X coordiante by a given amount. */ - void yadd(int num) {mY += num;}/**< Increase Y coordinate by a given amount. */ - void xset(int x) {mX = x;}/**< Sets the Sprite's X Coordinate. */ - void yset(int y) {mY = y;}/**< Sets the Sprite's Y coordinate. */ - void setPosition(int x, int y) {mX = x; mY = y;}/**< Sets the Sprite's X an Y coordinate. */ + void xadd(int num) {mPos.X += num;}/**< Increase X coordiante by a given amount. */ + void yadd(int num) {mPos.Y += num;}/**< Increase Y coordinate by a given amount. */ + void xset(int x) {mPos.X = x;}/**< Sets the Sprite's X Coordinate. */ + void yset(int y) {mPos.Y = y;}/**< Sets the Sprite's Y coordinate. */ + void setPosition(int x, int y) {mPos.X = x; mPos.Y = y;}/**< Sets the Sprite's X an Y coordinate. */ std::string name; private: std::string mName;/**< Sprite's name */ - Point2D mPos; - int mX,mY; /**< Sprite's position \todo make a 2D point class and use instead. */ + Point2D mPos;/**< Sprite's position */ bool mAnimating;/**< Tells whether to animate or not */ bool mDrawn;/**< Tells if the object has been drawn the first time */ bool mVisible;/**< Determine if Sprite should be visible */ -- 2.11.0