File: sprites.h

package info (click to toggle)
kspaceduel 4%3A4.12.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,220 kB
  • ctags: 483
  • sloc: cpp: 3,149; makefile: 9; sh: 2
file content (133 lines) | stat: -rw-r--r-- 4,564 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
    Copyright (C) 1998-2001 Andreas Zehender <az@azweb.de>

    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef KSPACEDUEL_SPRITES_H
#define KSPACEDUEL_SPRITES_H

#include "defines.h"
#include "spritebase.h"

#ifdef sun
#undef sun
#endif

class SunSprite:public SimpleSprite
{
public:
   SunSprite(QSvgRenderer* svg, const QString& element);
   virtual int type() const {return S_SUN;}
};

class PowerupSprite:public SimpleSprite
{
public:
   enum {PowerupMine=0, PowerupBullet, PowerupShield, PowerupEnergy,
         PowerupNum};
   PowerupSprite(QSvgRenderer* svg, const QString& element, int t, double lifetime);
   virtual int type() const {return S_POWERUP;}

   double getLifetime() {return time;}
   void setLifetime(double t) {time=t;}
   int getType() {return mtype;}
private:
   double time;
   int mtype;
};

class ShipSprite:public MobileSprite
{
public:
   ShipSprite(QSvgRenderer* svg, const QString& element, int pn);
   virtual int type() const {return S_SHIP;}
   int getHitPoints() {return hitpoints;}
   void setHitPoints(int hp) {hitpoints=(hp<0?0:hp);}
   double getEnergy() {return energy;}
   void setEnergy(double e) {energy=(e<0?0:e);}
   void setWins(int w) {wins=w;}
   int getWins() {return wins;}
   void setExplosion(int f) {explosion=f;}
   int getExplosion() {return explosion;}
   void setRotation(double r);
   double getRotation() {return rotation;}
   void rotateRight(double rotationEnergyNeed,double rotationSpeed);
   void rotateLeft(double rotationEnergyNeed,double rotationSpeed);
   void bullet(double reloadTime) {reloadBulletTime=reloadTime;}
   bool reloadsBullet(double t=0.0) {return reloadBulletTime>t;}
   void mine(double reloadTime) {reloadMineTime=reloadTime;}
   bool reloadsMine(double t=0.0) {return reloadMineTime>t;}
   bool explodes() {return explosion>=0;}
   void setMinePowerups(int m) {minePowerups=m;}
   int getMinePowerups() {return minePowerups;}
   void setBulletPowerups(int b) {bulletPowerups=b;}
   int getBulletPowerups() {return bulletPowerups;}
   virtual void forward(double mult);
   virtual void forward(double mult,int fr);
   virtual void calculateGravityAndEnergy(double gravity,double sunEnergy,
                                          double mult);
private:
   int hitpoints, wins, explosion;
   double energy,rotation,reloadBulletTime,reloadMineTime;
   int bulletPowerups,minePowerups;
   double angle; // current rotation angle
};

class BulletSprite:public MobileSprite
{
public:
   BulletSprite(QSvgRenderer* svg, const QString& elem, int pn,double lifetime);
   virtual int type() const {return S_BULLET;}
   virtual void forward(double mult);
   virtual void forward(double mult,int fr);
   bool timeOut() {return time<=0;}
private:
   double time;
};

class MineSprite:public AnimatedSprite
{
public:
   MineSprite(QSvgRenderer* svg, const QList<QString> &animation, const QList<QString> &exploanimation, int pn,double atime,double f);
   virtual int type() const {return S_MINE;}
   bool isActive() {return active;}
   double getFuel() {return fuel;}
   void setFuel(double f) {fuel=(f<0.0?0.0:f);}
   virtual void forward(double mult);
   void explode();
   bool explodes() {return expl;}
   bool over() {return (expl&&(explosiontime>(timeToGo-0.1)));}
   virtual void calculateGravity(double gravity,double mult);
private:
   bool expl,active;
   double activateTime,fuel,timeToGo,explosiontime;
   QList<QString> exploframes; /* when mine explodes, we set frames to exploframes (needed because both player's mines have
   			          the same explosion animation) */
};

class ExplosionSprite:public AnimatedSprite
{
public:
   explicit ExplosionSprite(QSvgRenderer* svg, const QList<QString> &animation, MobileSprite *sp = 0);
   virtual int type() const {return S_EXPLOSION;}
   bool isOver() {return over;}
   virtual void forward(double mult);
private:
   double timeToGo,time;
   bool over;
   MobileSprite *obj;
};

#endif // KSPACEDUEL_SPRITES_H