found issue with collision detection
authorunknown <Ivan Lloyd@.(none)>
Fri, 28 Jan 2011 19:12:52 +0000 (13:12 -0600)
committerunknown <Ivan Lloyd@.(none)>
Fri, 28 Jan 2011 19:12:52 +0000 (13:12 -0600)
Collision.h
Level.cpp
LevelWorld.cpp
Sprite.cpp

index a598941..9953d5c 100644 (file)
@@ -18,7 +18,7 @@ class Collision
 {
 public:
        Collision():mPos(0.0,0.0),color(0xFF00FF00){ }
-       Point2D mPos;/**< The position of the center of the collision data */
+       Point2D mPos;/**< The position of the center of the collision data \todo need the parent object's position*/
        bool checkCollisions(const vector<Collision*>& c); /**< Check collision with objects */
        virtual bool collision(const Collision *c) = 0; /**< Check collision with objects */
        /// \todo See this http://www.metanetsoftware.com/technique/tutorialA.html
index 4ba86c6..5860477 100644 (file)
--- a/Level.cpp
+++ b/Level.cpp
@@ -136,6 +136,7 @@ void Level::removeActor(string name){
 }
 
 Sprite* Level::findSpriteByName(string name){
+       /// \todo make this return a list of all sprites with the same name (or make it specifiable)
        for(int i=0; i < mSprites.size(); i++){
                if(mSprites[i]->getName()==name)//find the sprite with the same name
                        return mSprites[i];
index 3883e00..0ef05a0 100644 (file)
@@ -40,6 +40,6 @@ void LevelWorld::update()
        if ( keys[SDLK_d] ) { mBackground->xadd(1); }
        if ( keys[SDLK_w] ) { mBackground->yadd(-1); }
        if ( keys[SDLK_s] ) { mBackground->yadd(1); }
-
+       Level::update();
 }
 
index 5b5c38f..806ecd3 100644 (file)
@@ -65,6 +65,8 @@ Sprite* Sprite::collisionWithSprite(string name){
        SpriteFrame frame = mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame];
        //get the first sprite with this name
        Sprite* s= Game::game()->getCurrentLevel()->findSpriteByName(name);
+       if(s==NULL)
+               return NULL;
        for(int i=0; i <  frame.collisionData.size(); i++)
                if(frame.collisionData[i]->checkCollisions(s->getCollisionData()))//if there is a collision
                        return s;