changed getAnimation to return SpriteFrame*
authorunknown <Ivan Lloyd@.(none)>
Sat, 29 Jan 2011 18:35:23 +0000 (12:35 -0600)
committerunknown <Ivan Lloyd@.(none)>
Sat, 29 Jan 2011 18:35:23 +0000 (12:35 -0600)
Sprite.cpp
Sprite.h

index 4a9242e..ed9e49a 100644 (file)
@@ -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*mSpeed<SDL_GetTicks()) {
+               if(mLastUpdate+frame->pause*mSpeed<SDL_GetTicks()) {
                        //obtain current peg 
-                       Point2D ppos = frame.animationPeg;
+                       Point2D ppos = frame->animationPeg;
                        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
 }
index ec86c92..cb588ac 100644 (file)
--- 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. */