From 837c6c0cf9de126e6e626cc2da4674c401ffb9ec Mon Sep 17 00:00:00 2001 From: Ivan Hernandez Date: Sat, 4 Sep 2010 15:14:20 -0500 Subject: [PATCH] updates files and added better todo list as well as some slight reworking of background and other classes. --- Background.cpp | 49 +++++++++++++++++++++++++++++++++++----- Background.h | 5 ++++- Doxyfile | 2 +- Level.h | 4 ++-- Sprite.cpp | 27 +++++++++++----------- Sprite.h | 70 ++++++++++++++++++++++++++++++++-------------------------- Text.h | 7 ++++++ fns.cpp | 14 ++++++------ fns.h | 47 ++++++++++++++++++++++++++++++++++++++- 9 files changed, 162 insertions(+), 63 deletions(-) diff --git a/Background.cpp b/Background.cpp index f60c988..18e69b6 100644 --- a/Background.cpp +++ b/Background.cpp @@ -2,8 +2,10 @@ #include using namespace std; -Background::Background(SDL_Surface *screen, std::string name, std::string filename, Point2D ScreenPosition, SizeD ScreenSize, Point2D bgSamplePos, SizeD bgSize):mScreen(screen),_name(name),mPos(ScreenPosition),mScreenSize(ScreenSize){ +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){ + mScreenSize.width = screen->w; + mScreenSize.height = screen->h; source.w = bgSize.width; source.h = bgSize.height; source.x = bgSamplePos.X; @@ -11,16 +13,45 @@ Background::Background(SDL_Surface *screen, std::string name, std::string filena load(filename); - cout<<"background "<<_name<<" created"< mScreenSize){ + extraX.x = _imageSize.width-mPos.x; + extraX.Y = _imageSize.height-mPos.y; + extraX.w = mPos.x; + extrax.h = mScreenSize.height; + SDL_BlitSurface(mBackground, &extraX, mScreen, &dests); + } + ///hanging off the left side + if(mPos+.x_imageSize < mScreenSize){ + extraX.x = 0; + extraX.Y = 0; + extraX.w = -mPos.x; + extrax.h = mScreenSize.height; + SDL_BlitSurface(mBackground, &extraX, mScreen, &dests); + } - SDL_BlitSurface(mBackground, &source, mScreen, &dest); + + + } + else{ + SDL_Rect dest; + dest.x = mPos.X; + dest.y = mPos.Y; + + SDL_BlitSurface(mBackground, &source, mScreen, &dest); + } } SDL_Surface* Background::load(std::string filename){ @@ -33,4 +64,10 @@ SDL_Surface* Background::load(std::string filename){ return mBackground; } +void Background::setWrapping(bool tf){ + wrapping=tf; +} +bool Background::getWrap(){ + return wrapping; +} diff --git a/Background.h b/Background.h index f1eeb12..fceb014 100644 --- a/Background.h +++ b/Background.h @@ -21,16 +21,19 @@ class Background{ Point2D mPos;/// mSprites;/**< Vector of all sprites on the level. \todo Maybe make into map? */ - void DrawBG();/**< Draws the Background. \todo Why is this in existance? */ + void DrawBG();/**< Draws the Background. \todo make this draw the current level*/ void DrawIMG();/**< Draws an image to the screen. (Not implemented) */ void DrawIMG(SDL_Surface *img, int x, int y);/**< Draws the specified image to the screen at location (x,y) */ void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2);/**< Draws an image at the specified location (x,y) that is blitted with width w and height h from the point (x2,y2) of the given image */ diff --git a/Sprite.cpp b/Sprite.cpp index 116e8f1..40cc00e 100644 --- a/Sprite.cpp +++ b/Sprite.cpp @@ -2,37 +2,36 @@ #include using std::cout; using std::endl; - Sprite::Sprite(SDL_Surface *screen, std::string name, Animation *anim) : - mFrame(0), - mCurrentAnimation(0), mDrawn(0), mVisible(true), mLastUpdate(0), + mActor(anim), mScreen(screen) + /** \todo implement name and mName seee if I even need both of them. */ { - //later add a part that adds name to list of level sprites - //Game.Level.SpriteList.pushback(name); - mSpriteAnimations.push_back(anim); - if(mSpriteAnimations[mCurrentAnimation] -> mBuilt) + /** \todo Later add a part that adds name to list of level sprites + Game.Level.SpriteList.pushback(name); + */ + if(mActor.mAnimations[mActor.mCurrentAnimation] -> mBuilt) { - if (mSpriteAnimations[mCurrentAnimation]->mNumFrames > 1) mAnimating = 1; + if (mActor.mAnimations[mActor.mCurrentAnimation]->mNumFrames > 1) mAnimating = 1; } } void Sprite::draw() { if(mAnimating == 1) { - if(mLastUpdate+mSpriteAnimations[mCurrentAnimation]->mAnim[mFrame].pause*mSpeed mSpriteAnimations[mCurrentAnimation]->mNumFrames-1) mFrame=0; + if(mLastUpdate+mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame].pause*mSpeed mActor.mAnimations[mActor.mCurrentAnimation]->mNumFrames-1) mActor.mFrame=0; mLastUpdate = SDL_GetTicks(); } } SDL_Rect dest; - dest.x = mX; - dest.y = mY; + dest.x = mPos.X; + dest.y = mPos.Y; if(mVisible == true) - SDL_BlitSurface(mSpriteAnimations[mCurrentAnimation]->mAnim[mFrame].image,NULL,mScreen,&dest); + SDL_BlitSurface(mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame].image,NULL,mScreen,&dest); } diff --git a/Sprite.h b/Sprite.h index ec39f55..dbca2ba 100644 --- a/Sprite.h +++ b/Sprite.h @@ -1,44 +1,52 @@ #ifndef SPRITE #define SPRITE -#include "Animation.h" #include -#include +#include +#include "fns.h" +#include "Actor.h" + +/** + Characters and other mobile objects displayed on screen. + + This class is tasked with the following: + - loading and controlling an Animation + - movement of objects + - check collision with other objects + */ class Sprite { public: Sprite(SDL_Surface *screen, std::string name, Animation *anim); - void draw(); - void setAnimation(int animation){ mCurrentAnimation = animation; } - int getAnimation(){ return mCurrentAnimation; } - void setFrame(int frame) { mFrame = frame; } - int getFrame() { return mFrame; } - void setSpeed(float speed) {mSpeed = speed;} - float getSpeed() {return mSpeed;} - void toggleAnim(){ mAnimating = !mAnimating;} - void startAnim() {mAnimating = 1;} - void stopAnim() {mAnimating = 0;} - void rewind() {mFrame = 0;} - void xadd(int num) {mX += num;} - void yadd(int num) {mY += num;} - void xset(int x) {mX = x;} - void yset(int y) {mY = y;} - void setPosition(int x, int y) {mX = x; mY = y;} + void draw();/**< draws Sprite. */ + void setAnimation(int animation){ mActor.mCurrentAnimation = animation; }/**< changes to the specified animation beginning at 0. */ + int getAnimation(){ return mActor.mCurrentAnimation; }/**< returns active animation. */ + void setFrame(int frame) { mActor.mFrame = frame; }/**< cahnges to the specified frame of the animation beginning at 0. */ + int getFrame() { return mActor.mFrame; }/**< returns active frame. */ + void setSpeed(float speed) {mSpeed = speed;}/**< sets the Sprite's speed. */ + float getSpeed() {return mSpeed;}/**< returns a Sprite's current speed. */ + void toggleAnim(){ mAnimating = !mAnimating;}/**< Pauses or resumes an animation. */ + 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. */ std::string name; private: - std::string mName; - int mFrame; - int mX,mY; - bool mAnimating; - int mCurrentAnimation; - bool mDrawn; - bool mVisible; - int mAnimation; - float mSpeed; - long mLastUpdate; - std::vector mSpriteAnimations; - SDL_Surface *mScreen; - int ZOrder; + std::string mName;/**< Sprite's name */ + Point2D mPos; + int mX,mY; /**< Sprite's position \todo make a 2D point class and use instead. */ + 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 */ + float mSpeed;/**< Movement speed of the Sprite. */ + long mLastUpdate;/**< Number that indicates when the Sprite has last updated. Overflows in about 24 days so no worries. */ + Actor mActor;/**< This Sprite's Actor. */ + SDL_Surface *mScreen;/**< Screen to be drawn to. */ + int ZOrder;/**< Stacking order. Determines what draws on top. \todo implement. */ }; #endif diff --git a/Text.h b/Text.h index be47bde..7ec5109 100644 --- a/Text.h +++ b/Text.h @@ -5,6 +5,13 @@ #include #include +/** + On-screen text + + This class is tasked with the following: + - displaying text on screen. + */ + class Text { public: diff --git a/fns.cpp b/fns.cpp index b90fd11..607f0bf 100644 --- a/fns.cpp +++ b/fns.cpp @@ -13,30 +13,30 @@ SDL_Surface* LoadImage( std::string filename ) SDL_Surface* compatible_image = NULL; filename="ArtAssets/"+filename; - if(filename.c_str() == NULL) // check to see if a filename was provided + if(filename.c_str() == NULL) /**< check to see if a filename was provided. */ { printf("No Filename %s\n\n",filename.c_str()); - return NULL;// if not exit the function + return NULL;/**< if not exit the function */ } - // load the image using our new IMG_Load function from sdl-Image1.2 + /** Load the image using our new IMG_Load function from sdl-Image1.2 */ loaded_image = IMG_Load( filename.c_str() ); - if(!loaded_image) // check to see if it loaded properly + if(!loaded_image) /**< check to see if it loaded properly */ { printf("Error opening %s\n\n",filename.c_str()); return NULL; } - // the image loaded fine so we can now convert it to the current display depth + /** the image loaded fine so we can now convert it to the current display depth */ compatible_image = SDL_DisplayFormat( loaded_image ); - // Destroy the old copy + /** Destroy the old copy */ SDL_FreeSurface( loaded_image ); - // return a pointer to the newly created display compatible image + /** return a pointer to the newly created display compatible image */ return compatible_image; } diff --git a/fns.h b/fns.h index dc9759c..5586a4b 100644 --- a/fns.h +++ b/fns.h @@ -3,7 +3,52 @@ #include #include -SDL_Surface* LoadImage( std::string filename ); +SDL_Surface* LoadImage( std::string filename );/**< Loads supported images. */ + +//class SizeD; +/** 2D position or vector placed here because of general access*/ +class Point2D +{ + public: + friend class SizeD; + Point2D ():X(0),Y(0){} + Point2D (double x, double y):X(x),Y(y){} + Point2D (const Point2D& copy)/**< Copy object */ + { + X = copy.X; + Y = copy.Y; + } +// Point2D (const SizeD& copy)/**< Copy object */ /// \todo make SizeD work here +/* { + X = copy.width; + Y = copy.height; + } +*/ + /** \todo add typical vector functionality like length, nomal vectors etc. */ + double X;/**< X position */ + double Y;/**< Y Position */ +}; + +/** Just for more logical names for sizes of objects*/ +class SizeD +{ + public: + friend class Pont2D; + SizeD ():width(0),height(0){} + SizeD (double w, double h):width(w),height(h){} + SizeD (const SizeD& copy) + { + width = copy.width; + height = copy.height; + } + SizeD (const Point2D& copy) + { + width = copy.X; + height = copy.Y; + } + double width;/**< X position */ + double height;/**< Y Position */ +}; //template string to_string(const T& t); -- 2.11.0