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();
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);
}
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
}
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. */