[10078] | 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: |
---|
| 23 | * Fabien Vultier |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file JumpPlatform.cc |
---|
| 31 | @brief All platforms in this minigame inherit from this class. The basic functions of a platform (interact with figure) is implemented here. Special functions are implemented in the specialized classes. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "JumpPlatform.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/GameMode.h" |
---|
[10443] | 38 | #include "core/XMLPort.h" |
---|
| 39 | #include "sound/WorldSound.h" |
---|
[10078] | 40 | #include "JumpFigure.h" |
---|
| 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | RegisterClass(JumpPlatform); |
---|
| 45 | |
---|
| 46 | JumpPlatform::JumpPlatform(Context* context) : MovableEntity(context) |
---|
| 47 | { |
---|
| 48 | RegisterObject(JumpPlatform); |
---|
| 49 | |
---|
| 50 | figure_ = 0; |
---|
| 51 | |
---|
| 52 | //initialize sound |
---|
| 53 | if (GameMode::isMaster()) |
---|
[10215] | 54 | { |
---|
| 55 | defScoreSound_ = new WorldSound(this->getContext()); |
---|
| 56 | defScoreSound_->setVolume(1.0f); |
---|
| 57 | defBatSound_ = new WorldSound(this->getContext()); |
---|
| 58 | defBatSound_->setVolume(0.4f); |
---|
| 59 | defBoundarySound_ = new WorldSound(this->getContext()); |
---|
| 60 | defBoundarySound_->setVolume(0.5f); |
---|
| 61 | } |
---|
| 62 | else |
---|
| 63 | { |
---|
| 64 | defScoreSound_ = 0; |
---|
| 65 | defBatSound_ = 0; |
---|
| 66 | defBoundarySound_ = 0; |
---|
| 67 | } |
---|
[10078] | 68 | |
---|
| 69 | setPosition(Vector3(0,0,0)); |
---|
| 70 | setVelocity(Vector3(0,0,0)); |
---|
| 71 | setAcceleration(Vector3(0,0,0)); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | @brief |
---|
| 76 | Destructor. |
---|
| 77 | */ |
---|
| 78 | JumpPlatform::~JumpPlatform() |
---|
| 79 | { |
---|
| 80 | |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | //xml port for loading sounds |
---|
| 84 | void JumpPlatform::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 85 | { |
---|
| 86 | SUPER(JumpPlatform, XMLPort, xmlelement, mode); |
---|
| 87 | |
---|
| 88 | XMLPortParam(JumpPlatform, "height", setHeight, getHeight, xmlelement, mode); |
---|
| 89 | XMLPortParam(JumpPlatform, "width", setWidth, getWidth, xmlelement, mode); |
---|
| 90 | |
---|
| 91 | XMLPortParam(JumpPlatform, "defScoreSound", setDefScoreSound, getDefScoreSound, xmlelement, mode); |
---|
| 92 | XMLPortParam(JumpPlatform, "defBatSound", setDefBatSound, getDefBatSound, xmlelement, mode); |
---|
| 93 | XMLPortParam(JumpPlatform, "defBoundarySound", setDefBoundarySound, getDefBoundarySound, xmlelement, mode); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | /** |
---|
| 97 | @brief |
---|
| 98 | Is called every tick. |
---|
| 99 | Handles the movement of the ball and its interaction with the boundaries and bats. |
---|
| 100 | @param dt |
---|
| 101 | The time since the last tick. |
---|
| 102 | */ |
---|
| 103 | void JumpPlatform::tick(float dt) |
---|
| 104 | { |
---|
| 105 | SUPER(JumpPlatform, tick, dt); |
---|
| 106 | |
---|
| 107 | Vector3 platformPosition = this->getPosition(); |
---|
| 108 | |
---|
| 109 | if (figure_ != NULL) |
---|
| 110 | { |
---|
| 111 | Vector3 figurePosition = figure_->getPosition(); |
---|
| 112 | Vector3 figureVelocity = figure_->getVelocity(); |
---|
| 113 | |
---|
| 114 | float tolerance = 3.0; |
---|
| 115 | |
---|
| 116 | if(figureVelocity.z < 0 && figurePosition.x > platformPosition.x-width_/2 && figurePosition.x < platformPosition.x+width_/2 && figurePosition.z > platformPosition.z-height_/2*tolerance && figurePosition.z < platformPosition.z+height_/2) |
---|
| 117 | { |
---|
[10215] | 118 | touchFigure(); |
---|
[10078] | 119 | } |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | void JumpPlatform::setFigure(WeakPtr<JumpFigure> newFigure) |
---|
| 124 | { |
---|
| 125 | figure_ = newFigure; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | void JumpPlatform::touchFigure() |
---|
| 129 | { |
---|
| 130 | |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | void JumpPlatform::setDefScoreSound(const std::string &jumpSound) |
---|
| 134 | { |
---|
| 135 | if( defScoreSound_ ) |
---|
| 136 | defScoreSound_->setSource(jumpSound); |
---|
| 137 | else |
---|
| 138 | assert(0); // This should never happen, because soundpointer is only available on master |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | const std::string& JumpPlatform::getDefScoreSound() |
---|
| 142 | { |
---|
| 143 | if( defScoreSound_ ) |
---|
| 144 | return defScoreSound_->getSource(); |
---|
| 145 | else |
---|
| 146 | assert(0); |
---|
| 147 | return BLANKSTRING; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | void JumpPlatform::setDefBatSound(const std::string &jumpSound) |
---|
| 151 | { |
---|
| 152 | if( defBatSound_ ) |
---|
| 153 | defBatSound_->setSource(jumpSound); |
---|
| 154 | else |
---|
| 155 | assert(0); // This should never happen, because soundpointer is only available on master |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | const std::string& JumpPlatform::getDefBatSound() |
---|
| 159 | { |
---|
| 160 | if( defBatSound_ ) |
---|
| 161 | return defBatSound_->getSource(); |
---|
| 162 | else |
---|
| 163 | assert(0); |
---|
| 164 | return BLANKSTRING; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | void JumpPlatform::setDefBoundarySound(const std::string &jumpSound) |
---|
| 168 | { |
---|
| 169 | if( defBoundarySound_ ) |
---|
| 170 | defBoundarySound_->setSource(jumpSound); |
---|
| 171 | else |
---|
| 172 | assert(0); // This should never happen, because soundpointer is only available on master |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | const std::string& JumpPlatform::getDefBoundarySound() |
---|
| 176 | { |
---|
| 177 | if( defBoundarySound_ ) |
---|
| 178 | return defBoundarySound_->getSource(); |
---|
| 179 | else |
---|
| 180 | assert(0); |
---|
| 181 | return BLANKSTRING; |
---|
| 182 | } |
---|
| 183 | } |
---|