Create a debian package for debug symbols.
[tagua/yd.git] / src / animation.h
blob4a3f5706327e95134fde6efca340c8bdbfb95525
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef ANIMATION_H
12 #define ANIMATION_H
14 #include <list>
15 #include <vector>
16 #include <boost/shared_ptr.hpp>
17 #include <boost/enable_shared_from_this.hpp>
18 #include <QPoint>
20 #include <core/animation.h>
21 #include <core/namedsprite.h>
22 #include "sprite.h"
24 class Movement;
25 class Random;
27 class ConflictingAnimation {
28 public:
29 virtual ~ConflictingAnimation() { }
30 virtual void setTarget(const SpritePtr&) = 0;
31 virtual void setSource(const SpritePtr&) = 0;
34 class ConcreteAnimation : public Animation {
35 protected:
36 SpritePtr m_piece;
37 public:
38 ConcreteAnimation(const SpritePtr& piece);
39 virtual void stop() { }
42 class OneShotAnimation : public ConcreteAnimation {
43 protected:
44 virtual void shoot() = 0;
45 public:
46 OneShotAnimation(const SpritePtr& piece);
47 virtual State animationAdvance(int);
48 virtual void abort() { }
51 class InstantAnimation : public OneShotAnimation
52 , public ConflictingAnimation {
53 QPoint m_destination;
54 SpritePtr m_source;
55 public:
56 InstantAnimation(const SpritePtr& piece, const QPoint& destination);
57 virtual void shoot();
58 virtual void setTarget(const SpritePtr&) { }
59 virtual void setSource(const SpritePtr& source) { m_source = source; }
63 class MovementAnimation : public ConcreteAnimation
64 , public ConflictingAnimation {
65 protected:
66 SpritePtr m_source;
67 SpritePtr m_target;
68 QPoint m_destination;
69 double m_speed;
70 State m_state;
72 double m_time;
73 int m_start;
74 boost::shared_ptr<Movement> m_movement;
75 bool m_rotate;
77 virtual boost::shared_ptr<Movement> createMovement(const QPoint& from, const QPoint& to) const;
78 void start();
79 public:
80 MovementAnimation(const SpritePtr& piece, const QPoint& destination, bool rotate = false, double speed = 1.0);
81 virtual ~MovementAnimation();
82 virtual State animationAdvance(int msec);
83 virtual void stop();
84 virtual void abort();
86 virtual void setTarget(const SpritePtr& target);
87 virtual void setSource(const SpritePtr& source);
90 class KnightMovementAnimation : public MovementAnimation {
91 protected:
92 virtual boost::shared_ptr<Movement> createMovement(const QPoint& from, const QPoint& to) const;
93 public:
94 KnightMovementAnimation(const SpritePtr& piece, const QPoint& destination,
95 bool rotate, double speed = 1.0);
98 class CaptureAnimation : public OneShotAnimation {
99 protected:
100 virtual void shoot();
101 public:
102 CaptureAnimation(const SpritePtr& piece);
105 class DropAnimation : public OneShotAnimation {
106 bool m_valid_position;
107 QPoint m_position;
108 protected:
109 virtual void shoot();
110 public:
111 DropAnimation(const SpritePtr& piece);
112 DropAnimation(const SpritePtr& piece, const QPoint&);
115 class PromotionAnimation : public OneShotAnimation {
116 protected:
117 SpritePtr m_promoted;
118 virtual void shoot();
119 public:
120 PromotionAnimation(const SpritePtr& piece, const SpritePtr& promoted);
123 class DelayAnimation : public Animation {
124 State m_state;
126 int m_msecs;
127 int m_start;
128 void start();
129 public:
130 DelayAnimation(int msecs);
131 virtual State animationAdvance(int msec);
132 virtual void stop();
133 virtual void abort();
136 class FadeAnimation : public ConcreteAnimation {
137 int m_fadeFrom;
138 int m_fadeTo;
139 QPoint m_to;
140 State m_state;
142 int m_start;
143 void start();
144 public:
145 FadeAnimation(const SpritePtr& sprite, const QPoint& pos, int fadeFrom, int fadeTo);
146 FadeAnimation(const SpritePtr& sprite, int fadeFrom, int fadeTo);
147 virtual State animationAdvance(int msec);
148 virtual void stop();
149 virtual void abort();
152 class GrowAnimation : public ConcreteAnimation {
153 State m_state;
154 int m_start;
156 void start();
157 public:
158 GrowAnimation(const SpritePtr& sprite);
159 virtual State animationAdvance(int msec);
160 virtual void stop();
161 virtual void abort();
164 class ExplodeAnimation : public ConcreteAnimation {
165 State m_state;
166 Random& m_random;
168 int m_start;
169 void start();
170 public:
171 ExplodeAnimation(const SpritePtr& sprite, Random& random);
172 virtual State animationAdvance(int msec);
173 virtual void stop();
174 virtual void abort();
178 * @brief Two groups of animations, to be executed one after the other.
180 * A double list of animations: pre-animations and post-animations.
181 * When an AnimationGroup is advanced, pre-animations are handled first,
182 * and removed from the list as they finish animating.
183 * When all pre-animations are gone, post-animations are handled.
185 class AnimationGroup : public Animation {
186 private:
187 typedef std::list<AnimationPtr> AnimationList;
188 typedef AnimationList::iterator Iterator;
189 AnimationList pre;
190 AnimationList post;
192 protected:
193 bool m_active;
194 bool m_persistent;
195 bool m_chain_abortions;
197 virtual void start();
198 bool empty() const;
199 public:
200 AnimationGroup(bool persistent = false);
202 virtual bool sticky() const { return m_persistent; }
203 void setPersistent(bool value) { m_persistent = value; }
204 void setChainAbortions(bool value) { m_chain_abortions = value; }
206 virtual void addPreAnimation(AnimationPtr);
207 virtual void addPostAnimation(AnimationPtr);
209 virtual State animationAdvance(int msec);
210 virtual void stop();
211 virtual void abort() { stop(); }
214 class TeleportAnimation : public AnimationGroup {
215 public:
216 TeleportAnimation(const SpritePtr& sprite, const QPoint& from, const QPoint& to);
217 TeleportAnimation(const SpritePtr& sprite, const QPoint& to);
220 class CrossFadingAnimation : public AnimationGroup {
221 SpritePtr m_piece;
222 protected:
223 virtual void start();
224 public:
225 CrossFadingAnimation(const SpritePtr& piece, const SpritePtr& promoted);
228 class DelayedAnimationSet : public Animation {
229 class Event {
230 int m_index;
231 int m_time;
232 public:
233 Event(int index, int time)
234 : m_index(index), m_time(time) { }
235 int index() const { return m_index; }
236 int time() const { return m_time; }
238 bool operator<(const Event& other) const { return m_time < other.m_time; }
241 int m_time;
242 int m_start;
243 Random& m_random;
244 State m_state;
245 std::vector<boost::shared_ptr<Animation> > m_animations;
246 AnimationGroup m_group;
247 std::vector<Event> m_events;
248 std::vector<Event>::iterator m_next_event;
250 void execute(int);
251 public:
252 DelayedAnimationSet(Random& random);
253 void addAnimation(const boost::shared_ptr<Animation>& animation);
254 void start();
255 virtual State animationAdvance(int msec);
256 virtual void stop();
257 virtual void abort();
260 #endif // ANIMATION_H