Merge branch 'pool_rebirth'
[tagua/yd.git] / src / animationfactory.cpp
blob12b2f5d60b9f466484238b00610b453ec18f8956
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)
34 : m_sprite(sprite)
35 , m_to(to) { }
37 AnimationPtr move::run(const PointConverter* converter, AnimationType type) const {
38 switch (type) {
39 case Normal:
40 return AnimationPtr(new MovementAnimation(m_sprite.sprite(), converter->toReal(m_to)));
41 case Instant:
42 default:
43 return AnimationPtr(new InstantAnimation(m_sprite.sprite(), converter->toReal(m_to)));
47 appear::appear(const NamedSprite& sprite)
48 : m_sprite(sprite) { }
50 AnimationPtr appear::run(const PointConverter*, AnimationType type) const {
51 switch (type) {
52 case Normal:
53 return AnimationPtr(new FadeAnimation(m_sprite.sprite(), 0, 255));
54 case Instant:
55 default:
56 return AnimationPtr(new DropAnimation(m_sprite.sprite()));
60 disappear::disappear(const NamedSprite& sprite)
61 : m_sprite(sprite) { }
63 AnimationPtr disappear::run(const PointConverter*, AnimationType type) const {
64 switch (type) {
65 case Normal:
66 return AnimationPtr(new FadeAnimation(m_sprite.sprite(), 255, 0));
67 case Instant:
68 default:
69 return AnimationPtr(new CaptureAnimation(m_sprite.sprite()));
73 destroy::destroy(const NamedSprite& sprite)
74 : m_sprite(sprite) { }
76 AnimationPtr destroy::run(const PointConverter*, AnimationType type) const {
77 switch (type) {
78 case Normal:
79 return AnimationPtr(new ExplodeAnimation(m_sprite.sprite(), Random::instance()));
80 case Instant:
81 default:
82 return AnimationPtr(new CaptureAnimation(m_sprite.sprite()));
86 morph::morph(const NamedSprite& sprite, const NamedSprite& new_sprite)
87 : m_sprite(sprite)
88 , m_new_sprite(new_sprite) { }
90 AnimationPtr morph::run(const PointConverter*, AnimationType type) const {
91 switch (type) {
92 case Normal:
93 return AnimationPtr(new CrossFadingAnimation(m_sprite.sprite(), m_new_sprite.sprite()));
94 case Instant:
95 default:
96 return AnimationPtr(new PromotionAnimation(m_sprite.sprite(), m_new_sprite.sprite()));