1 | /* |
2 | Copyright (C) 1998-2001 Andreas Zehender <az@azweb.de> |
3 | |
4 | it under the terms of the GNU General Public License as published by |
5 | the Free Software Foundation; either version 2 of the License, or |
6 | (at your option) any later version. |
7 | |
8 | This program is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License |
14 | along with this program; if not, write to the Free Software |
15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
16 | */ |
17 | |
18 | #ifndef __SPRITE_BASE_H |
19 | #define __SPRITE_BASE_H |
20 | |
21 | #include <QGraphicsSvgItem> |
22 | |
23 | //#include "defines.h" |
24 | #include "spritebase.h" |
25 | #include "structs.h" |
26 | |
27 | class SimpleSprite: public QGraphicsSvgItem |
28 | { |
29 | public: |
30 | int width(); |
31 | int height(); |
32 | QPointF center(); |
33 | protected: |
34 | void init(); |
35 | |
36 | private: |
37 | int m_width; |
38 | int m_height; |
39 | QPointF m_center; |
40 | protected: |
41 | SimpleSprite(QSvgRenderer* svg, const QString& element); |
42 | }; |
43 | |
44 | class MobileSprite:public SimpleSprite |
45 | { |
46 | public: |
47 | MobileSprite(QSvgRenderer* svg, const QString&, int pn); |
48 | |
49 | virtual void forward(double mult,int frame); |
50 | virtual void forward(double mult); |
51 | virtual void calculateGravity(double gravity,double mult); |
52 | int spriteFieldWidth(); |
53 | int spriteFieldHeight(); |
54 | double xVelocity(){return xvel;} |
55 | double yVelocity(){return yvel;} |
56 | void setVelocity(double vx, double vy); |
57 | AiSprite toAiSprite(); |
58 | |
59 | bool isStopped() {return stopped;} |
60 | void stop(bool s=true) {stopped=s;} |
61 | int getPlayerNumber() {return playerNumber;} |
62 | protected: |
63 | void checkBounds(); |
64 | bool stopped; |
65 | int playerNumber; |
66 | double xvel; |
67 | double yvel; |
68 | }; |
69 | |
70 | class AnimatedSprite:public MobileSprite |
71 | { |
72 | public: |
73 | explicit AnimatedSprite(QSvgRenderer* svg, const QList<QString> &animation, int pn=0); |
74 | |
75 | void setFrame(int frame); |
76 | inline int frame() const |
77 | { return currentFrame; } |
78 | inline int frameCount() const |
79 | { return frames.size(); } |
80 | inline QString element(int frame) const |
81 | { return frames.isEmpty() ? QString() : frames.at(frame % frames.size()); } |
82 | QPainterPath shape() const; |
83 | void setAnimation(const QList<QString> &animation); |
84 | |
85 | void advance(int phase); |
86 | |
87 | private: |
88 | int currentFrame; |
89 | QList<QString> frames; |
90 | }; |
91 | |
92 | #endif |
93 | |