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