From: Ivan Hernandez Date: Tue, 31 Aug 2010 20:13:18 +0000 (-0500) Subject: added new files and made things work again X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=5cac19d69b9c2c7c7313ae1642a8607ded653dc9;p=IvanGame.git added new files and made things work again --- diff --git a/Actor.cpp b/Actor.cpp index 6a32c04..54c636e 100644 --- a/Actor.cpp +++ b/Actor.cpp @@ -1,26 +1,9 @@ +#include "Actor.h" //the beggining -{ +Actor::Actor(Animation *anim): mFrame(0), - mCurrentAnimation(0), - mSpriteAnimations.push_back(anim); - if(mSpriteAnimations[mCurrentAnimation] -> mBuilt) - { - if (mSpriteAnimations[mCurrentAnimation]->mNumFrames > 1) mAnimating = 1; - } -} -Actor::Draw() + mCurrentAnimation(0) { - if(mAnimating == 1) { - if(mLastUpdate+mSpriteAnimations[mCurrentAnimation]->mAnim[mFrame].pause*mSpeed mSpriteAnimations[mCurrentAnimation]->mNumFrames-1) mFrame=0; - mLastUpdate = SDL_GetTicks(); - } - } - SDL_Rect dest; - dest.x = mX; - dest.y = mY; - if(mVisible == true) - SDL_BlitSurface(mSpriteAnimations[mCurrentAnimation]->mAnim[mFrame].image,NULL,mScreen,&dest); + mAnimations.push_back(anim); } diff --git a/Actor.h b/Actor.h index 45ef5e8..26f4708 100644 --- a/Actor.h +++ b/Actor.h @@ -1,18 +1,28 @@ -#ifndef SPRITE -#define SPRITE +#ifndef ACTOR +#define ACTOR #include "Animation.h" #include #include -class Sprite +/** + Set of Animations + + This class is tasked with the following: + - keeping track of the current Animation's state + */ + + +class Actor { public: - void draw(); - std::vector mSpriteAnimations; - bool mAnimating; - int mCurrentAnimation; - bool mDrawn; - bool mVisible; - int mAnimation; -} + Actor(Animation *anim); + int mFrame;/**< The frame # */ + int mCurrentAnimation;/**< Index to the current loaded animation */ + int mAnimation;/**< \todo See if this is used anywhere. Else Del */ + std::vector mAnimations;/**< Vector of pointers to all of this sprite's Animations */ + + private: + +}; +#endif diff --git a/Animation.cpp b/Animation.cpp index a7a878d..1b65d57 100644 --- a/Animation.cpp +++ b/Animation.cpp @@ -60,12 +60,12 @@ int Animation::loadAnimation(std::string animFile) SDL_Surface *temp=NULL; if((temp = LoadImage("Sprites/"+file)) == NULL) return -1; - //set transparent color + /** Set transparent color */ SDL_SetColorKey(temp, SDL_SRCCOLORKEY, SDL_MapRGB(temp->format, transparency[0], transparency[1], transparency[2])); - //loads image into animation + /** Loads image into animation */ mAnim[count].image = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); - //sets frame delay and makes sure height and width are correct + /** sets frame delay and makes sure height and width are correct */ mAnim[count].pause = pause; if(!mW) mW = mAnim[count].image->w; if(!mH) mH = mAnim[count].image->h; diff --git a/Animation.h b/Animation.h index 57b3e81..63a597a 100644 --- a/Animation.h +++ b/Animation.h @@ -5,17 +5,28 @@ #include struct SpriteFrame{ - SDL_Surface *image; - int pause; + SDL_Surface *image;/**< Pointer to an image. */ + int pause;;/**< Tells the amount of time to pause between this frame and the next. */ }; +/** + An Animation + + This class is tasked with the following: + - loading sets of images into an animation set. +*/ + + class Animation { public: Animation(std::string animFile); - int loadAnimation(std::string animFile); - SpriteFrame *mAnim; - int mBuilt, mNumFrames, mW, mH; + int loadAnimation(std::string animFile);/**< Loads the Animations from a file in the specified format. */ + SpriteFrame *mAnim;/**< Pointer to the current animation. */ + int mBuilt,/**< Using as a bool */ + mNumFrames,/**< Number of frames in this Animation */ + mW,/**< Animation's current width */ + mH;/**< The animation's current Height */ private: std::string mname;//add name to anim file HERE diff --git a/Background.cpp b/Background.cpp index 3b72594..f60c988 100644 --- a/Background.cpp +++ b/Background.cpp @@ -1,8 +1,36 @@ #include "Background.h" +#include +using namespace std; -Background::Background(std::string name, std::string filename):_name(name){ - /** \todo Implememnt the constructor that gets image sizes and puts it together so that background can be used correctly. */ +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){ + + source.w = bgSize.width; + source.h = bgSize.height; + source.x = bgSamplePos.X; + source.y = bgSamplePos.Y; + + load(filename); + + cout<<"background "<<_name<<" created"<w,mBackground->h);/// #include @@ -13,17 +13,24 @@ class Background{ private: - std::string _name; - SizeD _imageSize; + std::string _name;///drawScene(); break; - // If our event reports a key being pressed down - // we process it + /** If our event reports a key being pressed down + we process it + */ case SDL_KEYDOWN: { Uint8 *keys = SDL_GetKeyState(NULL); + std::cout<<*keys< mLevels; - SDL_Surface *mScreen; + int mCurrentLevel; /**< Current Level index. */ + std::vector mLevels;/**< Vector of pointers to all of the levels. \todo Make into map? */ + SDL_Surface *mScreen;/**< The surface to draw to. */ - void addLevel(Level level); - void removeLevel(std::string levelName); - void loadLevel(std::string levelName); + void addLevel(Level level);/**< Adds a level to the vector. \todo Implement! */ + void removeLevel(std::string levelName);/**< Removes the level with given name from the vector. \todo Implement! */ + void loadLevel(std::string levelName);/**< Loads a level by name. \todo Implement! */ static Uint32 timerCallback(Uint32 interval, void* data); }; diff --git a/Level.cpp b/Level.cpp index 22f223b..27d3546 100644 --- a/Level.cpp +++ b/Level.cpp @@ -2,15 +2,15 @@ #include "fns.h" Level::Level(SDL_Surface* screen) : - mBackground(0), + //mBackground(), mScreen(screen), mVikingAnimation("viking.anim"), mSunAnimation("sun.anim") { - // load background - mBackground = LoadImage("Backgrounds/bg.bmp"); + /** load background */ + mBackground= new Background(screen);//mBackground = LoadImage("Backgrounds/bg.bmp"); - // load sprites + /** load sprites */ Sprite* vikings1 = new Sprite(screen, "viking1", &mVikingAnimation); vikings1->setPosition(10,30); vikings1->setSpeed(1); @@ -60,7 +60,8 @@ void Level::DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2 void Level::DrawBG() { - DrawIMG(mBackground, 0, 0); + //DrawIMG(mBackground, 0, 0); + mBackground->draw(); } @@ -68,16 +69,16 @@ void Level::drawScene() { Uint32 color; - // Create a black mBackgroundground using the mScreen pixel format (32 bpp) + /** Create a black mBackgroundground using the mScreen pixel format (32 bpp) */ color = SDL_MapRGB(mScreen->format, 0, 0, 0); SDL_FillRect(mScreen, NULL, color); - //Draw BG + /** Draw BG */ DrawBG(); DrawSprites(); - // Flip the working image buffer with the mScreen buffer + /** Flip the working image buffer with the mScreen buffer */ SDL_Flip (mScreen); } @@ -90,7 +91,7 @@ void Level::DrawSprites() void Level::LoadBG(std::string name) { - mBackground=LoadImage("Background"+name); + mBackground->load(name); } void Level::postEvent(SDL_Event event) @@ -102,6 +103,7 @@ void Level::postEvent(SDL_Event event) } } +/** Will handle all movement and dynamic triggers. */ void Level::update() { Uint8 *keys = SDL_GetKeyState(NULL); diff --git a/Level.h b/Level.h index 67a9bbf..f10d794 100644 --- a/Level.h +++ b/Level.h @@ -1,30 +1,45 @@ #ifndef LEVEL #define LEVEL #include "Sprite.h" +#include "Background.h" #include #include + using std::vector; using std::string; + +/** + This is a stand alone Level that will have varying jobs + + This class is tasked with the following: + - drawing the scence and all objects in order + - loading the background + - keeping track of animations + - moving objects + - handling events + */ + class Level { public: Level(SDL_Surface *screen); ~Level(); - void drawScene(); - void LoadBG(string name); - virtual void postEvent(SDL_Event event); - void update(); + void drawScene();/**< Draws everything that is set to draw on the screen. */ + void LoadBG(string name);/**< Loads the Background. */ + virtual void postEvent(SDL_Event event);/**< Passes along SDL events */ + void update();/**< Loop that runs every game frame that calculates movement, placement, etc. */ private: - SDL_Surface *mBackground; - SDL_Surface *mScreen; - vector mSprites; - void DrawBG(); - void DrawIMG(); - void DrawIMG(SDL_Surface *img, int x, int y); - void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2); - void DrawSprites(); + Background* mBackground;//SDL_Surface *mBackground;/**< Pointer to the current Background. */ //<\todochange this to a Background*; + SDL_Surface *mScreen;/**< Pointer to the screen. */ + vector 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 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 */ + void DrawSprites();/**< Draws all Sprites. */ - Animation mVikingAnimation, mSunAnimation; + Animation mVikingAnimation,/**< Viking animation. \todo make a storage location for Animations. */ + mSunAnimation;/**< Sun animation. */ }; #endif