Merge branch 'lua' of nslu34:disk/projects/SDLBotor into lua
[sdlbotor.git] / DAnimation.cpp
blob4f2da85b0c860dde23bcf4dcd2997cdcd91d40ec
1 #include "DAnimation.h"
3 namespace botor
5 anim_t::anim_t( unsigned int _start, unsigned int _length, unsigned int _delay, bool _loop )
7 start = _start;
8 length = _length;
9 delay = _delay;
10 loop = _loop;
13 DAnimation::DAnimation( Tileset *set )
15 this->set = set;
16 Reset();
19 DAnimation::~DAnimation() {}
21 void DAnimation::Reset()
23 anim = 0;
24 framescount = 0;
25 pos = 0;
28 void DAnimation::load( anim_t *anim )
30 if( this->anim == anim )
31 return;
32 Reset();
34 this->anim = anim;
37 void DAnimation::Draw( Sint16 X, Sint16 Y )
39 if( anim && set )
41 if( anim->length == 0 )
43 set->Draw( X, Y, anim->start );
44 return;
47 if( ++framescount >= anim->delay )
49 framescount -= anim->delay;
51 if( anim->loop )
53 pos = (pos+1) % (anim->length);
55 else
56 if( pos < anim->length )
57 pos++;
60 set->Draw( X, Y, anim->start + pos );
65 bool DAnimation::finished()
67 if(!anim) return true;
68 if(anim->loop) return false;
69 if(pos<anim->length) return false;
71 return true;