]> git.mmlx.us Git - IvanGame.git/commitdiff
updates files and added better todo list as well as some slight
authorIvan Hernandez <iturtleman128@gmail.com>
Sat, 4 Sep 2010 20:14:20 +0000 (15:14 -0500)
committerIvan Hernandez <iturtleman128@gmail.com>
Sat, 4 Sep 2010 20:14:20 +0000 (15:14 -0500)
reworking of background and other classes.

Background.cpp
Background.h
Doxyfile
Level.h
Sprite.cpp
Sprite.h
Text.h
fns.cpp
fns.h

index f60c9885e45657db98bfe9f30ba66b63fb8a7f9b..18e69b6f4c1e26bb471f5fadc03cdb05c212e559 100644 (file)
@@ -2,8 +2,10 @@
 #include <iostream>
 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"<<endl;   
+       cout<<"background \""<<_name<<"\" created"<<endl;       
 }
 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.*/
        ///destination rectangle only position is used and describes where the output is drawn.
-       SDL_Rect dest;
-    dest.x = mPos.X;
-    dest.y = mPos.Y;
+       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
+               SDL_Rect dests;///<the place where the sample will be drawn (can be reused)
+               dests.x=0;
+               dests.y=0;
+               ///hanging off the right side
+               if(mPos.x+_imageSize > 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;
+}
index f1eeb12fac406ed691e03e5836e6a701743c1a89..fceb0148d99b311fd4b6554f056654be264fa282 100644 (file)
@@ -21,16 +21,19 @@ class Background{
        Point2D mPos;///<The current (x,y) position
        SizeD mScreenSize;///<This is the size of the screen to be drawn to. used to get the sections of the background when moving and for screen-at-a-time scrolling.
        SDL_Rect source;///< This is the rectangle that gets taken from the actual background image (h,w) determine the size of the rectangle to sample from the background image. (x,y) determine the position of the rectangle's top left corner on the actual background image.
+       bool wrapping;
        
 
        
        public:
-       Background(SDL_Surface *screen,std::string name="default", std::string filename="bg.bmp",Point2D ScreenPosition=Point2D(0,0), SizeD screenSize=SizeD(800,600)/** \todo figure out how to get the game window's size to the background.*/,Point2D bgSamplePos=Point2D(0,0), SizeD bgSize=SizeD(800,600));
+       Background(SDL_Surface *screen,std::string name="default", std::string filename="bg.bmp", bool wrap=true, Point2D ScreenPosition=Point2D(50,0), SizeD screenSize=SizeD(800,600)/** \todo figure out how to get the game window's size to the background.*/,Point2D bgSamplePos=Point2D(0,0), SizeD bgSize=SizeD(800,600));
        void draw();/**< Draw background. */
        std::string getName(){ return _name; }/** Returns name. */
        void setName(std::string name){ _name = name; }/** Set Name. */
        SizeD size(){ return _imageSize;}/** returns image size */
        SDL_Surface* load(std::string name="default");///< Loads a Bacground by name.
        SizeD getPosition(){return mPos;}
+       void setWrap(bool tf);
+       bool getWrap();
 };
 
index 6c2bfc9510a4c62a8bb8ffe384e016a30eff387c..1bd1d3face09062ce8e06291f16dda36e3e88169 100644 (file)
--- a/Doxyfile
+++ b/Doxyfile
@@ -593,7 +593,7 @@ RECURSIVE              = NO
 # excluded from the INPUT source files. This way you can easily exclude a 
 # subdirectory from a directory tree whose root is specified with the INPUT tag.
 
-EXCLUDE                = 
+EXCLUDE                = ./ArtAssets ./bin ./doc ./tutorials ./.git
 
 # The EXCLUDE_SYMLINKS tag can be used select whether or not files or 
 # directories that are symbolic links (a Unix filesystem feature) are excluded 
diff --git a/Level.h b/Level.h
index f10d7945dd8d739767df755e3497dfba47e69956..33ee952f6e462025d4a28a0ad94b2514cd064a9e 100644 (file)
--- a/Level.h
+++ b/Level.h
@@ -30,10 +30,10 @@ public:
        void update();/**< Loop that runs every game frame that calculates movement, placement, etc. */
 
 private:
-       Background* mBackground;//SDL_Surface *mBackground;/**< Pointer to the current Background. */ //<\todochange this to a Background*;
+       Background* mBackground;/**< Pointer to the current Background. \todo change this to a Background\current background also should be a vector or list of backgroundsfor the current level.*/
        SDL_Surface *mScreen;/**< Pointer to the screen. */
        vector<Sprite*> 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 */
index 116e8f149676be5769806c7c69b363d9160a6fdb..40cc00e3c396b4d4c7b705e33b31aeed06604d92 100644 (file)
@@ -2,37 +2,36 @@
 #include <iostream>
 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<SDL_GetTicks()) {
-                       mFrame++;
-                       if(mFrame > mSpriteAnimations[mCurrentAnimation]->mNumFrames-1) mFrame=0;
+               if(mLastUpdate+mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame].pause*mSpeed<SDL_GetTicks()) {
+                       mActor.mFrame++;
+                       if(mActor.mFrame > 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);
 }
 
index ec39f552896af23c4a5d86c105142bd4545c92c1..dbca2ba52ff46400d19ad2914272a033b4d7064c 100644 (file)
--- a/Sprite.h
+++ b/Sprite.h
@@ -1,44 +1,52 @@
 #ifndef SPRITE
 #define SPRITE
-#include "Animation.h"
 #include <SDL/SDL.h>
-#include <vector>
+#include <string>
+#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<Animation*> 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 be47bdefed92d0795f8ec42dc127e8f848b8014a..7ec5109e94afa445f962d06d65b5be183d59f82d 100644 (file)
--- a/Text.h
+++ b/Text.h
@@ -5,6 +5,13 @@
 #include <string>
 #include <SDL/SDL.h>
 
+/**
+  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 b90fd115f4015fe715702f68f668ed88a0a5f187..607f0bfd3dfdcfe7cf0d3e27566570f19f07f29d 100644 (file)
--- 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 dc9759c9b7fb80acb0401527aed6c361071dbc01..5586a4b7a962127b0da8dc7858a016ff973c940f 100644 (file)
--- a/fns.h
+++ b/fns.h
@@ -3,7 +3,52 @@
 #include <SDL/SDL.h>
 #include <string>
 
-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<class T> string to_string(const T& t);