[8489] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[8713] | 23 | * Sandro Sgier |
---|
[8489] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file ShrinkPickup.h |
---|
| 31 | @brief Declaration of the ShrinkPickup class. |
---|
| 32 | @ingroup PickupItems |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | |
---|
[8375] | 36 | #ifndef _ShrinkPickup_H__ |
---|
| 37 | #define _ShrinkPickup_H__ |
---|
| 38 | |
---|
| 39 | #include "pickup/PickupPrereqs.h" |
---|
| 40 | |
---|
| 41 | #include <string> |
---|
[8381] | 42 | #include <vector> |
---|
[8375] | 43 | |
---|
| 44 | #include "pickup/Pickup.h" |
---|
| 45 | #include "tools/interfaces/Tickable.h" |
---|
| 46 | |
---|
| 47 | namespace orxonox { |
---|
| 48 | |
---|
| 49 | /** |
---|
[8536] | 50 | @brief |
---|
| 51 | The ShrinkPickup is a Pickupable that causes the pawn to shrink to a certain size for a certain time with a certain speed, all of them specified in the following variables: |
---|
| 52 | - The @b shrinkFactor It determines how much the ship is going to shrink (e.g. the factor 2 would make the ship shrinking to half its size). |
---|
[8713] | 53 | - The @b duration Specifies how long the ship will stay small. |
---|
| 54 | - The @b shrinkDuration Defines how fast the ship shrinks and grows in seconds. |
---|
[8536] | 55 | |
---|
[8713] | 56 | An example of a XML implementation of a ShrinkPickup would be: |
---|
[8536] | 57 | @code |
---|
[8713] | 58 | <ShrinkPickup |
---|
[8536] | 59 | shrinkFactor = "5.0" |
---|
| 60 | duration = "5.0" |
---|
| 61 | shrinkSpeed = "5.0" |
---|
| 62 | /> |
---|
| 63 | @endcode |
---|
| 64 | |
---|
| 65 | @author |
---|
| 66 | Sandro Sgier |
---|
| 67 | |
---|
| 68 | @ingroup PickupItems |
---|
| 69 | */ |
---|
| 70 | |
---|
[8375] | 71 | class _PickupExport ShrinkPickup : public Pickup, public Tickable |
---|
| 72 | { |
---|
| 73 | public: |
---|
[8713] | 74 | ShrinkPickup(BaseObject* creator); // Constructor. |
---|
| 75 | virtual ~ShrinkPickup(); // Destructor. |
---|
| 76 | |
---|
[8534] | 77 | virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); |
---|
[8713] | 78 | virtual void tick(float dt); |
---|
| 79 | |
---|
| 80 | virtual void changedUsed(void); // Is called when the pickup has transited from used to unused or the other way around. |
---|
| 81 | virtual void changedPickedUp(void); |
---|
| 82 | virtual void clone(OrxonoxClass*& item); // Creates a duplicate of the input OrxonoxClass. |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | @brief Get the shrinking factor. |
---|
| 86 | @return Returns the shrinking factor, |
---|
| 87 | */ |
---|
[8534] | 88 | inline float getShrinkFactor(void) const |
---|
| 89 | { return this->shrinkFactor_; } |
---|
[8713] | 90 | /** |
---|
| 91 | @brief Sets the shrinking factor. |
---|
| 92 | @param factor The factor, needs to greater than 1. |
---|
| 93 | */ |
---|
| 94 | inline void setShrinkFactor(float factor) |
---|
| 95 | { if(factor <= 1.0f) { COUT(2) << "Invalid shrinking factor in ShrinkPickup. Ignoring.." << endl; return; } this->shrinkFactor_ = factor; } |
---|
| 96 | /** |
---|
| 97 | @brief Get the duration for which the ship remains shrunken. |
---|
| 98 | @return Returns the duration. |
---|
| 99 | */ |
---|
[8534] | 100 | inline float getDuration(void) const |
---|
| 101 | { return this->duration_; } |
---|
[8713] | 102 | /** |
---|
| 103 | @brief Set the duration for which the ship remains shrunken. |
---|
| 104 | @param duration The duration, needs to be non-negative. |
---|
| 105 | */ |
---|
| 106 | inline void setDuration(float duration) |
---|
| 107 | { if(duration < 0.0f) { COUT(2) << "Invalid duration in ShrinkPickup. Ignoring.." << endl; return; } this->duration_ = duration; } |
---|
| 108 | /** |
---|
| 109 | @brief Get the shrink speed. |
---|
| 110 | @return Returns the shrink speed. |
---|
| 111 | */ |
---|
| 112 | inline float getShrinkDuration(void) const |
---|
| 113 | { return this->shrinkDuration_; } |
---|
| 114 | /** |
---|
| 115 | @brief Set the shrink duration. |
---|
| 116 | @param speed The shrink duration, needs to be positive. |
---|
| 117 | */ |
---|
| 118 | inline void setShrinkDuration(float speed) |
---|
| 119 | { if(speed <= 0.0f) { COUT(2) << "Invalid shrink duration in ShrinkPickup. Ignoring.." << endl; return; } this->shrinkDuration_ = speed; } |
---|
[8375] | 120 | |
---|
[8534] | 121 | protected: |
---|
| 122 | void initializeIdentifier(void); |
---|
| 123 | |
---|
[8375] | 124 | private: |
---|
| 125 | void initialize(void); |
---|
[8713] | 126 | |
---|
| 127 | float duration_; //!< Determines how long the pickup will be active |
---|
| 128 | float shrinkFactor_; //!< Shrink factor of the space ship |
---|
| 129 | float shrinkDuration_; //!< Duration of shrinking |
---|
| 130 | |
---|
| 131 | bool isActive_; //!< True if ship is shrinking, small, or growing back. |
---|
| 132 | bool isShrinking_; //!< True if ship is shrinking |
---|
| 133 | bool isTerminating_; //!< True if ship is growing back to the original size |
---|
| 134 | |
---|
| 135 | float currentFactor_; //!< The shrink factor that is currently applied. |
---|
| 136 | float timeRemainig_; //!< The remaining shrink time. |
---|
| 137 | |
---|
[8534] | 138 | Pawn* carrierToPawnHelper(void); |
---|
[8554] | 139 | Timer durationTimer_; |
---|
[8534] | 140 | void terminate(void); |
---|
[8375] | 141 | }; |
---|
| 142 | } |
---|
| 143 | |
---|
[8502] | 144 | #endif |
---|