File indexing completed on 2022-09-27 13:19:27

0001 /*
0002     SPDX-FileCopyrightText: 1998-2001 Andreas Zehender <az@azweb.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KSPACEDUEL_SPRITES_H
0008 #define KSPACEDUEL_SPRITES_H
0009 
0010 #include "defines.h"
0011 #include "spritebase.h"
0012 
0013 #ifdef sun
0014 #undef sun
0015 #endif
0016 
0017 class SunSprite:public SimpleSprite
0018 {
0019 public:
0020    SunSprite(QSvgRenderer* svg, const QString& element);
0021    int type() const override {return S_SUN;}
0022 };
0023 
0024 class PowerupSprite:public SimpleSprite
0025 {
0026 public:
0027    enum {PowerupMine=0, PowerupBullet, PowerupShield, PowerupEnergy,
0028          PowerupNum};
0029    PowerupSprite(QSvgRenderer* svg, const QString& element, int t, double lifetime);
0030    int type() const override {return S_POWERUP;}
0031 
0032    double getLifetime() {return time;}
0033    void setLifetime(double t) {time=t;}
0034    int getType() {return mtype;}
0035 private:
0036    double time;
0037    int mtype;
0038 };
0039 
0040 class ShipSprite:public MobileSprite
0041 {
0042 public:
0043    ShipSprite(QSvgRenderer* svg, const QString& element, int pn);
0044    int type() const override {return S_SHIP;}
0045    int getHitPoints() {return hitpoints;}
0046    void setHitPoints(int hp) {hitpoints=(hp<0?0:hp);}
0047    double getEnergy() {return energy;}
0048    void setEnergy(double e) {energy=(e<0?0:e);}
0049    void setWins(int w) {wins=w;}
0050    int getWins() {return wins;}
0051    void setExplosion(int f) {explosion=f;}
0052    int getExplosion() {return explosion;}
0053    void setRotation(double r);
0054    double getRotation() {return rotation;}
0055    void rotateRight(double rotationEnergyNeed,double rotationSpeed);
0056    void rotateLeft(double rotationEnergyNeed,double rotationSpeed);
0057    void bullet(double reloadTime) {reloadBulletTime=reloadTime;}
0058    bool reloadsBullet(double t=0.0) {return reloadBulletTime>t;}
0059    void mine(double reloadTime) {reloadMineTime=reloadTime;}
0060    bool reloadsMine(double t=0.0) {return reloadMineTime>t;}
0061    bool explodes() {return explosion>=0;}
0062    void setMinePowerups(int m) {minePowerups=m;}
0063    int getMinePowerups() {return minePowerups;}
0064    void setBulletPowerups(int b) {bulletPowerups=b;}
0065    int getBulletPowerups() {return bulletPowerups;}
0066    void forward(double mult) override;
0067    void forward(double mult,int fr) override;
0068    virtual void calculateGravityAndEnergy(double gravity,double sunEnergy,
0069                                           double mult);
0070 private:
0071    int hitpoints, wins, explosion;
0072    double energy,rotation,reloadBulletTime,reloadMineTime;
0073    int bulletPowerups,minePowerups;
0074    double angle; // current rotation angle
0075 };
0076 
0077 class BulletSprite:public MobileSprite
0078 {
0079 public:
0080    BulletSprite(QSvgRenderer* svg, const QString& elem, int pn,double lifetime);
0081    int type() const override {return S_BULLET;}
0082    void forward(double mult) override;
0083    void forward(double mult,int fr) override;
0084    bool timeOut() {return time<=0;}
0085 private:
0086    double time;
0087 };
0088 
0089 class MineSprite:public AnimatedSprite
0090 {
0091 public:
0092    MineSprite(QSvgRenderer* svg, const QList<QString> &animation, const QList<QString> &exploanimation, int pn,double atime,double f);
0093    int type() const override {return S_MINE;}
0094    bool isActive() {return active;}
0095    double getFuel() {return fuel;}
0096    void setFuel(double f) {fuel=(f<0.0?0.0:f);}
0097    using AnimatedSprite::forward;
0098    void forward(double mult) override;
0099    void explode();
0100    bool explodes() {return expl;}
0101    bool over() {return (expl&&(explosiontime>(timeToGo-0.1)));}
0102    void calculateGravity(double gravity,double mult) override;
0103 private:
0104    bool expl,active;
0105    double activateTime,fuel,timeToGo,explosiontime;
0106    QList<QString> exploframes; /* when mine explodes, we set frames to exploframes (needed because both player's mines have
0107                       the same explosion animation) */
0108 };
0109 
0110 class ExplosionSprite:public AnimatedSprite
0111 {
0112 public:
0113    explicit ExplosionSprite(QSvgRenderer* svg, const QList<QString> &animation, MobileSprite *sp = nullptr);
0114    int type() const override {return S_EXPLOSION;}
0115    bool isOver() {return over;}
0116    using AnimatedSprite::forward;
0117    void forward(double mult) override;
0118 private:
0119    double timeToGo,time;
0120    bool over;
0121    MobileSprite *obj;
0122 };
0123 
0124 #endif // KSPACEDUEL_SPRITES_H