1 /* 2 SPDX-FileCopyrightText: 1998-2001 Andreas Zehender <az@azweb.de> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #ifndef KSPACEDUEL_SPRITES_H 8 #define KSPACEDUEL_SPRITES_H 9 10 #include "defines.h" 11 #include "spritebase.h" 12 13 #ifdef sun 14 #undef sun 15 #endif 16 17 class SunSprite:public SimpleSprite 18 { 19 public: 20 SunSprite(QSvgRenderer* svg, const QString& element); type()21 int type() const override {return S_SUN;} 22 }; 23 24 class PowerupSprite:public SimpleSprite 25 { 26 public: 27 enum {PowerupMine=0, PowerupBullet, PowerupShield, PowerupEnergy, 28 PowerupNum}; 29 PowerupSprite(QSvgRenderer* svg, const QString& element, int t, double lifetime); type()30 int type() const override {return S_POWERUP;} 31 getLifetime()32 double getLifetime() {return time;} setLifetime(double t)33 void setLifetime(double t) {time=t;} getType()34 int getType() {return mtype;} 35 private: 36 double time; 37 int mtype; 38 }; 39 40 class ShipSprite:public MobileSprite 41 { 42 public: 43 ShipSprite(QSvgRenderer* svg, const QString& element, int pn); type()44 int type() const override {return S_SHIP;} getHitPoints()45 int getHitPoints() {return hitpoints;} setHitPoints(int hp)46 void setHitPoints(int hp) {hitpoints=(hp<0?0:hp);} getEnergy()47 double getEnergy() {return energy;} setEnergy(double e)48 void setEnergy(double e) {energy=(e<0?0:e);} setWins(int w)49 void setWins(int w) {wins=w;} getWins()50 int getWins() {return wins;} setExplosion(int f)51 void setExplosion(int f) {explosion=f;} getExplosion()52 int getExplosion() {return explosion;} 53 void setRotation(double r); getRotation()54 double getRotation() {return rotation;} 55 void rotateRight(double rotationEnergyNeed,double rotationSpeed); 56 void rotateLeft(double rotationEnergyNeed,double rotationSpeed); bullet(double reloadTime)57 void bullet(double reloadTime) {reloadBulletTime=reloadTime;} 58 bool reloadsBullet(double t=0.0) {return reloadBulletTime>t;} mine(double reloadTime)59 void mine(double reloadTime) {reloadMineTime=reloadTime;} 60 bool reloadsMine(double t=0.0) {return reloadMineTime>t;} explodes()61 bool explodes() {return explosion>=0;} setMinePowerups(int m)62 void setMinePowerups(int m) {minePowerups=m;} getMinePowerups()63 int getMinePowerups() {return minePowerups;} setBulletPowerups(int b)64 void setBulletPowerups(int b) {bulletPowerups=b;} getBulletPowerups()65 int getBulletPowerups() {return bulletPowerups;} 66 void forward(double mult) override; 67 void forward(double mult,int fr) override; 68 virtual void calculateGravityAndEnergy(double gravity,double sunEnergy, 69 double mult); 70 private: 71 int hitpoints, wins, explosion; 72 double energy,rotation,reloadBulletTime,reloadMineTime; 73 int bulletPowerups,minePowerups; 74 double angle; // current rotation angle 75 }; 76 77 class BulletSprite:public MobileSprite 78 { 79 public: 80 BulletSprite(QSvgRenderer* svg, const QString& elem, int pn,double lifetime); type()81 int type() const override {return S_BULLET;} 82 void forward(double mult) override; 83 void forward(double mult,int fr) override; timeOut()84 bool timeOut() {return time<=0;} 85 private: 86 double time; 87 }; 88 89 class MineSprite:public AnimatedSprite 90 { 91 public: 92 MineSprite(QSvgRenderer* svg, const QList<QString> &animation, const QList<QString> &exploanimation, int pn,double atime,double f); type()93 int type() const override {return S_MINE;} isActive()94 bool isActive() {return active;} getFuel()95 double getFuel() {return fuel;} setFuel(double f)96 void setFuel(double f) {fuel=(f<0.0?0.0:f);} 97 using AnimatedSprite::forward; 98 void forward(double mult) override; 99 void explode(); explodes()100 bool explodes() {return expl;} over()101 bool over() {return (expl&&(explosiontime>(timeToGo-0.1)));} 102 void calculateGravity(double gravity,double mult) override; 103 private: 104 bool expl,active; 105 double activateTime,fuel,timeToGo,explosiontime; 106 QList<QString> exploframes; /* when mine explodes, we set frames to exploframes (needed because both player's mines have 107 the same explosion animation) */ 108 }; 109 110 class ExplosionSprite:public AnimatedSprite 111 { 112 public: 113 explicit ExplosionSprite(QSvgRenderer* svg, const QList<QString> &animation, MobileSprite *sp = nullptr); type()114 int type() const override {return S_EXPLOSION;} isOver()115 bool isOver() {return over;} 116 using AnimatedSprite::forward; 117 void forward(double mult) override; 118 private: 119 double timeToGo,time; 120 bool over; 121 MobileSprite *obj; 122 }; 123 124 #endif // KSPACEDUEL_SPRITES_H 125