[12266] | 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 OrxoBloxCenterpoint.h |
---|
| 31 | @brief Declaration of the OrxoBloxCenterpoint class. |
---|
| 32 | @ingroup OrxoBlox |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | #ifndef _OrxoBloxCenterpoint_H__ |
---|
| 36 | #define _OrxoBloxCenterpoint_H__ |
---|
| 37 | |
---|
| 38 | #include "OrxoBlox/OrxoBloxPrereqs.h" |
---|
| 39 | |
---|
| 40 | #include <string> |
---|
| 41 | |
---|
| 42 | #include <util/Math.h> |
---|
| 43 | |
---|
| 44 | #include "worldentities/StaticEntity.h" |
---|
| 45 | |
---|
| 46 | namespace orxonox |
---|
| 47 | { |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | @brief |
---|
| 51 | The OrxoBloxCenterpoint implements the playing field @ref orxonox::OrxoBlox "OrxoBlox" takes place in and allows for many parameters of the minigame to be set. |
---|
| 52 | The playing field resides in the x,z-plane, with the x-axis being the horizontal axis and the z-axis being the vertical axis. |
---|
| 53 | |
---|
| 54 | Various parameters can be set: |
---|
| 55 | - The <b>dimension</b> is a vector, that defines the width and height of the playing field. The default is <em>(200, 120)</em>. |
---|
| 56 | - The <b>balltemplate</b> is a template that is applied to the @ref orxonox::OrxoBloxBall "OrxoBloxBall", it can be used to attach different things to it, e.g. its @ref orxonox::Model "Model". See below for a usage example. |
---|
| 57 | - The <b>battemplate</b> is a template that is applied to the @ref orxonox::OrxoBloxBall "OrxoBloxBat", it can be used to attach different things to it, e.g. its @ref orxonox::Model "Model". See below for a usage example. |
---|
| 58 | - The <b>ballspeed</b> is the speed with which the @ref orxonox::OrxoBloxBall "OrxoBloxBall" moves. The default is <em>100</em>. |
---|
| 59 | - The <b>ballaccfactor</b> is the acceleration factor for the @ref orxonox::OrxoBloxBall "OrxoBloxBall". The default is <em>1.0</em>. |
---|
| 60 | - The <b>batspeed</b> is the speed with which the @ref orxonox::OrxoBloxBat "OrxoBloxBats" move. The default is <em>60</em>. |
---|
| 61 | - The <b>batlength</b> is the length of the @ref orxonox::OrxoBloxBat "OrxoBloxBats" as the percentage of the height of the playing field. The default is <em>0.25</em>. |
---|
| 62 | |
---|
| 63 | An example in XML of the OrxoBloxCenterpoint would be: |
---|
| 64 | |
---|
| 65 | First the needed templates: |
---|
| 66 | The template for the @ref orxonox::OrxoBloxBall "OrxoBloxBall". |
---|
| 67 | @code |
---|
| 68 | <Template name="OrxoBloxball"> |
---|
| 69 | <OrxoBloxBall> |
---|
| 70 | <attached> |
---|
| 71 | <Model mesh="sphere.mesh" scale="2" /> |
---|
| 72 | <ParticleSpawner name="hiteffect" position="0,0,0" source="Orxonox/sparks2" lifetime="0.01" autostart="0" mainstate="spawn" /> |
---|
| 73 | </attached> |
---|
| 74 | <eventlisteners> |
---|
| 75 | <EventTarget target="hiteffect" /> |
---|
| 76 | </eventlisteners> |
---|
| 77 | </OrxoBloxBall> |
---|
| 78 | </Template> |
---|
| 79 | @endcode |
---|
| 80 | As can be seen, a sphere is attached as the @ref orxonox::Model "Model" for the @ref orxonox::OrxoBloxBall "OrxoBloxBall", and also an @ref orxonox::EventListener "EventListener" that triggers a @ref orxonox::ParticleSpawner "ParticleSpawner", whenever the ball hits the boundaries is attached. |
---|
| 81 | |
---|
| 82 | Additionally the template for the @ref orxonox::OrxoBloxBat "OrxoBloxBat". |
---|
| 83 | @code |
---|
| 84 | <Template name="OrxoBloxbatcameras" defaults="0"> |
---|
| 85 | <OrxoBloxBat> |
---|
| 86 | <camerapositions> |
---|
| 87 | <CameraPosition position="0,200,0" pitch="-90" absolute="true" /> |
---|
| 88 | </camerapositions> |
---|
| 89 | </OrxoBloxBat> |
---|
| 90 | </Template> |
---|
| 91 | |
---|
| 92 | <Template name="OrxoBloxbat"> |
---|
| 93 | <OrxoBloxBat camerapositiontemplate=OrxoBloxbatcameras> |
---|
| 94 | <attached> |
---|
| 95 | <Model position="0,0,3" mesh="cube.mesh" scale3D="14,2,2" /> |
---|
| 96 | </attached> |
---|
| 97 | </OrxoBloxBat> |
---|
| 98 | </Template> |
---|
| 99 | @endcode |
---|
| 100 | As can be seen, there are actually two templates. The first template is needed to set the camera for the @ref orxonox::OrxoBloxBat "OrxoBloxBat". The second template ist the actual template for the @ref orxonox::OrxoBloxBat "OrxoBloxBat", the template for the camera position is added and a @ref orxonox::Model "Model" for the @ref orxonox::OrxoBloxBat "OrxoBloxBat" is attached. |
---|
| 101 | |
---|
| 102 | Finally the OrxoBloxCenterpoint is created. |
---|
| 103 | @code |
---|
| 104 | <OrxoBloxCenterpoint name="OrxoBloxcenter" dimension="200,120" balltemplate="OrxoBloxball" battemplate="OrxoBloxbat" ballspeed="200" ballaccfactor="1.0" batspeed="130" batlength="0.25"> |
---|
| 105 | <attached> |
---|
| 106 | <Model position="0,0,60" mesh="cube.mesh" scale3D="105,1,1" /> |
---|
| 107 | <Model position="0,0,-60" mesh="cube.mesh" scale3D="105,1,1" /> |
---|
| 108 | </attached> |
---|
| 109 | </OrxoBloxCenterpoint> |
---|
| 110 | @endcode |
---|
| 111 | All parameters are specified. And also two @ref orxonox::Model "Models" (for the upper and lower boundary) are attached. |
---|
| 112 | |
---|
| 113 | For a more elaborate example, have a look at the <code>OrxoBlox.oxw</code> level file. |
---|
| 114 | |
---|
| 115 | @author |
---|
| 116 | Fabian 'x3n' Landau |
---|
| 117 | |
---|
| 118 | @ingroup OrxoBlox |
---|
| 119 | */ |
---|
| 120 | class _OrxoBloxExport OrxoBloxCenterpoint : public StaticEntity |
---|
| 121 | { |
---|
| 122 | public: |
---|
| 123 | OrxoBloxCenterpoint(Context* context); //!< Constructor. Registers and initializes the object and checks whether the gametype is actually OrxoBlox. |
---|
| 124 | virtual ~OrxoBloxCenterpoint() {} |
---|
| 125 | |
---|
| 126 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; //!< Method to create a OrxoBloxCenterpoint through XML. |
---|
| 127 | |
---|
| 128 | /** |
---|
| 129 | @brief Set the template for the ball. (e.g. to attach the model of the ball, but also to attach an EventListener to it to detect, when it hits the boundaries, and e.g. display some ParticleEffets, when it does.) |
---|
| 130 | @param balltemplate The name of the template to be set. |
---|
| 131 | */ |
---|
| 132 | void setBalltemplate(const std::string& balltemplate) |
---|
| 133 | { this->balltemplate_ = balltemplate; } |
---|
| 134 | /** |
---|
| 135 | @brief Get the template of the ball. |
---|
| 136 | @return Returns the name of the template of the ball. |
---|
| 137 | */ |
---|
| 138 | const std::string& getBalltemplate() const |
---|
| 139 | { return this->balltemplate_; } |
---|
| 140 | |
---|
[12366] | 141 | |
---|
[12266] | 142 | /** |
---|
| 143 | @brief Set the dimensions of the playing field. |
---|
| 144 | @param dimension A vector with the width of the playing field as first component and the height as second. |
---|
| 145 | */ |
---|
| 146 | void setFieldDimension(const Vector2& dimension) |
---|
| 147 | { this->width_ = dimension.x; this->height_ = dimension.y; } |
---|
| 148 | /** |
---|
| 149 | @brief Get the dimensions of the playing field. |
---|
| 150 | @return Returns a vector with the width of the playing field as first component and the height as second. |
---|
| 151 | */ |
---|
| 152 | Vector2 getFieldDimension() const |
---|
| 153 | { return Vector2(this->width_, this->height_); } |
---|
| 154 | |
---|
| 155 | /** |
---|
| 156 | @brief Set the speed of the ball. |
---|
| 157 | @param ballspeed The speed of the ball. |
---|
| 158 | */ |
---|
| 159 | void setBallSpeed(float ballspeed) |
---|
| 160 | { this->ballspeed_ = ballspeed; } |
---|
| 161 | /** |
---|
| 162 | @brief Get the speed of the ball. |
---|
| 163 | @return Returns the speed of the ball. |
---|
| 164 | */ |
---|
| 165 | float getBallSpeed() const |
---|
| 166 | { return this->ballspeed_; } |
---|
| 167 | |
---|
| 168 | /** |
---|
| 169 | @brief Set the ball's acceleration factor. |
---|
| 170 | @param ballaccfactor The ball's acceleration factor. |
---|
| 171 | */ |
---|
| 172 | void setBallAccelerationFactor(float ballaccfactor) |
---|
| 173 | { this->ballaccfactor_ = ballaccfactor; } |
---|
| 174 | /** |
---|
| 175 | @brief Get the ball's acceleration factor |
---|
| 176 | @return Returns the ball's acceleration factor. |
---|
| 177 | */ |
---|
| 178 | float getBallAccelerationFactor() const |
---|
| 179 | { return this->ballaccfactor_; } |
---|
| 180 | |
---|
[12366] | 181 | |
---|
[12266] | 182 | /** |
---|
[12307] | 183 | @brief Set the template for the stones. |
---|
| 184 | @param templateName The template name to be applied to each stone. |
---|
| 185 | */ |
---|
| 186 | void setStoneTemplate(const std::string& templateName) |
---|
| 187 | { this->stoneTemplate_ = templateName; } |
---|
| 188 | /** |
---|
| 189 | @brief Get the template for the stones. |
---|
| 190 | @return Returns the template name to be applied to each stone. |
---|
| 191 | */ |
---|
| 192 | const std::string& getStoneTemplate(void) const |
---|
| 193 | { return this->stoneTemplate_; } |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | /** |
---|
| 197 | @brief Set the template for the bricks. |
---|
| 198 | @param templateName The template name to be applied to each brick. |
---|
| 199 | */ |
---|
| 200 | void setWallTemplate(const std::string& templateName) |
---|
| 201 | { this->WallTemplate_ = templateName; } |
---|
| 202 | |
---|
| 203 | /** |
---|
| 204 | @brief Get the template for the bricks. |
---|
| 205 | @return Returns the template name to be applied to each brick. |
---|
| 206 | */ |
---|
| 207 | const std::string& getWallTemplate(void) const |
---|
| 208 | { return this->WallTemplate_; } |
---|
| 209 | |
---|
| 210 | |
---|
[12266] | 211 | private: |
---|
| 212 | void checkGametype(); //!< Checks whether the gametype is OrxoBlox and if it is, sets its centerpoint. |
---|
| 213 | |
---|
| 214 | std::string balltemplate_; //!< The template for the ball. |
---|
[12307] | 215 | std::string WallTemplate_; |
---|
| 216 | std::string stoneTemplate_; |
---|
[12266] | 217 | |
---|
| 218 | float ballspeed_; //!< The speed of then ball. |
---|
| 219 | float ballaccfactor_; //!< The acceleration factor of the ball. |
---|
| 220 | float width_; //!< The height of the playing field. |
---|
| 221 | float height_; //!< The width of the playing field. |
---|
[12307] | 222 | |
---|
| 223 | |
---|
[12266] | 224 | }; |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | #endif /* _OrxoBloxCenterpoint_H__ */ |
---|