From 864bf9234e296e1db6e5ba8276c7000d66167dff Mon Sep 17 00:00:00 2001 From: Ivan Hernandez Date: Tue, 11 Jan 2011 16:48:34 -0600 Subject: [PATCH] Attempted add of behaviors. Causes unexpected errors need to think about Introduced Collision data. --- Animation.cpp | 1 + Animation.h | 2 ++ Background.h | 3 ++- Behavior.h | 6 ++---- Behaviors.h | 42 ++++++++++++++++++++++++++++++++++++++++++ Collision.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Level.cpp | 12 +++++++++++- Level.h | 8 ++++++-- LevelWorld.cpp | 16 ---------------- Sprite.h | 4 ++++ 10 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 Behaviors.h create mode 100644 Collision.h diff --git a/Animation.cpp b/Animation.cpp index 1b65d57..b21e01e 100644 --- a/Animation.cpp +++ b/Animation.cpp @@ -73,6 +73,7 @@ int Animation::loadAnimation(std::string animFile) } } } + /// \todo add collision info obtained from file. fin.close(); return 0; } diff --git a/Animation.h b/Animation.h index 63a597a..8db9525 100644 --- a/Animation.h +++ b/Animation.h @@ -1,5 +1,6 @@ #ifndef SPRITEBASE #define SPRITEBASE +#include "Collision.h" #include #include #include @@ -27,6 +28,7 @@ class Animation mNumFrames,/**< Number of frames in this Animation */ mW,/**< Animation's current width */ mH;/**< The animation's current Height */ + Collision collisionData; private: std::string mname;//add name to anim file HERE diff --git a/Background.h b/Background.h index 1a72d6d..51c0365 100644 --- a/Background.h +++ b/Background.h @@ -1,6 +1,7 @@ #ifndef BACKGROUND #define BACKGROUND #include "fns.h" +#include "Collision.h" #include #include @@ -23,7 +24,7 @@ class Background{ SizeD mScreenSize;/// -#include #include using std::vector; @@ -20,7 +18,7 @@ class Behavior { public: Behavior(); - Behavior(string Name):name(Name); + Behavior(string Name):name(Name){}/**< \todo finish this */ virtual void load();/**< Loading Behavior*/ virtual void update();/**< Update Behavior*/ virtual void unload();/**< Delete Behavior*/ diff --git a/Behaviors.h b/Behaviors.h new file mode 100644 index 0000000..7c949c4 --- /dev/null +++ b/Behaviors.h @@ -0,0 +1,42 @@ +#ifndef BEHAVIORS +#define BEHAVIORS +#include "Behavior.h" +#include +#include + +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: + - 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 diff --git a/Collision.h b/Collision.h new file mode 100644 index 0000000..752c97f --- /dev/null +++ b/Collision.h @@ -0,0 +1,53 @@ +#ifndef COLLISION +#define COLLISION +#include "fns.h" +#include +#include + +using std::vector; +using std::string; + +/** + This defines Collision boundaries and data for objects/levels + + This class is tasked with the following: + - being a parent container for actions. + */ + +class Collision +{ +public: + Collision(); + virtual bool rectColl(Collision &c); + virtual bool circColl(Collision &c); + /// \todo See this http://www.metanetsoftware.com/technique/tutorialA.html +protected: + string name;///< Name of this behavior \todo make this actually be useful +}; + +/** + This defines CollisionRectangle boundaries and data for objects/levels + + This class is tasked with the following: + - being a parent container for actions. + */ + +class CollisionRectangle : public Collision +{ +public: + CollisionRectangle(); +}; + +/** + This defines CollisionCircle boundaries and data for objects/levels + + This class is tasked with the following: + - being a parent container for actions. + */ + +class CollisionCircle : public Collision +{ +public: + CollisionCircle(); +}; +#endif diff --git a/Level.cpp b/Level.cpp index 1d83b1a..a884c46 100644 --- a/Level.cpp +++ b/Level.cpp @@ -12,6 +12,15 @@ Level::Level(SDL_Surface* screen,string n) : mScreen(screen), mName(n) /** load background */ mBackground= new Background(screen, n);//mBackground = LoadImage("Backgrounds/bg.bmp"); } + +Level::Level(SDL_Surface* screen,string n, string behavior/** \todo implement obtaining correct behavior maybe a fn get Behavior */) : mScreen(screen), mName(n) +{ + /** load background */ + mBackground= new Background(screen, n);//mBackground = LoadImage("Backgrounds/bg.bmp"); + /// \todo make this wotk + //mBehavior.load(); +} + Level::~Level() { for (size_t i = 0; i < mSprites.size(); ++i) { @@ -83,7 +92,8 @@ void Level::postEvent(SDL_Event event) /** Will handle all movement and dynamic triggers. */ void Level::update(){ - + /// \todo fix this too + //mBehavior.update(); } diff --git a/Level.h b/Level.h index efacc27..8ae7a22 100644 --- a/Level.h +++ b/Level.h @@ -2,8 +2,11 @@ #define LEVEL #include "Sprite.h" #include "Background.h" +#include "Behaviors.h" #include #include + + #include using std::vector; @@ -25,8 +28,9 @@ class Level public: Level(SDL_Surface *screen); Level(SDL_Surface *screen, string name); + Level(SDL_Surface *screen, string name, string behavior); ~Level(); - virtual void drawScene();/**< Draws everything that is set to draw on the screen. */ + 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 */ virtual void update();/**< Loop that runs every game frame that calculates movement, placement, etc. as well as obtains key strokes (limited by keyboard hardware)*/ @@ -40,12 +44,12 @@ 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 mSprites;/**< Vector of all sprites on the level. \todo Maybe make into map? This should be a list of World objects once implemented.*/ 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. */ - map mActors;/**< This level's actors. */ vector mAnim;/**< This level's Animations */ }; diff --git a/LevelWorld.cpp b/LevelWorld.cpp index 5e36006..3883e00 100644 --- a/LevelWorld.cpp +++ b/LevelWorld.cpp @@ -26,23 +26,7 @@ LevelWorld::LevelWorld(SDL_Surface* screen) : mSprites.push_back(sun); } -void LevelWorld::drawScene() -{ - Uint32 color; - /** 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 */ - mBackground->draw(); - - /** Draw Sprites*/ - DrawSprites(); - - /** Flip the working image buffer with the mScreen buffer */ - SDL_Flip (mScreen); -} /** Will handle all movement and dynamic triggers. */ void LevelWorld::update() diff --git a/Sprite.h b/Sprite.h index 61d1aad..70f585c 100644 --- a/Sprite.h +++ b/Sprite.h @@ -4,6 +4,8 @@ #include #include "fns.h" #include "Actor.h" +#include "Behaviors.h" +#include "Collision.h" /** Characters and other mobile objects displayed on screen with animations. @@ -44,6 +46,8 @@ class Sprite SDL_Surface *mScreen;/**< Screen to be drawn to. */ Point2D mPos;/**< Object's position */ bool mVisible;/**< Determine if Object should be visible */ + //SpriteBehavior mBehavior;/**< \todo implement*/ + Collision collisionData;/**< Collision data \todo implement*/ int ZOrder;/**< Stacking order. Determines what draws on top. \todo implement. */ }; #endif -- 2.11.0