[4597] | 1 | /*! |
---|
[5039] | 2 | * @file projectile.h |
---|
[5498] | 3 | * a projectile, that is been shooted by a weapon |
---|
| 4 | * |
---|
| 5 | * You can use this class to make some Projectiles/Bullets/Lasers/Rockets/etc. |
---|
| 6 | * |
---|
| 7 | */ |
---|
[3710] | 8 | |
---|
[3573] | 9 | #ifndef _PROJECTILE_H |
---|
| 10 | #define _PROJECTILE_H |
---|
| 11 | |
---|
| 12 | #include "world_entity.h" |
---|
[9869] | 13 | #include "loading/fast_factory.h" |
---|
[9959] | 14 | #include "space_ships/space_ship.h" |
---|
[3573] | 15 | |
---|
[7084] | 16 | #include "sound_source.h" |
---|
| 17 | #include "sound_buffer.h" |
---|
| 18 | |
---|
[4597] | 19 | class Projectile : public WorldEntity |
---|
[3573] | 20 | { |
---|
[9869] | 21 | ObjectListDeclaration(Projectile); |
---|
[4890] | 22 | public: |
---|
[4932] | 23 | Projectile (); |
---|
[4890] | 24 | virtual ~Projectile (); |
---|
[3573] | 25 | |
---|
[4927] | 26 | void setFlightDirection(const Quaternion& flightDirection); |
---|
[4890] | 27 | void setVelocity(const Vector &velocity); |
---|
| 28 | void setLifeSpan(float lifeSpan); |
---|
[3573] | 29 | |
---|
[7221] | 30 | void loadExplosionSound(const std::string& explosionSound); |
---|
| 31 | void loadEngineSound(const std::string& engineSound); |
---|
[6431] | 32 | void setMinEnergy(float energyMin); |
---|
[4948] | 33 | /** @returns the minimal charched energy */ |
---|
[6431] | 34 | inline float getMinEnergy() { return this->energyMin; }; |
---|
[4948] | 35 | /** @returns if the Projectile can be charged */ |
---|
| 36 | inline bool isChageable() { return this->bChargeable; }; |
---|
[3578] | 37 | |
---|
[5766] | 38 | void setTarget(PNode* target); |
---|
[3573] | 39 | |
---|
[5443] | 40 | /** @brief This is called, when the Projectile is Emitted */ |
---|
| 41 | virtual void activate() = 0; |
---|
| 42 | /** @brief This is called, when the Projectile is being destroyed, or deleted */ |
---|
| 43 | virtual void deactivate() = 0; |
---|
[4948] | 44 | |
---|
[9235] | 45 | virtual void destroy (WorldEntity* killer); |
---|
[4597] | 46 | |
---|
[9959] | 47 | virtual void collidesWith (SpaceShip* target, const Vector& location); //!< collision handler; used against SpaceShip as most target will be |
---|
[9957] | 48 | |
---|
[9959] | 49 | |
---|
[6056] | 50 | virtual void tick (float dt); |
---|
| 51 | /** @brief convenience function |
---|
| 52 | * @param dt the Time passed |
---|
| 53 | * @returns true if the Projectile is past its lifeTime, false if it shall still live */ |
---|
| 54 | inline bool tickLifeCycle(float dt ) { this->lifeCycle += dt/this->lifeSpan; return(unlikely(this->lifeCycle >= 1)); } |
---|
[4890] | 55 | |
---|
[9958] | 56 | inline int getPhysDamage() { return this->physDamage; }; |
---|
| 57 | inline int getElecDamage() { return this->elecDamage; }; |
---|
[6056] | 58 | |
---|
[4890] | 59 | protected: |
---|
| 60 | // energy |
---|
[7460] | 61 | float energyMin; //!< The minimal Energy a Projectile needs to be emitted. |
---|
| 62 | bool bChargeable; //!< if the Projectile is Charegeable |
---|
[4890] | 63 | |
---|
[7460] | 64 | float lifeCycle; //!< The percentage of the Lifetime done [0-1] |
---|
| 65 | float lifeSpan; //!< The entire lifespan of the Shoot. in seconds |
---|
[4890] | 66 | |
---|
[9959] | 67 | float physDamage; //!< damage to shield and armor |
---|
| 68 | float elecDamage; //!< damage to elctronic |
---|
| 69 | |
---|
[7460] | 70 | Vector flightDirection; //!< DOF direction in which the shoot flighs |
---|
[4890] | 71 | |
---|
[7460] | 72 | Vector velocity; //!< velocity of the projectile. |
---|
[5766] | 73 | |
---|
[7460] | 74 | PNode* target; //!< A target for guided Weapons. |
---|
[7084] | 75 | |
---|
[7460] | 76 | OrxSound::SoundSource soundSource; |
---|
[7084] | 77 | private: |
---|
[9869] | 78 | OrxSound::SoundBuffer explosionBuffer; |
---|
| 79 | OrxSound::SoundBuffer engineBuffer; |
---|
[3573] | 80 | }; |
---|
| 81 | |
---|
| 82 | #endif /* _PROJECTILE_H */ |
---|