From: unknown Date: Sat, 29 Jan 2011 18:35:23 +0000 (-0600) Subject: changed getAnimation to return SpriteFrame* X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=03a94770e740186eb14499d6383e465a58baec1e;p=IvanGame.git changed getAnimation to return SpriteFrame* --- diff --git a/Sprite.cpp b/Sprite.cpp index 4a9242e..ed9e49a 100644 --- a/Sprite.cpp +++ b/Sprite.cpp @@ -22,18 +22,18 @@ mName(name), void Sprite::draw() { //Frame so we don't have to find it so often - SpriteFrame frame = mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame]; + SpriteFrame* frame = getAnimation(); if(mAnimating == 1) { - if(mLastUpdate+frame.pause*mSpeedpause*mSpeedanimationPeg; mActor.mFrame++; if(mActor.mFrame > mActor.mAnimations[mActor.mCurrentAnimation]->mNumFrames-1) mActor.mFrame=0; //update frame so we don't need to worry - frame = mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame]; + frame = &mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame]; //obtain next peg - Point2D npos = frame.animationPeg; + Point2D npos = frame->animationPeg; //move current position to difference of two mPos.add(ppos - npos); mLastUpdate = SDL_GetTicks(); @@ -43,7 +43,7 @@ void Sprite::draw() dest.x = mPos.x; dest.y = mPos.y; if(mVisible == true) - SDL_BlitSurface(frame.image,NULL,mScreen,&dest); + SDL_BlitSurface(frame->image,NULL,mScreen,&dest); } @@ -62,13 +62,13 @@ void Sprite::drawCollisions(){ Sprite* Sprite::collisionWithSprite(string name){ //get the frame for readability - SpriteFrame frame = mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame]; + SpriteFrame* frame = getAnimation(); //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(), s->mPos + s->mActor.mAnimations[s->mActor.mCurrentAnimation]->mAnim[s->mActor.mFrame].animationPeg, mPos + frame.animationPeg))//if there is a collision + for(int i=0; i < frame->collisionData.size(); i++) + if(frame->collisionData[i]->checkCollisions(s->getCollisionData(), s->mPos + s->getAnimation()->animationPeg, mPos + frame->animationPeg))//if there is a collision return s; return NULL;//if there aren't collisions } diff --git a/Sprite.h b/Sprite.h index ec86c92..cb588ac 100644 --- a/Sprite.h +++ b/Sprite.h @@ -19,7 +19,7 @@ class Sprite : public WorldObject public: Sprite(SDL_Surface *screen, std::string name, Actor actor); void setAnimation(int animation){ mActor.mCurrentAnimation = animation; }/**< changes to the specified animation beginning at 0. */ - int getAnimation(){ return mActor.mCurrentAnimation; }/**< returns active animation. */ + SpriteFrame* getAnimation(){ return &mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame]; }/**< returns active animation. (actually the current frame within the animation) \todo see if this is slower maybe undo */ void setFrame(int frame) { mActor.mFrame = frame; }/**< cahnges to the specified frame of the animation beginning at 0. */ int getFrame() { return mActor.mFrame; }/**< returns active frame. */ void setSpeed(float speed) {mSpeed = speed;}/**< sets the Sprite's speed. */