]> git.mmlx.us Git - IvanGame.git/commitdiff
Implemented unit vector as well as changed comments about multiple input and edited...
authorIvan Hernandez <iturtleman128@gmail.com>
Tue, 11 Jan 2011 17:22:26 +0000 (11:22 -0600)
committerIvan Hernandez <iturtleman128@gmail.com>
Tue, 11 Jan 2011 17:22:26 +0000 (11:22 -0600)
removed public name from sprite. (may need to make mName public or add accessors)
Created Behavior class to use in place of function pointers (so that there is only one level class and it has a behavior instead)

Behavior.h [new file with mode: 0644]
Game.cpp
Level.h
LevelWorld.h
Sprite.cpp
Sprite.h
fns.cpp
fns.h

diff --git a/Behavior.h b/Behavior.h
new file mode 100644 (file)
index 0000000..a4169e4
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef BEHAVIOR
+#define BEHAVIOR
+#include "Sprite.h"
+#include "Background.h"
+#include <vector>
+#include <map>
+#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);
+       virtual void load();/**< Loading Behavior*/
+       virtual void update();/**< Update Behavior*/
+       virtual void unload();/**< Delete Behavior*/
+protected:
+       string name;/**< Name of this behavior */
+};
+#endif
index 99a8e00f597e26f742f9d6f1de67ef670576a1e0..ce12c8ff6fd48fb99291833ca773bc212703cc67 100644 (file)
--- a/Game.cpp
+++ b/Game.cpp
@@ -40,7 +40,8 @@ Game::~Game()
        for (size_t i = 0; i < mLevels.size(); ++i) {
                delete mLevels[i];
        }
-       delete mScreen;
+       /// \todo Does this even need to be here or will closing the program unallocate the mem?
+       //delete mScreen; 
 }
 
 Level* Game::getCurrentLevel()
@@ -78,7 +79,6 @@ void Game::run()
                        break;
                }
 
-               ///\todo This needs to be changed to where every single key-press is registered at once and put into a list of sorts and then events on keys is handled elsewhere to allow multi-keypresses and for better program flow.
                switch (event.type) {
                /** If the event is a click on the close button in the top
                        right corner of the window, we kill the application
diff --git a/Level.h b/Level.h
index 76f1ff5c1df6b1dd6916908a9c2ec894e5e7628e..efacc27b80e45bf972acf06058985c58e3f32ef5 100644 (file)
--- a/Level.h
+++ b/Level.h
@@ -29,7 +29,7 @@ public:
        virtual 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. */
+       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
index 436d4c839d2ab72ed3024a4355ad5df4d7004269..0b5a0ba9c30c92b3b47c125b9fae8c361bf95e30 100644 (file)
@@ -18,7 +18,6 @@ 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.*/ 
-
+       void update();/**< Loop that runs every game frame that calculates movement, placement, etc.  as well as obtains key strokes (limited by keyboard hardware)*/
 };
 #endif
index 39fb7e9a0b60901cd239072f40f3d26b23e18f1f..e2c3bff3ac042495c1156207db40c49243d7c073 100644 (file)
@@ -2,13 +2,13 @@
 #include <iostream>
 using std::cout;
 using std::endl;
-Sprite::Sprite(SDL_Surface *screen, std::string name, Actor actor) :
+Sprite::Sprite(SDL_Surface *screen, std::string name, Actor actor, int z) :
        mDrawn(0),
        mVisible(true),
        mLastUpdate(0),
        mActor(actor),
-       mScreen(screen)
-       /** \todo implement name and mName seee if I even need both of them. */
+       mScreen(screen),
+       ZOrder(z)
 {
        /** \todo Later add a part that adds name to list of level sprites 
                Game.Level.SpriteList.pushback(name);
index 3062991572cf77df6bf151d65c65d5a1657e31c3..61d1aad80f6e39ddbeb7d6fb686d9b2a95afe963 100644 (file)
--- a/Sprite.h
+++ b/Sprite.h
@@ -15,7 +15,7 @@
 class Sprite
 {
        public:
-       Sprite(SDL_Surface *screen, std::string name, Actor actor);
+       Sprite(SDL_Surface *screen, std::string name, Actor actor, int z = 0);
        void setAnimation(int animation){ mActor.mCurrentAnimation = animation; }/**< changes to the specified animation beginning at 0. */
        int getAnimation(){ return mActor.mCurrentAnimation; }/**< returns active animation. */
        void setFrame(int frame) { mActor.mFrame = frame; }/**< cahnges to the specified frame of the animation beginning at 0. */
@@ -26,7 +26,6 @@ class Sprite
        void startAnim() {mAnimating = 1;}/**< Causes the animation to play. */
        void stopAnim() {mAnimating = 0;}/**< Causes the animation to stop. */
        void rewind() {mActor.mFrame = 0;}/**< Resets the Sprite's animation to the first frame. */
-       std::string name;
        void draw();/**< draws Sprite. */
        void xadd(int num) {mPos.x += num;}/**< Increase X coordiante by a given amount. */
        void yadd(int num) {mPos.y += num;}/**< Increase y coordinate by a given amount. */
diff --git a/fns.cpp b/fns.cpp
index 17b440579a66bd3c16f72c4716cb1079a5176d58..1a7da663296c8ede6fbfef285ba68a8287520828 100644 (file)
--- a/fns.cpp
+++ b/fns.cpp
@@ -40,8 +40,18 @@ SDL_Surface* LoadImage( std::string filename )
        return compatible_image;
 }
 
+Point2D::Point2D (const SizeD& copy){
+       x = copy.w; 
+       y = copy.h;
+}
+
 double Point2D::length(){
-       return sqrt(x*x + y*y);///< \todo find math.sqrt
+       return sqrt(x*x + y*y);
+}
+
+Point2D Point2D::unitVec(){
+       double len = length();///< \todo optimize
+       return Point2D((x/len), (y/len));
 }
 
 Point2D Point2D::add(Point2D pt){
diff --git a/fns.h b/fns.h
index ee09912070c77c2148b978021a1a0d44eea15273..33b8056fa5cafded531bee4260ccc4ed7f2a29b5 100644 (file)
--- a/fns.h
+++ b/fns.h
@@ -21,7 +21,7 @@ class Point2D
                x = copy.x; 
                y = copy.y;
        }
-       Point2D (/*const SizeD& copy*/int i);///< Copy object \todo make SizeD work here
+       Point2D (const SizeD& copy);///< Copy object
 
        /** \todo add typical vector functionality like length, nomal vectors etc. */
        double x;/**< x position */
@@ -29,6 +29,9 @@ class Point2D
        double length();/**< The length of the Point (from origin)
        \return length of the vector/point
        */
+       Point2D unitVec();/**< The unit vector of the Point (from origin)
+       \return length of the vector/point
+       */
        Point2D add(Point2D pt);/**< Adds the value of the point to this \return This after modificaiton*/
        Point2D sub(Point2D pt);/**< Subtracts the value of the point from this \return This after modification*/
        Point2D mult(double d);/**< Multiplies the values of this by i \return This after modificaiton*/