MovementType -> int in the signature of the Animate::move constructor.
[tagua.git] / src / animationfactory.cpp
blob773d49e7593b53b15f0d3884c8a5814b909973ba
1 #include "animationfactory.h"
3 #include "animation.h"
4 #include "namedsprite.h"
5 #include "pointconverter.h"
6 #include "graphicalapi.h"
8 AnimationFactory::AnimationFactory(GraphicalAPI* api)
9 : m_api(api) {
10 m_group = AnimationGroupPtr(new AnimationGroup);
13 AnimationGroupPtr AnimationFactory::group() const {
14 return m_group;
17 void AnimationFactory::addPreAnimation(const Animate::Scheme& scheme, Animate::AnimationType type) {
18 m_group->addPreAnimation(m_api->animate(scheme, type));
21 void AnimationFactory::addPostAnimation(const Animate::Scheme& scheme, Animate::AnimationType type) {
22 m_group->addPostAnimation(m_api->animate(scheme, type));
25 AnimationFactory::operator AnimationGroupPtr() const {
26 return group();
29 namespace Animate {
31 Scheme::~Scheme() { }
33 move::move(const NamedSprite& sprite, const Point& to, int type)
34 : m_sprite(sprite)
35 , m_to(to)
36 , m_type(type) { }
38 AnimationPtr move::run(const PointConverter* converter, AnimationType type) const {
39 switch (type) {
40 case Normal: {
41 MovementAnimation* mov;
42 if (m_type & LShaped) {
43 mov = new KnightMovementAnimation(m_sprite.sprite(), converter->toReal(m_to), m_type & Rotating);
45 else {
46 mov = new MovementAnimation(m_sprite.sprite(), converter->toReal(m_to), m_type & Rotating);
48 return AnimationPtr(mov);
50 case Instant:
51 default:
52 return AnimationPtr(new InstantAnimation(m_sprite.sprite(), converter->toReal(m_to)));
56 appear::appear(const NamedSprite& sprite)
57 : m_sprite(sprite) { }
59 AnimationPtr appear::run(const PointConverter*, AnimationType type) const {
60 switch (type) {
61 case Normal:
62 return AnimationPtr(new FadeAnimation(m_sprite.sprite(), 0, 255));
63 case Instant:
64 default:
65 return AnimationPtr(new DropAnimation(m_sprite.sprite()));
69 disappear::disappear(const NamedSprite& sprite)
70 : m_sprite(sprite) { }
72 AnimationPtr disappear::run(const PointConverter*, AnimationType type) const {
73 switch (type) {
74 case Normal:
75 return AnimationPtr(new FadeAnimation(m_sprite.sprite(), 255, 0));
76 case Instant:
77 default:
78 return AnimationPtr(new CaptureAnimation(m_sprite.sprite()));
82 destroy::destroy(const NamedSprite& sprite)
83 : m_sprite(sprite) { }
85 AnimationPtr destroy::run(const PointConverter*, AnimationType type) const {
86 switch (type) {
87 case Normal:
88 return AnimationPtr(new ExplodeAnimation(m_sprite.sprite(), Random::instance()));
89 case Instant:
90 default:
91 return AnimationPtr(new CaptureAnimation(m_sprite.sprite()));
95 morph::morph(const NamedSprite& sprite, const NamedSprite& new_sprite)
96 : m_sprite(sprite)
97 , m_new_sprite(new_sprite) { }
99 AnimationPtr morph::run(const PointConverter*, AnimationType type) const {
100 switch (type) {
101 case Normal:
102 return AnimationPtr(new CrossFadingAnimation(m_sprite.sprite(), m_new_sprite.sprite()));
103 case Instant:
104 default:
105 return AnimationPtr(new PromotionAnimation(m_sprite.sprite(), m_new_sprite.sprite()));