Behavriors implemented removed extraneous code
authorIvan Hernanez <iturtleman128@gmail.com>
Mon, 8 Aug 2011 04:31:00 +0000 (23:31 -0500)
committerIvan Hernanez <iturtleman128@gmail.com>
Mon, 8 Aug 2011 04:31:00 +0000 (23:31 -0500)
20 files changed:
Animation.cpp
Animation.h
ArtAssets/Sprites/sun.anim
ArtAssets/Sprites/viking.anim
Behavior.h [deleted file]
Behaviors.h
CMakeLists.txt
Game.cpp
Game.h
Level.cpp
Level.h
LevelFns.h [new file with mode: 0644]
LevelWorld.cpp [deleted file]
LevelWorld.h [deleted file]
LoadLevels.h [deleted file]
LoadResources.cpp [new file with mode: 0644]
Sprite.cpp
Sprite.h
fns.h
game.vcxproj

index 85d590c..04fc82b 100644 (file)
 #include "fns.h"
 using namespace std;
 
-Animation::Animation(std::string animFile)
+Animation::Animation(std::string animFile):mName(animFile)
+{
+       loadAnimation(animFile);
+}
+
+Animation::Animation(std::string animFile, string name):mName(name)
 {
        loadAnimation(animFile);
 }
index 2f57b39..36f836b 100644 (file)
@@ -19,15 +19,15 @@ class Animation
 {
        public:
        Animation(std::string animFile);
+       Animation(std::string animFile, string name);
        int loadAnimation(std::string animFile);/**< Loads the Animations from a file in the specified format. */
        SpriteFrame *mAnim;/**< Pointer to the current animation. As an array of SpriteFrames */
        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
+       bool operator==(Animation a){return mName==a.mName;}
+       std::string mName;//add name to anim file
 };
 
 #endif
index b466db1..c4fbf5b 100644 (file)
@@ -1,6 +1,6 @@
 #Number of Frames 
 #ArtAssets/ milisec    Transparency
-#filename      pause   r       g       b       xOffset yOffset ( collisionType <Circle has offset, radius | rectangle has offset, width, height>, ... )
+#filename      pause   r       g       b       xOffset yOffset ( <n | c | r> <c=circle has offset, radius | r=rectangle has offset, width, height>, ... )
 NumFrames: 4
 sun1.bmp       20      0 0 255 0.0 0.0 ( c 0.0 0.0 10.0 )
 sun2.bmp       20      0 0 255 0.0 0.0 ( c 0.0 0.0 10.0 )
index 22b240c..e4fcbee 100644 (file)
@@ -1,6 +1,6 @@
 #Number of Frames 
 #ArtAssets/ milisec    Transparency
-#filename      pause   r       g       b       xOffset yOffset ( <n | c | r> <Circle has offset, radius | rectangle has offset, width, height>, ... )
+#filename      pause   r       g       b       xOffset yOffset ( <n | c | r> <c=circle has offset, radius | r=rectangle has offset, width, height>, ... )
 NumFrames: 9
 viking1.bmp 50 0 255 0 0.0 0.0 ( r 0 0 150.0 100.0 )
 viking2.bmp 50 0 255 0 0.0 0.0 ( r 0 0 150.0 100.0 )
diff --git a/Behavior.h b/Behavior.h
deleted file mode 100644 (file)
index 0c21a65..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef __BEHAVIOR_H__
-#define __BEHAVIOR_H__
-#include "fns.h"
-#include <vector>
-#include <string>
-
-using std::vector;
-using std::string;
-
-/**
-  This is an action that a Behavior, Sprite, or other object can have.
-
-  This class is tasked with the following:
-    - being a parent container for actions.
- */
-
-class Behavior
-{
-public:
-       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 */
-};
-#endif
index fe72e9b..795329a 100644 (file)
@@ -1,42 +1,13 @@
 #ifndef __BEHAVIORS_H__
 #define __BEHAVIORS_H__
-#include "Behavior.h"
 #include <vector>
 #include <string>
+#include "Game.h"
 
 using std::vector;
 using std::string;
 
-/**
-  This is an action that a Behavior, Sprite, or other object can have.
+///\file this file should contain all Behaviors for WorldObjects inlcuding Backgrounds
 
-  This class is tasked with the following:
-    - All actions for the World Level.
- */
 
-class LevelBehavior : public  Behavior
-{
-public:
-       LevelBehavior(){}
-       virtual void load(){}/**< Loading Behavior*/
-       virtual void update(){}/**< Update Behavior*/
-       virtual void unload(){}/**< Delete Behavior*/
-       //Level* level;
-};
-
-/**
-  This is an action that a Behavior, Sprite, or other object can have.
-
-  This class is tasked with the following:
-    - All actions for Sprites.
- */
-class SpriteBehavior : public  Behavior
-{
-public:
-       SpriteBehavior(){}
-       virtual void load(){}/**< Loading Behavior*/
-       virtual void update(){}/**< Update Behavior*/
-       virtual void unload(){}/**< Delete Behavior*/
-       //Sprite* sprite;
-};
 #endif
index b7cb69c..e5fe16e 100644 (file)
@@ -4,6 +4,6 @@ project(game)
 find_package(SDL REQUIRED)
 find_package(SDL_image REQUIRED)
 
-add_executable(game Animation.cpp fns.cpp Game.cpp Level.cpp main.cpp WorldObject.cpp Sprite.cpp Text.cpp Actor.cpp Background.cpp LevelWorld.cpp Collision.cpp)
+add_executable(game Animation.cpp fns.cpp Game.cpp Level.cpp main.cpp WorldObject.cpp Sprite.cpp Text.cpp Actor.cpp Background.cpp Collision.cpp LoadResources.cpp)
 
 target_link_libraries(game ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY})
index 8f4ffde..07bcd90 100644 (file)
--- a/Game.cpp
+++ b/Game.cpp
@@ -2,7 +2,6 @@
 #include "fns.h"
 #include <string>
 #include <iostream>
-#include "LoadLevels.h"
 
 const Uint32 Game::waitTime = 1000/60; /* ms */
 
@@ -10,8 +9,8 @@ const Uint32 Game::waitTime = 1000/60; /* ms */
 Game* Game::m_instance = NULL;
 
 /** This function is called to create an instance of the class.
-Calling the constructor publicly is not allowed.
-The constructor is private and is only called by this Instance function.
+       Calling the constructor publicly is not allowed.
+       The constructor is private and is only called by this Instance function.
 */
 Game* Game::game(){
        if(!m_instance)
@@ -39,12 +38,10 @@ Game::Game() : mCurrentLevel(0), mScreen(0), ShowCollisions(false), ShowFPS(fals
        SDL_WM_SetCaption("Ivan's Game", NULL);
 
        SDL_ShowCursor(0);
-       /** Create the first level if there are none */
-       LoadLevels l(mScreen);
-       if(l.levels.size() == 0)
-               mLevels.push_back(new Level(mScreen));
-       else
-               mLevels = l.levels;
+       
+       /** Load Resources */
+       LoadResources();
+       
        // set start time for fps calc
        startclock = SDL_GetTicks();
 }
@@ -70,6 +67,22 @@ int Game::getLevelIndex()
        return mCurrentLevel;
 }
 
+void Game::setCurrentLevel(string name){
+       for(unsigned int i=0, count = mLevels.size(); i < count; i++){
+               if(mLevels[i]->getName() == name){
+                       mCurrentLevel=i;
+                       this->mLevels[mCurrentLevel]->load();
+                       return;
+               }
+       }
+       cout<<"Level "<<name<<" does not exist."<<endl;
+}
+
+int Game::getLevelCount()
+{
+       return mLevels.size();
+}
+
 void Game::run()
 {
        bool done = false;
@@ -80,6 +93,8 @@ void Game::run()
                return;
        }
 
+       setCurrentLevel("World");
+
        /** Game Loop */
        while (!done) {
                /** This will let us track events */
@@ -125,9 +140,11 @@ void Game::run()
                        getCurrentLevel()->postEvent(event);
                        break;
                }
+
                getCurrentLevel()->update();
                if(Game::game()->ShowFPS)
                        cout<<Game::game()->getFPS()<<endl;
+
                //obtain the current fps data.
                deltaclock = SDL_GetTicks() - startclock;
                startclock = SDL_GetTicks();
@@ -138,23 +155,6 @@ void Game::run()
        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)
-                       mCurrentLevel = i;
-               else
-                       std::cout<<"Level "<<levelName<<" not found."<<std::endl;
-}
-
 Uint32 Game::timerCallback(Uint32 interval, void* data)
 {
        SDL_Event event;
diff --git a/Game.h b/Game.h
index 3c27284..9c7c95c 100644 (file)
--- a/Game.h
+++ b/Game.h
@@ -2,6 +2,7 @@
 #define __GAME_H__
 
 #include "Level.h"
+#include "Sprite.h"
 #include <vector>
 #include <string>
 
@@ -33,11 +34,23 @@ public:
        Level* getCurrentLevel();
 
        /**
+         Sets the current level to play.
+         \param name Name of the level to load
+        */
+       void setCurrentLevel(string name);
+
+       /**
          Gets the index of the current level being played.
          \return index of the current level
         */
        int getLevelIndex();
 
+       /**
+         Gets the total count of levels.
+         \return number of levels
+        */
+       int getLevelCount();
+
        /** Makes the game loop begin and load objects. */
        void run();
 
@@ -47,13 +60,18 @@ public:
        /** 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. */
+       /** The current Sprite selected by the game */
+       static Sprite* CurrentSprite;
 
 protected:
        Game();
        ~Game();
-       /** This is the pointer to the Static Game object insuring only one*/
+       /** This is the pointer to the Static Game object insuring only one */
        static Game* m_instance;
+
+       /** Loads the game's resources. */
+       void LoadResources();
+
 private:
        static const Uint32 waitTime;
 
@@ -62,8 +80,6 @@ private:
        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. */
-
        static Uint32 timerCallback(Uint32 interval, void* data);
        
        //fps data calc
index b1e8fac..c32759b 100644 (file)
--- a/Level.cpp
+++ b/Level.cpp
@@ -4,33 +4,15 @@
 
 Level::Level(SDL_Surface* screen) : mScreen(screen)
 {
-       /** 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();
+       mLoadBehavior = DoNothing;
+       mUpdateBehavior = DoNothing;
 }
 
-Level::Level(SDL_Surface* screen,string n, string behaviorName) : mScreen(screen), mName(n)
+Level::Level(SDL_Surface* screen, string n, Behavior loadBehave, Behavior updateBehave) : mScreen(screen), mName(n), mBackground(NULL)
 {
-       /// load background
-       mBackground= new Background(screen, n);//mBackground = LoadImage("Backgrounds/bg.bmp");
-       
        /// Set behavior
-       mBehavior = getBehavior(behaviorName);
-
-       if(!mBehavior)
-               mBehavior = new LevelBehavior();
-
-       /// Complete load behavior
-       mBehavior->load();
+       mLoadBehavior = loadBehave;
+       mUpdateBehavior = updateBehave;
 }
 
 Level::~Level()
@@ -72,7 +54,8 @@ void Level::drawScene()
     SDL_FillRect(mScreen, NULL, color);
        
        /** Draw BG */
-       mBackground->draw();
+       if(mBackground!=NULL)
+               mBackground->draw();
        
        /** Draw Sprites*/
        DrawSprites();
@@ -117,11 +100,11 @@ void Level::postEvent(SDL_Event event)
 
 /** Will handle all movement and dynamic triggers. */
 void Level::update(){
-       mBehavior->update();
-       //check collision with sun sprite
-       mSprites[0]->collisionWithSprite("sun");
-       //check collision with sun sprite
-       mSprites[0]->collisionWithSprite("viking2");
+       mUpdateBehavior();
+}
+
+void Level::load(){
+       mLoadBehavior();
 }
 
 
@@ -129,6 +112,15 @@ void Level::addSprite(Sprite* sp){
        mSprites.push_back(sp);
 }
 
+Sprite* Level::getSprite(string name){
+       for(int i=0, count=mSprites.size(); i < count; i++){
+               if(mSprites[i]->getName()==name){
+                       return mSprites[i];
+               }
+       }
+       return NULL;
+}
+
 void Level::removeSprite(Sprite* sp){
        for(vector<Sprite*>::iterator ptr = mSprites.begin(); ptr != mSprites.end(); ptr++){
                if(*ptr == sp){
@@ -138,6 +130,28 @@ void Level::removeSprite(Sprite* sp){
        }
 }
 
+void Level::addAnimation(Animation anim){
+       mAnims.push_back(anim);
+}
+
+Animation* Level::getAnimation(string name){
+       for(int i=0, count=mAnims.size(); i < count; i++){
+               if(mAnims[i].mName==name){
+                       return &mAnims[i];
+               }
+       }
+       return NULL;
+}
+
+void Level::removeAnimation(Animation anim){
+       for(vector<Animation>::iterator ptr = mAnims.begin(); ptr != mAnims.end(); ptr++){
+               if(*ptr == anim){
+                       mAnims.erase(ptr);
+                       return;
+               }
+       }
+}
+
 void Level::addActor(string name, Actor actor){
        mActors.insert(make_pair(name, actor));
 }
@@ -154,12 +168,3 @@ Sprite* Level::findSpriteByName(string name){
        }
        return NULL;//if a sprite wasn't found return null
 }
-
-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;
-}
diff --git a/Level.h b/Level.h
index beda156..c13ddc1 100644 (file)
--- a/Level.h
+++ b/Level.h
@@ -2,7 +2,6 @@
 #define __LEVEL_H__
 #include "Sprite.h"
 #include "Background.h"
-#include "Behaviors.h"
 #include <vector>
 #include <map>
 
@@ -26,45 +25,49 @@ using std::string;
 class Level
 {
 public:
-       Level(SDL_Surface *screen);
+       Level(SDL_Surfacescreen);
        /**
                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);
-       /**
-               Level constructor
-               \param screen the Screen to be drawn to
-               \param name of the level
-               \param behavior the Behavior for this level.
-       */
-       Level(SDL_Surface *screen, string name, string behavior);
+       Level(SDL_Surface* screen, string name, Behavior loadBehave = DoNothing, Behavior updateBehave = 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 */
-       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 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 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 */
+       void addAnimation(Animation anim);/**< add a Actor to the list of sprites \param anim The actor to add */
+       Animation* Level::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 */
+       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 */
-       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. */
        SDL_Surface *mScreen;/**< Pointer to the screen. */
-       //LevelBehavior mBehavior;/**< will be used to define the start actions, update, and leaving actions of the level */
        vector<Sprite*> mSprites;/**< Vector of all sprites on the level. \todo Maybe make into map? This should be a list of World objects once implemented. \todo add accessor or move to public \todo make a map by name (for collisions) \todo make a list ordered by Zorder (for drawing*/
        map<string,Actor> mActors;/**< This level's actors. */
-       vector<Animation> mAnim;/**< This level's Animations */
+       vector<Animation> mAnims;/**< This level's Animations */
        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 */
-       LevelBehavior* mBehavior;
+       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 */
 };
 #endif
diff --git a/LevelFns.h b/LevelFns.h
new file mode 100644 (file)
index 0000000..7bb00a3
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef __LEVELFNS_H__
+#define __LEVELFNS_H__
+#include "Game.h"
+#include "Level.h"
+
+///\file this file should contain all Behaviors for Levels
+
+void LevelWorldLoad(){
+       Level* l = Game::game()->getCurrentLevel();
+
+       SDL_Surface* screen = l->getScreen();
+
+       /// load background
+       l->setBackground(new Background(screen, "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"));
+       vikings1->setPosition(10,30);
+       vikings1->setSpeed(1);
+
+       Sprite* vikings2 = new Sprite(screen, "viking2", l->getAnimation("viking.anim"));
+       vikings2->setPosition(350,300);
+       vikings2->setSpeed(1.5);
+
+       Sprite* sun = new Sprite(screen, "sun", l->getAnimation("sun.anim"));
+       sun->setPosition(480,50);
+       sun->setSpeed(1);
+}
+
+void LevelWorldUpdate(){
+       Level* LevelWorld = Game::game()->getCurrentLevel();
+
+       Sprite* player = LevelWorld->getSprite("viking1");
+
+       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); }
+}
+
+#endif
\ No newline at end of file
diff --git a/LevelWorld.cpp b/LevelWorld.cpp
deleted file mode 100644 (file)
index 0ef05a0..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "LevelWorld.h"
-#include "fns.h"
-
-LevelWorld::LevelWorld(SDL_Surface* screen) :
-       Level(screen, "World")
-{
-       /** load animations */
-       mAnim.push_back(Animation("viking.anim"));
-       mAnim.push_back(Animation("sun.anim"));
-
-       /** load sprites */
-       Sprite* vikings1 = new Sprite(screen, "viking1", &mAnim[0]);
-       vikings1->setPosition(10,30);
-       vikings1->setSpeed(1);
-
-       Sprite* vikings2 = new Sprite(screen, "viking2", &mAnim[0]);
-       vikings2->setPosition(350,300);
-       vikings2->setSpeed(1.5);
-
-       Sprite* sun = new Sprite(screen, "sun", &mAnim[1]);
-       sun->setPosition(480,50);
-       sun->setSpeed(1);
-       
-       mSprites.push_back(vikings1);
-       mSprites.push_back(vikings2);
-       mSprites.push_back(sun);
-}
-
-
-
-/** Will handle all movement and dynamic triggers. */
-void LevelWorld::update()
-{
-       Uint8 *keys = SDL_GetKeyState(NULL);
-       if ( keys[SDLK_LEFT] ) { mSprites[0]->xadd(-1); }
-       if ( keys[SDLK_RIGHT] ) { mSprites[0]->xadd(1); }
-       if ( keys[SDLK_UP] ) { mSprites[0]->yadd(-1); }
-       if ( keys[SDLK_DOWN] ) { mSprites[0]->yadd(1); }
-       if ( keys[SDLK_a] ) { mBackground->xadd(-1); }
-       if ( keys[SDLK_d] ) { mBackground->xadd(1); }
-       if ( keys[SDLK_w] ) { mBackground->yadd(-1); }
-       if ( keys[SDLK_s] ) { mBackground->yadd(1); }
-       Level::update();
-}
-
diff --git a/LevelWorld.h b/LevelWorld.h
deleted file mode 100644 (file)
index 6084926..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef __LEVELWORLD_H__
-#define __LEVELWORLD_H__
-#include "Level.h"
-
-/**
-  This is a stand alone Level that will have varying jobs in respect to the LevelWorld map
-
-  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 for the Level
- */
-
-class LevelWorld : public Level
-{
-public:
-       LevelWorld(SDL_Surface *screen);
-       void drawScene();/**< Draws everything that is set to draw on the screen. */
-       void update();/**< Loop that runs every game frame that calculates movement, placement, etc.  as well as obtains key strokes (limited by keyboard hardware)*/
-};
-#endif
diff --git a/LoadLevels.h b/LoadLevels.h
deleted file mode 100644 (file)
index 878d499..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef __LOADLEVELS_H__
-#define __LOADLEVELS_H__
-#include <vector>
-#include "fns.h"
-
-/// Add all levels and includes here
-#include "Level.h"
-#include "LevelWorld.h"
-
-using namespace std;
-
-
-/**                                                           
-  This is a container for creating all the levels in a neat location so as not to bulk up the Game class     
-                                                              
-  This class is tasked with the following:
-               - Creating all the levels.
- */  
-class LoadLevels{
-public:
-       LoadLevels(SDL_Surface* screen){
-               levels.push_back(new LevelWorld(screen));
-       }
-
-       vector<Level*> levels;
-};
-#endif
diff --git a/LoadResources.cpp b/LoadResources.cpp
new file mode 100644 (file)
index 0000000..64d02d7
--- /dev/null
@@ -0,0 +1,10 @@
+#include "Game.h"
+#include "fns.h"
+#include "LevelFns.h"
+
+///\file this file should contain implementations for loading resources
+
+void Game::LoadResources(){
+       mLevels.push_back(new Level(mScreen, "World", LevelWorldLoad, LevelWorldUpdate));
+}
+
index 2e9a025..140a825 100644 (file)
@@ -10,9 +10,9 @@ mName(name),
        mActor(actor),
        mScreen(screen)
 {
-       /** \todo Later add a part that adds name to list of level sprites 
-       Game.Level.SpriteList.pushback(name);
-       */
+       //add to current level
+       Game::game()->getCurrentLevel()->addSprite((this));
+
        if(mActor.mAnimations[mActor.mCurrentAnimation] -> mBuilt)
        {
                if (mActor.mAnimations[mActor.mCurrentAnimation]->mNumFrames > 1) mAnimating = 1;
@@ -71,13 +71,4 @@ Sprite* Sprite::collisionWithSprite(string name){
                if(frame->collisionData[i]->checkCollisions(s->getCollisionData(), s->mPos + s->getAnimation()->animationPeg, mPos + frame->animationPeg))//if there is a collision
                        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
index b04ffcf..e3a8840 100644 (file)
--- a/Sprite.h
+++ b/Sprite.h
@@ -4,7 +4,6 @@
 #include <string>
 #include "fns.h"
 #include "Actor.h"
-#include "Behaviors.h"
 #include "WorldObject.h"
 
 /**
@@ -33,7 +32,7 @@ class Sprite : public WorldObject
        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 */
-       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 */
@@ -43,6 +42,6 @@ private:
        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;/**< Sprite's Behavior */
+       Behavior mBehavior;/**< Sprite's Behavior */
 };
 #endif
diff --git a/fns.h b/fns.h
index 1f04b80..2e65005 100644 (file)
--- a/fns.h
+++ b/fns.h
@@ -6,6 +6,10 @@
 #include <iostream>
 using namespace std;
 
+///Behaviors use functions that take nothing and return nothing
+typedef void (*Behavior) ();
+///As the name denotes, this just simply does nothing
+static void DoNothing(){}
 
 SDL_Surface* LoadImage( std::string filename );/**< Loads supported images. */
 
index c435619..bf0a361 100644 (file)
@@ -97,8 +97,7 @@
     <ClInclude Include="Frame.h" />
     <ClInclude Include="Game.h" />
     <ClInclude Include="Level.h" />
-    <ClInclude Include="LevelWorld.h" />
-    <ClInclude Include="LoadLevels.h" />
+    <ClInclude Include="LevelFns.h" />
     <ClInclude Include="Sprite.h" />
     <ClInclude Include="Text.h">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
     <ClCompile Include="fns.cpp" />
     <ClCompile Include="Game.cpp" />
     <ClCompile Include="Level.cpp" />
-    <ClCompile Include="LevelWorld.cpp" />
+    <ClCompile Include="LoadResources.cpp" />
     <ClCompile Include="main.cpp" />
     <ClCompile Include="Sprite.cpp" />
     <ClCompile Include="Text.cpp">