Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/jump/JumpPlatform.cc @ 10544

Last change on this file since 10544 was 10262, checked in by landauf, 10 years ago

eol-style native. no changes in code.

  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
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"
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
46namespace orxonox
47{
48    RegisterClass(JumpPlatform);
49
50    JumpPlatform::JumpPlatform(Context* context) : MovableEntity(context)
51    {
52        RegisterObject(JumpPlatform);
53
54        figure_ = 0;
55
56        //initialize sound
57        if (GameMode::isMaster())
58        {
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);
65        }
66        else
67        {
68            defScoreSound_ = 0;
69            defBatSound_ = 0;
70            defBoundarySound_ = 0;
71        }
72
73        setPosition(Vector3(0,0,0));
74        setVelocity(Vector3(0,0,0));
75        setAcceleration(Vector3(0,0,0));
76    }
77
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);
91
92        XMLPortParam(JumpPlatform, "height", setHeight, getHeight, xmlelement, mode);
93        XMLPortParam(JumpPlatform, "width", setWidth, getWidth, xmlelement, mode);
94
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    */
107    void JumpPlatform::tick(float dt)
108    {
109        SUPER(JumpPlatform, tick, dt);
110
111        Vector3 platformPosition = this->getPosition();
112
113        if (figure_ != NULL)
114        {
115            Vector3 figurePosition = figure_->getPosition();
116            Vector3 figureVelocity = figure_->getVelocity();
117
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)
121            {
122                touchFigure();
123            }
124        }
125    }
126
127    void JumpPlatform::setFigure(WeakPtr<JumpFigure> newFigure)
128    {
129        figure_ = newFigure;
130    }
131
132    void JumpPlatform::touchFigure()
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    }
187}
Note: See TracBrowser for help on using the repository browser.