forked from NaiJi/project-kyoku
Encapsulate animation into objects
parent
a028773fe8
commit
06d099c11f
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <SFML/Config.hpp>
|
||||
#include <memory>
|
||||
|
||||
using microsec = sf::Int64;
|
||||
|
||||
class ClassicSprite;
|
||||
|
||||
class ClassicAnimationScenario
|
||||
{
|
||||
public:
|
||||
virtual ~ClassicAnimationScenario() = default;
|
||||
|
||||
virtual void launch(const std::shared_ptr<ClassicSprite> sprite, const microsec& time_begin, const microsec &time_end) = 0;
|
||||
virtual void update(const microsec& music_offset) = 0;
|
||||
virtual bool isDone() const = 0;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ClassicSprite> _sprite;
|
||||
microsec _time_begin;
|
||||
microsec _time_end;
|
||||
};
|
@ -0,0 +1,21 @@
|
||||
#include "classicdyinganimationscenario.h"
|
||||
#include "classicsprite.h"
|
||||
|
||||
void ClassicDyingAnimationScenario::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;
|
||||
|
||||
_sprite->pulse();
|
||||
}
|
||||
|
||||
void ClassicDyingAnimationScenario::update(const microsec& music_offset)
|
||||
{
|
||||
_sprite->update();
|
||||
}
|
||||
|
||||
bool ClassicDyingAnimationScenario::isDone() const
|
||||
{
|
||||
return _sprite->isDead();
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
#ifndef CLASSICDYINGANIMATIONSCENARIO_H
|
||||
#define CLASSICDYINGANIMATIONSCENARIO_H
|
||||
|
||||
#include "classicanimationscenario.h"
|
||||
|
||||
class ClassicDyingAnimationScenario : public ClassicAnimationScenario
|
||||
{
|
||||
public:
|
||||
virtual void launch(const std::shared_ptr<ClassicSprite> sprite, const microsec& time_begin, const microsec& time_end) override;
|
||||
virtual void update(const microsec& music_offset) override;
|
||||
virtual bool isDone() const override;
|
||||
};
|
||||
|
||||
#endif // CLASSICDYINGANIMATIONSCENARIO_H
|
@ -0,0 +1,42 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
int ClassicFlyingAnimationScenario::getPoint(float n1, float n2, float perc) const
|
||||
{
|
||||
float diff = n2 - n1;
|
||||
|
||||
return n1 + ( diff * perc );
|
||||
}
|
||||
|
||||
void ClassicFlyingAnimationScenario::update(const microsec& music_offset)
|
||||
{
|
||||
float i;
|
||||
const auto crd = _sprite->coordinates();
|
||||
auto update_time = music_offset - _time_begin;
|
||||
i = update_time / _percentage * 0.01;
|
||||
|
||||
float xa = getPoint( crd.first + 20. , crd.first + 90. , i );
|
||||
float ya = getPoint( crd.second - 600. , crd.second - 150. , i );
|
||||
float xb = getPoint( crd.first + 90. , crd.first , i );
|
||||
float yb = getPoint( crd.second - 150. , crd.second , i );
|
||||
|
||||
_sprite->update(getPoint( xa , xb , i ), getPoint( ya , yb , i ));
|
||||
if (i >= 1)
|
||||
{
|
||||
_sprite->trailFade();
|
||||
}
|
||||
}
|
||||
|
||||
bool ClassicFlyingAnimationScenario::isDone() const
|
||||
{
|
||||
return false;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
#ifndef CLASSICFLYINGANIMATIONSCENARIO_H
|
||||
#define CLASSICFLYINGANIMATIONSCENARIO_H
|
||||
|
||||
#include "classicanimationscenario.h"
|
||||
|
||||
class ClassicFlyingAnimationScenario : public ClassicAnimationScenario
|
||||
{
|
||||
public:
|
||||
virtual void launch(const std::shared_ptr<ClassicSprite> sprite, const microsec& time_begin, const microsec& time_end) override;
|
||||
virtual void update(const microsec& music_offset) override;
|
||||
virtual bool isDone() const override;
|
||||
|
||||
private:
|
||||
int getPoint(float n1, float n2, float perc) const;
|
||||
|
||||
float _percentage;
|
||||
};
|
||||
|
||||
#endif // CLASSICFLYINGANIMATIONSCENARIO_H
|
Loading…
Reference in New Issue