From: Ivan Hernanez Date: Fri, 1 Jun 2012 03:04:13 +0000 (-0500) Subject: Translated Level class from c# (mostly) X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=d76737d8e9f9d2cba0c00223b1597f12765d4670;p=IvanGame.git Translated Level class from c# (mostly) changed textrue from unsigned int to GLuint added << for Point2D World object implements ZOrder got rid of SDL_Surface* screen from most items moved text to class Text Moved mName from Sprite to WorldObject Added update behavior to sprites Changed Loading to access loadinglevel instead of currentlevel (allowing loading of other levels) Added framework for pausing and menu screens changed currentlevel to int from uint so we can determine if the first level was loaded Reworked background to use textures (draws again but doesn't wrap yet) Implemented a lot of shit. --- diff --git a/Background.cpp b/Background.cpp index 021db5a..ba05aad 100644 --- a/Background.cpp +++ b/Background.cpp @@ -3,69 +3,110 @@ #include 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), - mScreenSize(ScreenSize) +Background::Background( std::string name, std::string filename, bool wrap, Point2D pos) : +WorldObject(name,-10000, pos), + wrapping(wrap) { - mPos = ScreenPosition; - mScreenSize.w = screen->w; - mScreenSize.h = screen->h; + load(filename); + cout< 0)//move back til we are at the spot to the left of the current background - x -= W; - int initx = (int)x; - while(y > 0) - y -= H; - for(y; y < Y; y += H) - for(x = initx; x < X; x += W){ - dest.x = (int)x; - dest.y = (int)y; - SDL_BlitSurface(mBackground, NULL, mScreen, &dest); - } - } - else { - dest.x = (int)mPos.x; - dest.y = (int)mPos.y; - SDL_BlitSurface(mBackground, &source, mScreen, &dest); - } - //*/ +void Background::update(){ } -SDL_Surface* Background::load(std::string filename){ - /*mBackground = LoadImage("Backgrounds/"+filename); + +int Background::load(std::string filename){ + /** Load image for Frame */ + SDL_Surface *temp=NULL; + if((temp = LoadImage("Backgrounds/"+filename)) == NULL) return -1;//Load image for Frame cout<<"Loaded file"<w,mBackground->h);///format, transparency[0], transparency[1], transparency[2])); + + /** Loads image into animation */ + SDL_Surface* surface = SDL_DisplayFormatAlpha(temp); + SDL_FreeSurface(temp); + width=surface->w; + height=surface->h; + + // Check that the image’s width is a power of 2 + if ( (surface->w & (surface->w - 1)) != 0 ) { + cout<<"warning: "<h & (surface->h - 1)) != 0 ) { + cout<<"warning: "<format->BytesPerPixel; + + GLenum texture_format=NULL; + + //contains an alpha channel + if(surface->format->Rmask==0x000000ff) + texture_format=GL_RGBA; + else + texture_format=GL_BGRA; + if(!(nofcolors==4 || nofcolors==3)) + { + cout<<"warning: the image is not truecolor...this will break "<w, surface->h, 0, + texture_format, GL_UNSIGNED_BYTE, surface->pixels ); + + return 0; } void Background::setWrap(bool tf){ diff --git a/Background.h b/Background.h index bfbcdf1..8ce2d99 100644 --- a/Background.h +++ b/Background.h @@ -19,32 +19,23 @@ using std::vector; class Background : public WorldObject{ private: - string _name;/// collisionData;///unload(); + for(unsigned int i=0, count = mLevels.size(); i < count; i++){ + if(mLevels[i]->getName() == name){ + mCurrentLevel=i; + return; + } + } + } + cout<<"Level "<getName() == name){ - mCurrentLevel=i; - this->mLevels[mCurrentLevel]->load(); + LoadingLevel = mLevels[i]; + this->mLevels[i]->load(); + LoadingLevel = NULL; + if(mCurrentLevel<0) + mCurrentLevel = i; return; } } @@ -134,6 +155,7 @@ void Game::run() return; } + setCurrentLevel("World"); /** Game Loop */ diff --git a/Game.h b/Game.h index 78467dc..81178d4 100644 --- a/Game.h +++ b/Game.h @@ -40,6 +40,12 @@ public: void setCurrentLevel(string name); /** + Loads content for the next level to play. + \param name Name of the level to load + */ + void loadCurrentLevel(string name); + + /** Gets the index of the current level being played. \return index of the current level */ @@ -58,7 +64,7 @@ public: SDL_Surface* Screen(){ return mScreen; } /** Retrns the Current FPS of the game */ - Uint32 getFPS() { return currentFPS;} + Uint32 getFPS() { return currentFPS; } /** The current Sprite selected by the game */ static Sprite* CurrentSprite; @@ -81,7 +87,7 @@ protected: private: static const Uint32 waitTime; - unsigned int mCurrentLevel;/**< Current Level index. */ + 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. */ map mBehaviors;/**< This level's Behaviors */ diff --git a/Level.cpp b/Level.cpp index ffe14cf..d2fcd46 100644 --- a/Level.cpp +++ b/Level.cpp @@ -2,19 +2,20 @@ #include "Game.h" #include "fns.h" #include +#include -Level::Level(SDL_Surface* screen) : mScreen(screen) +Level::Level() { mLoadBehavior = DoNothing; mUpdateBehavior = DoNothing; } -Level::Level(SDL_Surface* screen, string n, Condition winCond, Behavior loadBehave, Behavior updateBehave, Behavior endBehave) : mScreen(screen), mName(n), mBackground(NULL), Loaded(false), mTextures(map()), ToAdd(vector()), ToRemove(vector()) +Level::Level(string n, Condition winCond, Behavior loadBehave, Behavior updateBehave, Behavior endBehave) : mName(n), mBackground(NULL), Loaded(false), mTextures(map()), ToAdd(vector()), ToRemove(vector()) { /// Set behavior mLoadBehavior = loadBehave; mUpdateBehavior = updateBehave; - mEndBehavior = endBehave; + mUnloadBehavior = endBehave; mWinCondition = winCond; } @@ -30,10 +31,9 @@ void Level::DrawIMG(SDL_Surface *img, int x, int y) SDL_Rect dest; dest.x = x; dest.y = y; - SDL_BlitSurface(img, NULL, mScreen, &dest); + SDL_BlitSurface(img, NULL, Game::game()->Screen(), &dest); } - void Level::DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2) { SDL_Rect dest; @@ -44,15 +44,13 @@ void Level::DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2 src.y = y2; src.w = w; src.h = h; - SDL_BlitSurface(img, &src, mScreen, &dest); + SDL_BlitSurface(img, &src, Game::game()->Screen(), &dest); } - void Level::drawScene() { glLoadIdentity(); - Uint32 color; /** Create a black mBackgroundground using the mScreen pixel format (32 bpp) */ glClear(GL_COLOR_BUFFER_BIT); @@ -62,7 +60,7 @@ void Level::drawScene() mBackground->draw(); /** Draw Sprites*/ - DrawObjects(); + DrawSprites(); /** Draw Boundary Data */ DrawCollisions(); @@ -71,10 +69,10 @@ void Level::drawScene() SDL_GL_SwapBuffers(); } -void Level::DrawObjects() +void Level::DrawSprites() { - for (size_t i=0; idraw(); + for (size_t i=0,size=mSprites.size(); idraw(); } } @@ -104,16 +102,124 @@ void Level::postEvent(SDL_Event event) /** Will handle all movement and dynamic triggers. */ void Level::update(){ - mUpdateBehavior(); + sort(mWorldObjects.begin(),mWorldObjects.end()); + if (Loaded) + { + if (!Game::game()->Paused) + { + mUpdateBehavior(); + if (mWinCondition()) + { + unload(); + return; + } + for(unsigned int i=0, size = mWorldObjects.size(); iupdate(); + else + { + unload(); + return; + } + } + for(unsigned int i=0, size = ToRemove.size(); i::iterator ptr = mWorldObjects.begin(); ptr != mWorldObjects.end(); ptr++){ + if(*ptr == ToRemove[i]){ + delete *ptr; + mWorldObjects.erase(ptr); + removed=true; + break; + } + } + if(removed){ + for(vector::iterator ptr = mSprites.begin(); ptr != mSprites.end(); ptr++){ + if(*ptr == ToRemove[i]){ + mSprites.erase(ptr); + removed=true; + break; + } + } + } else{ + for(vector::iterator ptr = ToAdd.begin(); ptr != ToAdd.end(); ptr++){ + if(*ptr == ToRemove[i]){ + ToAdd.erase(ptr); + break; + } + } + } + } + } + ToRemove.clear(); + for(unsigned int i=0, size = ToAdd.size(); i(ToAdd[i])) + mSprites.push_back(sp); + } + ToAdd.clear(); + /// \todo do collisions + /*Collision.Update(); + foreach (WorldObject sp in mWorldObjects) + { + sp.DoCollisions(); + }*/ + } + else { + /// \todo pause/unpause + } + } + else { + /// \todo loading screen + } } void Level::load(){ + clearData(); mLoadBehavior(); + /// \todo Add menu + Loaded = true; } +void Level::unload(){ + mUnloadBehavior(); + clearData(); + Loaded = false; +} + +void Level::clearData(){ + /// \todo stop and delete sound + + //clear WorldObjects + for(unsigned int i=0,size=mWorldObjects.size(); i texts = vector(); + for(map::iterator it = mTextures.begin(),end=mTextures.end();it!=end;it++){ + glDeleteTextures(1, &it->second); + } + mTextures.clear(); + + //clear actors + mActors.clear(); + + //clear anims + mAnims.clear(); + + /// \todo clear collision data + + +} void Level::addSprite(Sprite* sp){ - mSprites.push_back(sp); + ToAdd.push_back(sp); } Sprite* Level::getSprite(string name){ @@ -126,12 +232,7 @@ Sprite* Level::getSprite(string name){ } void Level::removeSprite(Sprite* sp){ - for(vector::iterator ptr = mSprites.begin(); ptr != mSprites.end(); ptr++){ - if(*ptr == sp){ - mSprites.erase(ptr); - return; - } - } + ToRemove.push_back(sp); } void Level::addAnimation(Animation anim){ diff --git a/Level.h b/Level.h index 984c94f..27cde98 100644 --- a/Level.h +++ b/Level.h @@ -24,21 +24,21 @@ This class is tasked with the following: class Level { public: - Level(SDL_Surface* screen); + Level(); /** Level constructor - \param screen the Screen to be drawn to \param name of the level \param loadBehavior the Loading Behavior for this level (Run once). \param updateBehavior the Updating Behavior for this level (Run every loop). */ - Level(SDL_Surface* screen, string name, Condition winCond, Behavior loadBehave = DoNothing, Behavior updateBehave = DoNothing, Behavior endBehave = DoNothing); + 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 ps Sprite to remove */ @@ -50,14 +50,13 @@ public: 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 */ - SDL_Surface* getScreen(){return mScreen;}/**< gets the current level's name \return Level's SDL_Surface */ 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; + 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) */ protected://allow inheritance string mName; Background* mBackground;/**< Pointer to the current Background. */ - SDL_Surface *mScreen;/**< Pointer to the screen. */ 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 */ map mActors;/**< This level's actors. */ @@ -69,11 +68,12 @@ protected://allow inheritance 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 DrawObjects();/**< Draws all Sprites. */ + void DrawSprites();/**< Draws all Sprites. */ void DrawCollisions();/**< Draws all Collision data */ 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 mEndBehavior;/**< will be used to define the end action of the level as it closes*/ + 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 */ }; #endif diff --git a/LevelFns.h b/LevelFns.h index 13d0333..c700d02 100644 --- a/LevelFns.h +++ b/LevelFns.h @@ -6,27 +6,27 @@ ///\file this file should contain all Behaviors for Levels void LevelWorldLoad(){ - Level* l = Game::game()->getCurrentLevel(); + Level* l = Game::game()->LoadingLevel; - SDL_Surface* screen = l->getScreen(); + SDL_Surface* screen = Game::game()->Screen(); /// load background - l->setBackground(new Background(screen, "default", "bg.bmp"));//mBackground = LoadImage("Backgrounds/bg.bmp"); + l->setBackground(new Background("default", "bg.bmp"));//mBackground = LoadImage("Backgrounds/bg.bmp"); /** load animations */ l->addAnimation(Animation("viking.anim")); l->addAnimation(Animation("sun.anim")); /** load sprites */ - Sprite* vikings1 = new Sprite(screen, "viking1", l->getAnimation("viking.anim")); + Sprite* vikings1 = new Sprite("viking1", l->getAnimation("viking.anim")); vikings1->setPosition(0,0); vikings1->setSpeed(1); - Sprite* vikings2 = new Sprite(screen, "viking2", l->getAnimation("viking.anim")); + Sprite* vikings2 = new Sprite("viking2", l->getAnimation("viking.anim")); vikings2->setPosition(350,300); vikings2->setSpeed(1.5); - Sprite* sun = new Sprite(screen, "sun", l->getAnimation("sun.anim")); + Sprite* sun = new Sprite("sun", l->getAnimation("sun.anim")); sun->setPosition(480,50); sun->setSpeed(1); } @@ -39,14 +39,18 @@ void LevelWorldUpdate(){ Background* bg = LevelWorld->getBackground(); Uint8 *keys = SDL_GetKeyState(NULL); - if ( keys[SDLK_LEFT] ) { player->xadd(-1); } - if ( keys[SDLK_RIGHT] ) { player->xadd(1); } - if ( keys[SDLK_UP] ) { player->yadd(-1); } - if ( keys[SDLK_DOWN] ) { player->yadd(1); } - if ( keys[SDLK_a] ) { bg->xadd(-1); } - if ( keys[SDLK_d] ) { bg->xadd(1); } - if ( keys[SDLK_w] ) { bg->yadd(-1); } - if ( keys[SDLK_s] ) { bg->yadd(1); } + if(player){ + if ( keys[SDLK_LEFT] ) { player->xadd(-1); } + if ( keys[SDLK_RIGHT] ) { player->xadd(1); } + if ( keys[SDLK_UP] ) { player->yadd(-1); } + if ( keys[SDLK_DOWN] ) { player->yadd(1); } + } + if(bg){ + if ( keys[SDLK_a] ) { bg->xadd(-1); } + if ( keys[SDLK_d] ) { bg->xadd(1); } + if ( keys[SDLK_w] ) { bg->yadd(-1); } + if ( keys[SDLK_s] ) { bg->yadd(1); } + } } #endif \ No newline at end of file diff --git a/LoadResources.cpp b/LoadResources.cpp index 5fcd495..4b28646 100644 --- a/LoadResources.cpp +++ b/LoadResources.cpp @@ -5,6 +5,6 @@ ///\file this file should contain implementations for loading resources void Game::LoadResources(){ - mLevels.push_back(new Level(mScreen, "World", NeverEnd, LevelWorldLoad, LevelWorldUpdate)); + mLevels.push_back(new Level("World", NeverEnd, LevelWorldLoad, LevelWorldUpdate)); } diff --git a/Sprite.cpp b/Sprite.cpp index aad2f4e..8b76308 100644 --- a/Sprite.cpp +++ b/Sprite.cpp @@ -5,15 +5,19 @@ using std::cout; using std::endl; -Sprite::Sprite(SDL_Surface *screen, std::string name, Actor actor) : -mName(name), +Sprite::Sprite( std::string name, Actor actor) : + WorldObject(name), mDrawn(0), mLastUpdate(0), mActor(actor), - mScreen(screen) + mBehavior(DoNothing) { //add to current level - Game::game()->getCurrentLevel()->addSprite((this)); + Level* l = Game::game()->LoadingLevel; + if(l!=0) + l->addSprite((this)); + else + Game::game()->getCurrentLevel()->addSprite(this); if(mActor.mAnimations[mActor.mCurrentAnimation] -> mBuilt) { @@ -74,6 +78,10 @@ void Sprite::draw() } } +void Sprite::update(){ + mBehavior(); +} + vector& Sprite::getCollisionData(){ return mActor.mAnimations[mActor.mCurrentAnimation]->mFrames[mActor.mFrame].collisionData; } diff --git a/Sprite.h b/Sprite.h index 0bb6ab4..37f43e6 100644 --- a/Sprite.h +++ b/Sprite.h @@ -16,32 +16,30 @@ class Sprite : public WorldObject { public: - Sprite(SDL_Surface *screen, std::string name, Actor actor); + Sprite(std::string name, Actor actor); void setAnimation(int animation){ mActor.mCurrentAnimation = animation; }/**< changes to the specified animation beginning at 0. */ SpriteFrame* getAnimation(){ return &mActor.mAnimations[mActor.mCurrentAnimation]->mFrames[mActor.mFrame]; }/**< returns active animation. (actually the current frame within the animation) \todo see if this is slower maybe undo */ 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. */ - std::string getName(){ return mName; }/**< returns the Sprite's name */ 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 draw();/**< draws Sprite. */ void drawCollisions();/**< Draws Collision data for the Object (from outside) */ + void update();/**< Update to run each loop */ Sprite* collisionWithSprite(string name);/**< checks for collision with sprite of a given name. */ vector& getCollisionData();/**< Returns collision data */ private: - std::string mName;/**< Sprite's name */ bool mAnimating;/**< Tells whether to animate or not */ bool mDrawn;/**< Tells if the object has been drawn the first time */ 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. */ Behavior mBehavior;/**< Sprite's Behavior */ }; #endif diff --git a/Text.cpp b/Text.cpp index 0238f09..6807189 100644 --- a/Text.cpp +++ b/Text.cpp @@ -1,17 +1,32 @@ #include "Text.h" #include #include -#include "Game.h" +//#include "Game.h" #include "fns.h" #include using namespace std; +Text::Text(string name, string t, SDL_Color color) : WorldObject(name){ + // Load a font + font = TTF_OpenFont("FreeSans.ttf", 24); + + if(font){ + //SDL_Color text_color = {r,g, b}; + string txt="A journey of a thousand miles begins with a single step."; + SDL_Rect rect = {0,0,100,100}; + draw(); + } + else + cerr << "TTF_OpenFont() Failed: " << TTF_GetError() << endl; + + TTF_CloseFont(font); +} + void Text::draw() { const char* txt = text.c_str(); SDL_Surface *initial; SDL_Surface *intermediary; - SDL_Rect rect; SDL_Rect location = {mPos.x, mPos.y, width, height}; int w,h; Texture texture; @@ -43,9 +58,7 @@ void Text::draw() /* Draw a quad at location */ glBegin(GL_QUADS); - /* Recall that the origin is in the lower-left corner - That is why the TexCoords specify different corners - than the Vertex coors seem to. */ + glTexCoord2f(0.0f, 0.0f); glVertex2f(location.x , location.y); glTexCoord2f(1.0f, 0.0f); @@ -69,21 +82,5 @@ void Text::draw() glDeleteTextures(1, &texture); } -Text::Text(string t, SDL_Color color){ - // Load a font - font = TTF_OpenFont("FreeSans.ttf", 24); - - if(font){ - // Write text to surface - SDL_Surface *text; - //SDL_Color text_color = {r,g, b}; - string txt="A journey of a thousand miles begins with a single step."; - SDL_Rect rect = {0,0,100,100}; - draw(); - } - else - cerr << "TTF_OpenFont() Failed: " << TTF_GetError() << endl; - - TTF_CloseFont(font); -} - +void Text::update(){ +} \ No newline at end of file diff --git a/Text.h b/Text.h index 9ae9993..111a9f1 100644 --- a/Text.h +++ b/Text.h @@ -21,8 +21,9 @@ class Text : public WorldObject string text; SDL_Color color; void draw(); + void update(); int width; int height; - Text(string t, SDL_Color color); + Text(string name, string t, SDL_Color color); }; #endif diff --git a/WorldObject.h b/WorldObject.h index 27f0df0..b9dbe2a 100644 --- a/WorldObject.h +++ b/WorldObject.h @@ -6,7 +6,9 @@ class WorldObject { public: - WorldObject(int z = 0) : + WorldObject(std::string name,int z = 0, Point2D pos = Point2D()) : + mName(name), + mPos(pos), ZOrder(z), mVisible(true), mTransparency(1), @@ -16,17 +18,24 @@ public: 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. */ + void setZOrder(int i) { ZOrder=i; } + int getZOrder() { return ZOrder; } + std::string getName(){ return mName; }/**< returns the Sprite's name */ + 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! */ diff --git a/fns.h b/fns.h index 06a7794..c3c134b 100644 --- a/fns.h +++ b/fns.h @@ -4,6 +4,7 @@ #include /// \todo remove this this is just to make testing easy w/o gdb #include +#include using namespace std; ///Behaviors use functions that take nothing and return nothing @@ -15,7 +16,7 @@ typedef bool (*Condition) (); ///Condition that is always false static bool NeverEnd(){return false;} ///Texture name -typedef unsigned int Texture; +typedef GLuint Texture; ///deg/rad const float deg2rad = (float)(3.14159/180); @@ -54,6 +55,11 @@ class Point2D Point2D operator- (const Point2D& pt) const { return Point2D(x - pt.x, y - pt.y); } Point2D operator+= (Point2D& pt){ return add(pt); } Point2D operator-= (Point2D& pt){ return sub(pt); } + friend ostream &operator<<(ostream &out, Point2D p) //output + { + out<<"("<