]> git.mmlx.us Git - IvanGame.git/commitdiff
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 1b65d572bd581bbf9e6c8311dd5591943918e299..b21e01e9555b287d0a80052abafd26d9b5d24e5c 100644 (file)
@@ -73,6 +73,7 @@ int Animation::loadAnimation(std::string animFile)
                        }
        }
        }
+       /// \todo add collision info obtained from file.
   fin.close();
   return 0;
 }
index 63a597a232575408f4ef4adf009abee05a7f1a91..8db9525525593dcf309205d7aeb84c39cdfef65e 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 1a72d6d9bc5c9c2d849db882548979d78b0b4ef4..51c0365550cceb1384e3deca4a9fc6c45d5a198c 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 a4169e4e9515ad3191660b200b10f34f55f85bf9..7d7128109c38a5c07a7d183a10e7f354ab015b58 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 1d83b1a74e0a283e223f56fe10d4b9d7a5993eb1..a884c463fb47f108ec93b78a2ab726c55c0c7a92 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 efacc27b80e45bf972acf06058985c58e3f32ef5..8ae7a22f273780a1c86e59d27fd2bb14f6a35623 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 5e3600629d7cdbed2450e9e20f0055641d7bb9a8..3883e00d3164cc336942be08b353e36aae9dc6b1 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 61d1aad80f6e39ddbeb7d6fb686d9b2a95afe963..70f585c262f194f2af4ffe5013a09d46d8ecae1d 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