class Behavior
{
public:
- Behavior();
- Behavior(string Name):name(Name){}/**< \todo finish this */
- virtual void load();/**< Loading Behavior*/
- virtual void update();/**< Update Behavior*/
- virtual void unload();/**< Delete Behavior*/
+ Behavior(){}
+ Behavior(string Name):name(Name){}/**< Loads functions from Game */
+ virtual void load(){}/**< Loading Behavior*/
+ virtual void update(){}/**< Update Behavior*/
+ virtual void unload(){}/**< Delete Behavior*/
protected:
string name;/**< Name of this behavior */
};
class LevelBehavior : public Behavior
{
public:
- LevelBehavior();
- virtual void load();/**< Loading Behavior*/
- virtual void update();/**< Update Behavior*/
- virtual void unload();/**< Delete Behavior*/
+ LevelBehavior(){}
+ virtual void load(){}/**< Loading Behavior*/
+ virtual void update(){}/**< Update Behavior*/
+ virtual void unload(){}/**< Delete Behavior*/
//Level* level;
};
class SpriteBehavior : public Behavior
{
public:
- SpriteBehavior();
- virtual void load();/**< Loading Behavior*/
- virtual void update();/**< Update Behavior*/
- virtual void unload();/**< Delete Behavior*/
+ SpriteBehavior(){}
+ virtual void load(){}/**< Loading Behavior*/
+ virtual void update(){}/**< Update Behavior*/
+ virtual void unload(){}/**< Delete Behavior*/
//Sprite* sprite;
};
#endif
break;
}
getCurrentLevel()->update();
+ if(Game::game()->ShowFPS)
+ cout<<Game::game()->getFPS()<<endl;
//obtain the current fps data.
deltaclock = SDL_GetTicks() - startclock;
startclock = SDL_GetTicks();
SDL_RemoveTimer(timer);
}
+Behavior* Game::getBehavior(string name){
+ Behavior* b = mBehaviors[name];
+ if(b){
+ return new Behavior(*b);
+ }
+ else
+ return NULL;
+}
+
void Game::loadLevel(std::string levelName){
for(unsigned int i=0; i< mLevels.size(); ++i)
if(mLevels[i]->getName() == levelName)
/** Retrns the Current FPS of the game */
Uint32 getFPS() { return currentFPS;}
+ Behavior* getBehavior(string name);/**<Gets the requested Behavior \param name Name of the behavior to obtain \return Copy of the requested Behavior. */
+
protected:
Game();
~Game();
private:
static const Uint32 waitTime;
- unsigned int mCurrentLevel; /**< Current Level index. */
+ unsigned int mCurrentLevel;/**< Current Level index. */
std::vector<Level*> mLevels;/**< Vector of pointers to all of the levels. \todo Make into map? */
SDL_Surface *mScreen;/**< The surface to draw to. */
+ map<string,Behavior*> mBehaviors;/**< This level's Behaviors */
void loadLevel(std::string levelName);/**< Loads a level by name. */
{
/** load background */
mBackground= new Background(screen);//mBackground = LoadImage("Backgrounds/bg.bmp");
+
+ mBehavior = new LevelBehavior();
}
Level::Level(SDL_Surface* screen,string n) : mScreen(screen), mName(n)
{
/** load background */
mBackground= new Background(screen, n);//mBackground = LoadImage("Backgrounds/bg.bmp");
+
+ mBehavior = new LevelBehavior();
}
-Level::Level(SDL_Surface* screen,string n, string behavior/** \todo implement obtaining correct behavior maybe a fn get Behavior */) : mScreen(screen), mName(n)
+Level::Level(SDL_Surface* screen,string n, string behaviorName) : mScreen(screen), mName(n)
{
- /** load background */
+ /// load background
mBackground= new Background(screen, n);//mBackground = LoadImage("Backgrounds/bg.bmp");
- /// \todo make this wotk
- //mBehavior.load();
+
+ /// Set behavior
+ mBehavior = getBehavior(behaviorName);
+
+ if(!mBehavior)
+ mBehavior = new LevelBehavior();
+
+ /// Complete load behavior
+ mBehavior->load();
}
Level::~Level()
/** Will handle all movement and dynamic triggers. */
void Level::update(){
- /// \todo fix this behavior too
- //mBehavior.update();
-
- if(Game::game()->ShowFPS)
- cout<<Game::game()->getFPS()<<endl;
-
+ mBehavior->update();
//check collision with sun sprite
mSprites[0]->collisionWithSprite("sun");
//check collision with sun sprite
return mSprites[i];
}
return NULL;//if a sprite wasn't found return null
-}
\ No newline at end of file
+}
+
+LevelBehavior* Level::getBehavior(string name){
+ Behavior* b = Game::game()->getBehavior(name);
+ if(LevelBehavior* lb = dynamic_cast<LevelBehavior*>(b)){
+ return new LevelBehavior(*lb);
+ }
+ else
+ return NULL;
+}
Level(SDL_Surface *screen, string name, string behavior);
~Level();
void drawScene();/**< Draws everything that is set to draw on the screen. */
- void LoadBG(string name);/**< Loads the Background. */
+ 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 */
virtual void update();/**< Loop that runs every game frame that calculates movement, placement, etc. as well as obtains key strokes (limited by keyboard hardware)*/
- void addSprite(Sprite* sp);///< add a Sprite to the list of sprites
- void removeSprite(Sprite* sp);///< remove the Sprite sp from the list of sprites
- void addActor(string name, Actor actor);///< add a Actor to the list of sprites
- void removeActor(string name);///< remove the Actor sp from the list of sprites
- string getName(){ return mName; }///< returns the current level's name
- Sprite* findSpriteByName(string name);///< returns the first Sprite with a given name
-
+ void addSprite(Sprite* sp);/**< add a Sprite to the list of sprites \param sp Sprite to add */
+ void removeSprite(Sprite* sp);/**< remove the Sprite sp from the list of sprites \param ps Sprite to remove */
+ 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 */
+ 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 */
+ LevelBehavior* getBehavior(string name);/**<Gets the requested Behavior \param name Name of the behavior to obtain \return Copy of the requested Behavior. */
protected://allow inheritance
string mName;
Background* mBackground;/**< Pointer to the current Background. */
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 */
-
+ LevelBehavior* mBehavior;
};
#endif
return s;
return NULL;//if there aren't collisions
}
+
+SpriteBehavior* Sprite::getBehavior(string name){
+ Behavior* b = Game::game()->getBehavior(name);
+ if(SpriteBehavior* sb = dynamic_cast<SpriteBehavior*>(b)){
+ return new SpriteBehavior(*sb);
+ }
+ else
+ return NULL;
+}
\ No newline at end of file
void drawCollisions();/**< Draws Collision data for the Object (from outside) */
Sprite* collisionWithSprite(string name);/**< checks for collision with sprite of a given name. */
vector<Collision*>& getCollisionData();/**< Returns collision data */
-
- private:
+ SpriteBehavior* getBehavior(string name);/**<Gets the requested Behavior \param name Name of the behavior to obtain \return Copy of the requested Behavior. */
+
+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 */
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. */
- //SpriteBehavior mBehavior;/**< \todo implement*/
+ SpriteBehavior* mBehavior;/**< Sprite's Behavior */
};
#endif