Attempted add of behaviors. Causes unexpected errors need to think about
authorIvan Hernandez <iturtleman128@gmail.com>
Tue, 11 Jan 2011 22:48:34 +0000 (16:48 -0600)
committerIvan Hernandez <iturtleman128@gmail.com>
Tue, 11 Jan 2011 22:48:34 +0000 (16:48 -0600)
Introduced Collision data.

Animation.cpp
Animation.h
Background.h
Behavior.h
Behaviors.h [new file with mode: 0644]
Collision.h [new file with mode: 0644]
Level.cpp
Level.h
LevelWorld.cpp
Sprite.h

index 1b65d57..b21e01e 100644 (file)
@@ -73,6 +73,7 @@ int Animation::loadAnimation(std::string animFile)
                        }
        }
        }
+       /// \todo add collision info obtained from file.
   fin.close();
   return 0;
 }
index 63a597a..8db9525 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef SPRITEBASE
 #define SPRITEBASE
+#include "Collision.h"
 #include <string>
 #include <SDL/SDL.h>
 #include <SDL/SDL_image.h>
@@ -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
index 1a72d6d..51c0365 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef BACKGROUND
 #define BACKGROUND
 #include "fns.h"
+#include "Collision.h"
 #include <string>
 #include <iostream>
 
@@ -23,7 +24,7 @@ class Background{
        SizeD mScreenSize;///<This is the size of the screen to be drawn to. used to get the sections of the background when moving and for screen-at-a-time scrolling.
        SDL_Rect source;///< This is the rectangle that gets taken from the actual background image (h,w) determine the size of the rectangle to sample from the background image. (x,y) determine the position of the rectangle's top left corner on the actual background image.
        bool wrapping;
-       
+       Collision collisionData;///<The collision data for this Background \todo implement collisions
 
        
        public:
index a4169e4..7d71281 100644 (file)
@@ -1,9 +1,7 @@
 #ifndef BEHAVIOR
 #define BEHAVIOR
-#include "Sprite.h"
-#include "Background.h"
+#include "fns.h"
 #include <vector>
-#include <map>
 #include <string>
 
 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 (file)
index 0000000..7c949c4
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef BEHAVIORS
+#define BEHAVIORS
+#include "Behavior.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:
+    - 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 (file)
index 0000000..752c97f
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef COLLISION
+#define COLLISION
+#include "fns.h"
+#include <vector>
+#include <string>
+
+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
index 1d83b1a..a884c46 100644 (file)
--- 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 (file)
--- a/Level.h
+++ b/Level.h
@@ -2,8 +2,11 @@
 #define LEVEL
 #include "Sprite.h"
 #include "Background.h"
+#include "Behaviors.h"
 #include <vector>
 #include <map>
+
+
 #include <string>
 
 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<Sprite*> 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<string,Actor> mActors;/**< This level's actors. */
        vector<Animation> mAnim;/**< This level's Animations */
 };
index 5e36006..3883e00 100644 (file)
@@ -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()
index 61d1aad..70f585c 100644 (file)
--- a/Sprite.h
+++ b/Sprite.h
@@ -4,6 +4,8 @@
 #include <string>
 #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