2021-06-23 18:43:13 -04:00
|
|
|
#include "classicflyinganimationscenario.h"
|
|
|
|
#include "classicsprite.h"
|
|
|
|
|
|
|
|
void ClassicFlyingAnimationScenario::launch(const std::shared_ptr<ClassicSprite> sprite, const microsec& time_begin, const microsec &time_end)
|
|
|
|
{
|
|
|
|
_sprite = sprite;
|
|
|
|
_time_begin = time_begin;
|
|
|
|
_time_end = time_end;
|
|
|
|
|
|
|
|
_percentage = ((_time_end - _time_begin) * 0.01);
|
|
|
|
}
|
|
|
|
|
2021-10-04 10:20:24 -04:00
|
|
|
float ClassicFlyingAnimationScenario::getPoint(float n1, float n2, float perc) const
|
2021-06-23 18:43:13 -04:00
|
|
|
{
|
|
|
|
float diff = n2 - n1;
|
|
|
|
|
|
|
|
return n1 + ( diff * perc );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicFlyingAnimationScenario::update(const microsec& music_offset)
|
|
|
|
{
|
|
|
|
const auto crd = _sprite->coordinates();
|
|
|
|
auto update_time = music_offset - _time_begin;
|
2021-10-04 10:20:24 -04:00
|
|
|
float i = update_time / _percentage * 0.01;
|
2021-06-23 18:43:13 -04:00
|
|
|
|
2021-06-24 14:04:09 -04:00
|
|
|
float xa = getPoint( crd.x + 20. , crd.x + 90. , i );
|
|
|
|
float ya = getPoint( crd.y - 600. , crd.y - 150. , i );
|
|
|
|
float xb = getPoint( crd.x + 90. , crd.x , i );
|
|
|
|
float yb = getPoint( crd.y - 150. , crd.y , i );
|
2021-06-23 18:43:13 -04:00
|
|
|
|
2021-11-24 13:21:30 -05:00
|
|
|
_sprite->setTrailCoordinates(Coordinates(getPoint( xa , xb , i ), getPoint( ya , yb , i )));
|
2021-10-04 10:20:24 -04:00
|
|
|
|
|
|
|
bool pastPerfectScore = (i >= 1);
|
|
|
|
|
|
|
|
if (pastPerfectScore)
|
|
|
|
fadeTrailSprite();
|
2021-06-23 18:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClassicFlyingAnimationScenario::isDone() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-10-04 10:20:24 -04:00
|
|
|
|
|
|
|
void ClassicFlyingAnimationScenario::fadeTrailSprite() const
|
|
|
|
{
|
|
|
|
auto fill_color = _sprite->trailColor();
|
|
|
|
|
|
|
|
if (fill_color.a == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto new_alpha = fill_color.a - 35;
|
|
|
|
fill_color.a = new_alpha < 0 ? 0 : new_alpha;
|
|
|
|
|
|
|
|
_sprite->setTrailColor(fill_color);
|
|
|
|
}
|