1 | /*! |
---|
2 | * @file projectile.h |
---|
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 | */ |
---|
8 | |
---|
9 | #ifndef _PROJECTILE_H |
---|
10 | #define _PROJECTILE_H |
---|
11 | |
---|
12 | #include "world_entity.h" |
---|
13 | |
---|
14 | #include "sound_source.h" |
---|
15 | #include "sound_buffer.h" |
---|
16 | |
---|
17 | class Projectile : public WorldEntity |
---|
18 | { |
---|
19 | public: |
---|
20 | Projectile (); |
---|
21 | virtual ~Projectile (); |
---|
22 | |
---|
23 | void setFlightDirection(const Quaternion& flightDirection); |
---|
24 | void setVelocity(const Vector &velocity); |
---|
25 | void setLifeSpan(float lifeSpan); |
---|
26 | |
---|
27 | void loadExplosionSound(const char* explosionSound); |
---|
28 | void loadEngineSound(const char* engineSound); |
---|
29 | void setMinEnergy(float energyMin); |
---|
30 | /** @returns the minimal charched energy */ |
---|
31 | inline float getMinEnergy() { return this->energyMin; }; |
---|
32 | /** @returns if the Projectile can be charged */ |
---|
33 | inline bool isChageable() { return this->bChargeable; }; |
---|
34 | |
---|
35 | void setTarget(PNode* target); |
---|
36 | |
---|
37 | /** @brief This is called, when the Projectile is Emitted */ |
---|
38 | virtual void activate() = 0; |
---|
39 | /** @brief This is called, when the Projectile is being destroyed, or deleted */ |
---|
40 | virtual void deactivate() = 0; |
---|
41 | |
---|
42 | virtual void destroy (); |
---|
43 | |
---|
44 | virtual void tick (float dt); |
---|
45 | /** @brief convenience function |
---|
46 | * @param dt the Time passed |
---|
47 | * @returns true if the Projectile is past its lifeTime, false if it shall still live */ |
---|
48 | inline bool tickLifeCycle(float dt ) { this->lifeCycle += dt/this->lifeSpan; return(unlikely(this->lifeCycle >= 1)); } |
---|
49 | |
---|
50 | |
---|
51 | protected: |
---|
52 | // energy |
---|
53 | float energyMin; //!< The minimal Energy a Projectile needs to be emitted. |
---|
54 | bool bChargeable; //!< if the Projectile is Charegeable |
---|
55 | |
---|
56 | float lifeCycle; //!< The percentage of the Lifetime done [0-1] |
---|
57 | float lifeSpan; //!< The entire lifespan of the Shoot. in seconds |
---|
58 | |
---|
59 | Vector flightDirection; //!< DOF direction in which the shoot flighs |
---|
60 | |
---|
61 | Vector velocity; //!< velocity of the projectile. |
---|
62 | |
---|
63 | PNode* target; //!< A target for guided Weapons. |
---|
64 | |
---|
65 | SoundSource soundSource; |
---|
66 | private: |
---|
67 | SoundBuffer* explosionBuffer; |
---|
68 | SoundBuffer* engineBuffer; |
---|
69 | }; |
---|
70 | |
---|
71 | #endif /* _PROJECTILE_H */ |
---|