1 | /******************************************************************* |
2 | * |
3 | * Copyright 2006-2007 Dmitry Suzdalev <dimsuz@gmail.com> |
4 | * |
5 | * This file is part of the KDE project "KLines" |
6 | * |
7 | * KLines is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2, or (at your option) |
10 | * any later version. |
11 | * |
12 | * KLines is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with KLines; see the file COPYING. If not, write to |
19 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
20 | * Boston, MA 02110-1301, USA. |
21 | * |
22 | ********************************************************************/ |
23 | #ifndef ANIMATOR_H |
24 | #define ANIMATOR_H |
25 | |
26 | #include <QTimeLine> |
27 | #include "commondefs.h" |
28 | |
29 | class KLinesScene; |
30 | class BallItem; |
31 | |
32 | /** |
33 | * Drives KLines animations |
34 | */ |
35 | class KLinesAnimator : public QObject |
36 | { |
37 | Q_OBJECT |
38 | public: |
39 | explicit KLinesAnimator( KLinesScene *scene ); |
40 | /** |
41 | * Starts animation of ball movement. |
42 | * When animation finishes moveFinished() signal is emitted |
43 | * @param from starting field position |
44 | * @param to target field position |
45 | * |
46 | * @return true is there exists a path (from,to), false otherwise |
47 | */ |
48 | bool animateMove( const FieldPos& from, const FieldPos& to ); |
49 | /** |
50 | * Starts animation of ball deletion from field. |
51 | * Note that it doesn't do actual deletion - it just runs |
52 | * animation of deletion. |
53 | * When animation finishes removeFinished() signal is emitted |
54 | * @param list list of balls to 'remove' |
55 | */ |
56 | void animateRemove( const QList<BallItem*>& list ); |
57 | /** |
58 | * Starts animation of ball movement. |
59 | * When animation finishes bornFinished() signal is emitted |
60 | * @param list list of balls to be 'born' |
61 | */ |
62 | void animateBorn( const QList<BallItem*>& list ); |
63 | /** |
64 | * @return whether some animation is in progress |
65 | */ |
66 | bool isAnimating() const; |
67 | /** |
68 | * Starts game over animation on the scene, shows game over message |
69 | * TODO: does nothing useful yet |
70 | */ |
71 | void startGameOverAnimation(); |
72 | /** |
73 | * Stops game over animation |
74 | * TODO: does nothing useful yet |
75 | */ |
76 | void stopGameOverAnimation(); |
77 | signals: |
78 | void moveFinished(); |
79 | void removeFinished(); |
80 | void bornFinished(); |
81 | private slots: |
82 | void moveAnimationFrame(int); |
83 | void removeAnimationFrame(int); |
84 | void bornAnimationFrame(int); |
85 | |
86 | void slotBornFinished(); |
87 | private: |
88 | /** |
89 | * Implements A* pathfinding algorithm. |
90 | */ |
91 | void findPath(const FieldPos& from, const FieldPos& to); |
92 | /** |
93 | * Timeline used to control movement animation |
94 | */ |
95 | QTimeLine m_moveTimeLine; |
96 | /** |
97 | * Timeline used to control deletion animation |
98 | */ |
99 | QTimeLine m_removeTimeLine; |
100 | /** |
101 | * Timeline used to control birth animation |
102 | */ |
103 | QTimeLine m_bornTimeLine; |
104 | /** |
105 | * Scene on which animations are played |
106 | */ |
107 | KLinesScene* m_scene; |
108 | /** |
109 | * Ball object used while animating movement |
110 | */ |
111 | BallItem* m_movingBall; |
112 | /** |
113 | * findPath() algorithm stores found path in this variable |
114 | */ |
115 | QList<FieldPos> m_foundPath; |
116 | /** |
117 | * Balls for which 'remove' animation is played |
118 | */ |
119 | QList<BallItem*> m_removedBalls; |
120 | /** |
121 | * Balls for which 'born' animation is played |
122 | */ |
123 | QList<BallItem*> m_bornBalls; |
124 | }; |
125 | |
126 | #endif |
127 | |