From: unknown Date: Fri, 28 Jan 2011 19:12:52 +0000 (-0600) Subject: found issue with collision detection X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=294f2a9b0b731a8788c850e778ba81be9c1fd0af;p=IvanGame.git found issue with collision detection --- diff --git a/Collision.h b/Collision.h index a598941..9953d5c 100644 --- a/Collision.h +++ b/Collision.h @@ -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& 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 diff --git a/Level.cpp b/Level.cpp index 4ba86c6..5860477 100644 --- 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]; diff --git a/LevelWorld.cpp b/LevelWorld.cpp index 3883e00..0ef05a0 100644 --- a/LevelWorld.cpp +++ b/LevelWorld.cpp @@ -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(); } diff --git a/Sprite.cpp b/Sprite.cpp index 5b5c38f..806ecd3 100644 --- a/Sprite.cpp +++ b/Sprite.cpp @@ -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;