Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cpp11_v2/src/modules/jump/JumpSpring.cc @ 10736

Last change on this file since 10736 was 10733, checked in by landauf, 9 years ago

merged branch cpp11 to cpp11_v2

  • Property svn:eol-style set to native
File size: 2.7 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 JumpSpring.cc
31    @brief If this spring is touched by the figure, it jumps higher then from a platform.
32*/
33
34#include "JumpSpring.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "JumpFigure.h"
39
40namespace orxonox
41{
42    RegisterClass(JumpSpring);
43
44    JumpSpring::JumpSpring(Context* context) : JumpItem(context)
45    {
46        RegisterObject(JumpSpring);
47
48        stretch_ = 1.0;
49
50        setPosition(Vector3(0,0,0));
51        setVelocity(Vector3(0,0,0));
52        setAcceleration(Vector3(0,0,0));
53
54        setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
55    }
56
57    JumpSpring::~JumpSpring()
58    {
59
60    }
61
62    void JumpSpring::XMLPort(Element& xmlelement, XMLPort::Mode mode)
63    {
64        SUPER(JumpSpring, XMLPort, xmlelement, mode);
65    }
66
67    void JumpSpring::tick(float dt)
68    {
69        SUPER(JumpSpring, tick, dt);
70
71        if (stretch_ > 1.0)
72        {
73            stretch_ -= dt;
74            setScale3D(1.0, 1.0, stretch_);
75        }
76
77        Vector3 springPosition = getWorldPosition();
78
79        if (figure_ != NULL)
80        {
81            Vector3 figurePosition = figure_->getWorldPosition();
82            Vector3 figureVelocity = figure_->getVelocity();
83
84            if(figureVelocity.z < 0 && figurePosition.x > springPosition.x-width_ && figurePosition.x < springPosition.x+width_ && figurePosition.z > springPosition.z-height_ && figurePosition.z < springPosition.z+height_)
85            {
86                touchFigure();
87            }
88        }
89    }
90
91    void JumpSpring::touchFigure()
92    {
93        JumpItem::touchFigure();
94
95        stretch_ = 3.0;
96
97        accelerateFigure();
98    }
99
100    void JumpSpring::accelerateFigure()
101    {
102        if (figure_ != 0)
103        {
104            figure_->JumpFromSpring(this);
105        }
106    }
107}
Note: See TracBrowser for help on using the repository browser.