119 lines
2.9 KiB
C++
119 lines
2.9 KiB
C++
/* ************************************************************************** */
|
||
/* _____ */
|
||
/* Animation.cpp | ___| _ ____ ___ */
|
||
/* Project : C-Engine | |_ | | | __| / _ \ */
|
||
/* | _| | | | |= | __/ */
|
||
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
|
||
/* */
|
||
/* */
|
||
/* ************************************************************************** */
|
||
|
||
#include "..\Rework\include\Components\Animation.hpp"
|
||
|
||
Animation::Animation()
|
||
{
|
||
TabSprite = NULL;
|
||
|
||
nb_image = 0;
|
||
delay = 0;
|
||
iterateur = 0;
|
||
time = 0;
|
||
|
||
waitatend = false;
|
||
waittheend = false;
|
||
isend = false;
|
||
}
|
||
|
||
Animation::Animation(Sprite & v)
|
||
{
|
||
TabSprite = &v;
|
||
nb_image = 1;
|
||
}
|
||
|
||
Animation::Animation(Sprite * v , int nb , int nbd , bool vwaitatend , bool vwaittheend)
|
||
{
|
||
TabSprite = v;
|
||
nb_image = nb;
|
||
delay = nbd;
|
||
|
||
waitatend = vwaitatend;
|
||
waittheend = vwaittheend;
|
||
}
|
||
|
||
void Animation::SetIt(int v)
|
||
{
|
||
iterateur = v;
|
||
time = RTC_getTicks();
|
||
isend = false;
|
||
}
|
||
|
||
int Animation::GetSizeY()
|
||
{
|
||
return TabSprite[iterateur].GetSizeY();
|
||
}
|
||
|
||
int Animation::GetSizeX()
|
||
{
|
||
return TabSprite[iterateur].GetSizeX();
|
||
}
|
||
|
||
int Animation::GetBlitX()
|
||
{
|
||
return TabSprite[iterateur].GetBlitX();
|
||
}
|
||
|
||
int Animation::GetBlitY()
|
||
{
|
||
return TabSprite[iterateur].GetBlitY();
|
||
}
|
||
|
||
|
||
void Animation::DrawAnim ( int x , int y , int d)
|
||
{
|
||
if( iterateur >= nb_image) iterateur = 0;
|
||
|
||
TabSprite[ iterateur ].DrawSprite( x , y , d);
|
||
|
||
if(WaitDelay())iterateur ++;
|
||
|
||
if( iterateur >= nb_image)
|
||
{
|
||
isend = true;
|
||
|
||
if(!waitatend)iterateur = 0;
|
||
else iterateur = nb_image - 1;
|
||
}
|
||
|
||
}
|
||
|
||
void Animation::DrawReverseAnim ( int x , int y , int d)
|
||
{
|
||
if( iterateur >= nb_image) iterateur = 0;
|
||
|
||
TabSprite[ iterateur ].DrawReverseSprite( x , y , d);
|
||
|
||
if(WaitDelay())iterateur ++;
|
||
|
||
if( iterateur >= nb_image)
|
||
{
|
||
isend = true;
|
||
|
||
if(!waitatend)iterateur = 0;
|
||
else iterateur = nb_image - 1;
|
||
}
|
||
}
|
||
|
||
bool Animation::WaitDelay()
|
||
{
|
||
|
||
if(RTC_getTicks() - time > (delay / 7.8125)) // si il s'est <20>coul<75> une seconde compl<70>te
|
||
{
|
||
time = RTC_getTicks(); // et on se rappelle du nombre de ticks de la derni<6E>re seconde <20>coul<75>e
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
|
||
}
|
||
|