From 986e60b8e4d14129f4b5e71d9bc3b628894c3d1e Mon Sep 17 00:00:00 2001 From: Matt Mullins Date: Fri, 15 Jun 2012 23:23:29 -0700 Subject: [PATCH] Documentation and comment formatting changes. --- Actor.h | 14 ++-- Animation.h | 23 +++--- Level.h | 249 ++++++++++++++++++++++++++++++++++++++++++++++------------ WorldObject.h | 116 +++++++++++++++++++++------ 4 files changed, 311 insertions(+), 91 deletions(-) diff --git a/Actor.h b/Actor.h index 0391f0a..449005d 100644 --- a/Actor.h +++ b/Actor.h @@ -14,16 +14,18 @@ class Actor { - public: +public: Actor(Animation *anim); Actor(std::vector anims); Actor(std::vector anims); - int mFrame;/**< The frame # */ - int mCurrentAnimation;/**< Index to the current loaded animation */ - std::vector mAnimations;/**< Vector of pointers to all of this sprite's Animations */ - private: - + /// The frame # + int mFrame; + /// Index to the current loaded animation + int mCurrentAnimation; + /// Vector of pointers to all of this sprite's Animations + std::vector mAnimations; +private: }; #endif diff --git a/Animation.h b/Animation.h index 9c445a3..dca4577 100644 --- a/Animation.h +++ b/Animation.h @@ -18,22 +18,25 @@ This class is tasked with the following: class Animation { public: - //variables - int mBuilt,/**< Tells if loading the Animation was successful */ - mNumFrames,/**< Number of frames in this Animation */ - mW,/**< Animation's current width */ - mH;/**< The animation's current Height */ + /// Tells if loading the Animation was successful + int mBuilt, + /// Number of frames in this Animation + mNumFrames, + /// Animation's current width + int mW, + /// The animation's current Height + int mH; std::vector Frames; - std::string mName;//add name to anim file - SpriteFrame *mFrames;/**< Pointer to the current animation. As an array of SpriteFrames */ + std::string mName; // add name to anim file + /// Pointer to the current animation. As an array of SpriteFrames + SpriteFrame *mFrames; - //Constructors Animation(); Animation(std::string animFile); Animation(std::string animFile, string name); - //Methods - int loadAnimation(std::string animFile);/**< Loads the Animations from a file in the specified format. */ + /// Loads the Animations from a file in the specified format. + int loadAnimation(std::string animFile); bool operator==(Animation a) {return mName==a.mName;} bool operator!=(Animation a) {return mName!=a.mName;} }; diff --git a/Level.h b/Level.h index af1f647..8ddb904 100644 --- a/Level.h +++ b/Level.h @@ -30,36 +30,140 @@ class Level public: Level(); /** - Level constructor - \param name of the level - \param loadBehave the Loading Behavior for this level (Run when loading). - \param updateBehave the Updating Behavior for this level (Run every loop). - \param endBehave the Unloading Behavior for this level (when leaving level). - \param winCond Returns a boolean telling the level that it shuold unload. - */ - Level(string name, Condition winCond, Behavior loadBehave = DoNothing, Behavior updateBehave = DoNothing, Behavior endBehave = DoNothing); + Level constructor + \param name name of the level + \param loadBehave the Loading Behavior for this level (Run when loading). + \param updateBehave the Updating Behavior for this level (Run every loop). + \param endBehave the Unloading Behavior for this level (when leaving level). + \param winCond Function thateturns a boolean telling the level that it shuold + unload. + */ + Level(string name, Condition winCond, Behavior loadBehave = DoNothing, + Behavior updateBehave = DoNothing, Behavior endBehave = DoNothing); + ~Level(); - void drawScene();/**< Draws everything that is set to draw on the screen. */ - void LoadBG(string name);/**< Loads the Background. \param name Name of the background to load */ - virtual void postEvent(SDL_Event event);/**< Passes along SDL events */ - void update();/**< Loop that runs every game frame that calculates movement, placement, etc. as well as obtains key strokes (limited by keyboard hardware)*/ - void load();/**< Runs load action*/ - void unload();/**< Runs load action*/ - void addSprite(Sprite* sp);/**< add a Sprite to the list of sprites \param sp Sprite to add */ - Sprite* getSprite(string name);/**< gets the first sprite with the given name \param name Name of the sprite \return Pointer to the requested Sprite */ - void removeSprite(Sprite* sp);/**< remove the Sprite sp from the list of sprites \param sp Sprite to remove */ - void addAnimation(Animation anim);/**< add a Actor to the list of sprites \param anim The actor to add */ - Animation* getAnimation(string name);/**< get a Actor* to the list of sprites \param name Name of the actor \return Pointer to the actor we requested or null */ - void removeAnimation(Animation anim);/**< remove an Actor to the list of sprites \param anim The actor to add */ - void addActor(string name, Actor actor);/**< add a Actor to the list of sprites \param name Name of the actor \param actor The actor to add */ - void removeActor(string name);/**< remove the Actor sp from the list of sprites \param name Name of the actor to remove */ - string getName() { return mName; }/**< returns the current level's name \return Level's name */ - void setBackground(Background* b) {mBackground=b;}/**< sets the current level's background \param b Background */ - Background* getBackground() {return mBackground;}/**< gets the current level's name \return Level's Background */ - Sprite* findSpriteByName(string name);/**< returns the first Sprite with a given name \param name Name of the sprite to return \return Pointer to the requested sprite */ - bool Loaded;/**< Shows if the level has loaded or not (level changing) */ - void Unload();/**< What should be done when this level is left (not deleted) */ - void closeFont(Font *);/**< Closes the font if not more texts are using it. */ + + /** + Draws everything that is set to draw on the screen. + */ + void drawScene(); + /** + Loads the Background. + \param name Name of the background to load + */ + void LoadBG(string name); + + /** + Passes along SDL events + */ + virtual void postEvent(SDL_Event event); + + /** + Loop that runs every game frame that calculates movement, placement, etc. + as well as obtains key strokes (limited by keyboard hardware) + */ + void update(); + + /** + Runs load action + */ + void load(); + + /** + Runs load action + */ + void unload(); + + /** + add a Sprite to the list of sprites + \param sp Sprite to add + */ + void addSprite(Sprite* sp); + + /** + gets the first sprite with the given name + \param name Name of the sprite + \return Pointer to the requested Sprite + */ + Sprite* getSprite(string name); + + /** + remove the Sprite sp from the list of sprites + \param sp Sprite to remove + */ + void removeSprite(Sprite* sp); + + /** + add a Actor to the list of sprites + \param anim The actor to add + */ + void addAnimation(Animation anim); + + /** + get a Actor* to the list of sprites + \param name Name of the actor + \return Pointer to the actor we requested or null + */ + Animation* getAnimation(string name); + + /** + remove an Actor to the list of sprites + \param anim The actor to add + */ + void removeAnimation(Animation anim); + + /** + add a Actor to the list of sprites + \param name Name of the actor + \param actor The actor to add + */ + void addActor(string name, Actor actor); + + /** + remove the Actor sp from the list of sprites + \param name Name of the actor to remove + */ + void removeActor(string name); + + /** + returns the current level's name + \return Level's name + */ + string getName() { return mName; } + + /** + sets the current level's background + \param b Background + */ + void setBackground(Background* b) {mBackground=b;} + + /** + gets the current level's name + \return Level's Background + */ + Background* getBackground() {return mBackground;} + + /** + returns the first Sprite with a given name + \param name Name of the sprite to return + \return Pointer to the requested sprite + */ + Sprite* findSpriteByName(string name); + + /** + Shows if the level has loaded or not (level changing) + */ + bool Loaded; + + /** + What should be done when this level is left (not deleted) + */ + void Unload(); + + /** + Closes the font if not more texts are using it. + */ + void closeFont(Font *); /** Add a Text object to be drawn on the screen @@ -67,34 +171,75 @@ public: */ void addText(Text* text); -protected://allow inheritance - string mName; - Background* mBackground;/**< Pointer to the current Background. */ - vector mWorldObjects;/**< Vector of all objects on the level. \todo make a list ordered by Zorder (for drawing)*/ - vector mSprites;/**< Vector of all sprites on the level */ - vector mText; /**< Text objects to be displayed */ - map mActors;/**< This level's actors. */ - vector mAnims;/**< This level's Animations */ - map mTextures;/**< Textures that have been loaded by the level. */ - vector ToAdd;/**< List of sprites that should be added this game loop */ - vector ToRemove;/**< List of sprites that should die after this game loop */ - vector< map > mFonts;/** List of all the fonts we have */ - HUD mHUD;/**< Display to draw on everything else */ - void DrawIMG();/**< Draws an image to the screen. (Not used) */ - 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 */ - void DrawSprites();/**< Draws all Sprites. */ - void DrawCollisions();/**< Draws all Collision data */ +protected: // allow inheritance + + /** + Draws an image to the screen. (Not used) + */ + void DrawIMG(); + + /** + Draws the specified image to the screen at location (x,y) + */ + void DrawIMG(SDL_Surface *img, int x, int y); + + /** + 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 + */ + void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2); + + /** + Draws all Sprites. + */ + void DrawSprites(); + + /** + Draws all Collision data + */ + void DrawCollisions(); /** Draws all Text elements on the screen. */ void DrawText(); - Behavior mLoadBehavior;/**< will be used to define the Load action of the level */ - Behavior mUpdateBehavior;/**< will be used to define the update action of the level */ - Behavior mUnloadBehavior;/**< will be used to define the end action of the level as it closes*/ - Condition mWinCondition;/**< Conditions for the level to wait upon before exiting.*/ - void clearData();/**< This will clear the data and make this level as if new */ + /** + This will clear the data and make this level as if new + */ + void clearData(); + + string mName; + /// Pointer to the current Background. + Background* mBackground; + /// Vector of all objects on the level. + vector mWorldObjects; + /// Vector of all sprites on the level + vector mSprites; + /// Text objects to be displayed + vector mText; + /// This level's actors. + map mActors; + /// This level's Animations + vector mAnims; + /// Textures that have been loaded by the level. + map mTextures; + /// List of sprites that should be added this game loop + vector ToAdd + /// List of sprites that should die after this game loop + vector ToRemove; + /// List of all the fonts we have + vector< map > mFonts; + /// Display to draw on everything else + HUD mHUD; + + /// will be used to define the Load action of the level + Behavior mLoadBehavior; + /// will be used to define the update action of the level + Behavior mUpdateBehavior; + /// will be used to define the end action of the level as it close + Behavior mUnloadBehavior; + /// Conditions for the level to wait upon before exiting + Condition mWinCondition; }; #endif diff --git a/WorldObject.h b/WorldObject.h index 2ebd9c6..593251b 100644 --- a/WorldObject.h +++ b/WorldObject.h @@ -14,33 +14,103 @@ public: mTransparency(1), mAngle(0), mScale(1) - {} - virtual void draw() = 0;/**< Draws the Object. */ - virtual void drawCollisions();/**< Draws Collision data for the Object */ - void drawCollisions(vector& vec, const Point2D& pos);/**< Draws Collision data for the Object */ - virtual void update() = 0;/**< Update to run each loop */ - 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. */ - Point2D getPosition() { return mPos; }/**< Gets the Sprite's position */ - void setTransparency(float f) { mTransparency = f>1?1:f<0?0:f;}/**< Sets the Sprite's transparency. \param f The sprite's transparancy [0,1] other values will be force set */ - float getTransparency() {return mTransparency;}/**< Gets the Sprite's transparency. */ - void setAngle(float a) { mAngle = a; while(a>360)a-=360;}/**< Sets the Sprite's angle in degrees. \param a Angle in degrees */ - float getAngle() {return mAngle;}/**< Gets the Sprite's angle. */ + { + } + + /** + Draws the Object. + */ + virtual void draw() = 0; + + /** + Draws Collision data for the Object + */ + virtual void drawCollisions(); + + /** + Draws Collision data for the Object + */ + void drawCollisions(vector& vec, const Point2D& pos); + + /** + Update to run each loop + */ + virtual void update() = 0; + + /** + Increase x coordiante by a given amount. + */ + void xadd(int num) {mPos.x += num;} + + /** + Increase y coordinate by a given amount. + */ + void yadd(int num) {mPos.y += num;} + + /** + Sets the Sprite's x Coordinate. + */ + void xset(int x) {mPos.x = x;} + + /** + Sets the Sprite's y coordinate. + */ + void yset(int y) {mPos.y = y;} + + /** + Sets the Sprite's x an y coordinate. + */ + void setPosition(int x, int y) {mPos.x = x; mPos.y = y;} + + /** + Gets the Sprite's position + */ + Point2D getPosition() { return mPos; } + + /** + Sets the Sprite's transparency. + \param f The sprite's transparancy [0,1] other values will be force set + */ + void setTransparency(float f) { mTransparency = f>1?1:f<0?0:f;} + + /** + Gets the Sprite's transparency. + */ + float getTransparency() {return mTransparency;} + + /** + Sets the Sprite's angle in degrees. + \param a Angle in degrees + */ + void setAngle(float a) { mAngle = a; while(a>360)a-=360;} + + /** + Gets the Sprite's angle. + */ + float getAngle() {return mAngle;} void setZOrder(int i) { ZOrder=i; } int getZOrder() { return ZOrder; } - std::string getName() { return mName; }/**< returns the Sprite's name */ + + /** + returns the Sprite's name + */ + std::string getName() { return mName; } bool operator<(WorldObject &rhs) { return ZOrder < rhs.getZOrder(); } protected: - std::string mName;/**< Sprite's name */ - Point2D mPos;/**< The current (x,y) position */ - bool mVisible;/**< Determine if Object should be visible */ - float mTransparency;/**< Transparency! */ - float mAngle;/**< Angle of rotation */ - float mScale;/**< Scale for the sprite*/ - int ZOrder;/**< Stacking order. Determines what draws on top. \todo implement. */ + /// Sprite's name + std::string mName; + /// The current (x,y) position + Point2D mPos; + /// Determine if Object should be visible + bool mVisible; + /// Transparency! + float mTransparency; + /// Angle of rotation + float mAngle; + /// Scale for the sprit + float mScale; + /// Stacking order. Determines what draws on top. \todo implement. + int ZOrder; }; #endif -- 2.11.0