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