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 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file JumpPlatform.cc |
---|
31 | @brief Implementation of the JumpPlatform class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "JumpPlatform.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/GameMode.h" |
---|
38 | #include "graphics/Model.h" |
---|
39 | #include "gametypes/Gametype.h" |
---|
40 | |
---|
41 | #include "JumpFigure.h" |
---|
42 | |
---|
43 | #include "sound/WorldSound.h" |
---|
44 | #include "core/XMLPort.h" |
---|
45 | |
---|
46 | namespace orxonox |
---|
47 | { |
---|
48 | RegisterClass(JumpPlatform); |
---|
49 | |
---|
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) |
---|
57 | { |
---|
58 | RegisterObject(JumpPlatform); |
---|
59 | |
---|
60 | figure_ = 0; |
---|
61 | |
---|
62 | //initialize sound |
---|
63 | if (GameMode::isMaster()) |
---|
64 | { |
---|
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); |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | defScoreSound_ = 0; |
---|
75 | defBatSound_ = 0; |
---|
76 | defBoundarySound_ = 0; |
---|
77 | } |
---|
78 | |
---|
79 | setPosition(Vector3(0,0,0)); |
---|
80 | setVelocity(Vector3(0,0,0)); |
---|
81 | setAcceleration(Vector3(0,0,0)); |
---|
82 | } |
---|
83 | |
---|
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); |
---|
97 | |
---|
98 | XMLPortParam(JumpPlatform, "height", setHeight, getHeight, xmlelement, mode); |
---|
99 | XMLPortParam(JumpPlatform, "width", setWidth, getWidth, xmlelement, mode); |
---|
100 | |
---|
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 | */ |
---|
113 | void JumpPlatform::tick(float dt) |
---|
114 | { |
---|
115 | SUPER(JumpPlatform, tick, dt); |
---|
116 | |
---|
117 | Vector3 platformPosition = this->getPosition(); |
---|
118 | |
---|
119 | if (figure_ != NULL) |
---|
120 | { |
---|
121 | Vector3 figurePosition = figure_->getPosition(); |
---|
122 | Vector3 figureVelocity = figure_->getVelocity(); |
---|
123 | |
---|
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) |
---|
127 | { |
---|
128 | touchFigure(); |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | void JumpPlatform::setFigure(WeakPtr<JumpFigure> newFigure) |
---|
134 | { |
---|
135 | figure_ = newFigure; |
---|
136 | } |
---|
137 | |
---|
138 | void JumpPlatform::touchFigure() |
---|
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 | } |
---|
193 | } |
---|