Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/MouseAPI_FS19/src/modules/jump/JumpItem.cc @ 12412

Last change on this file since 12412 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 3.2 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 JumpItem.cc
31    @brief All items in this minigame inherit from this class. Items can move around like platforms and enemies.
32*/
33
34#include "JumpItem.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "JumpFigure.h"
39
40namespace orxonox
41{
42    RegisterClass(JumpItem);
43
44    JumpItem::JumpItem(Context* context) : MovableEntity(context)
45    {
46        RegisterObject(JumpItem);
47
48        attachedToFigure_ = false;
49
50        figure_ = nullptr;
51        height_ = 0.0;
52        width_ = 0.0;
53        setPosition(Vector3(0,0,0));
54        setVelocity(Vector3(0,0,0));
55        setAcceleration(Vector3(0,0,0));
56    }
57
58    JumpItem::~JumpItem()
59    {
60
61    }
62
63    void JumpItem::XMLPort(Element& xmlelement, XMLPort::Mode mode)
64    {
65        SUPER(JumpItem, XMLPort, xmlelement, mode);
66
67        XMLPortParam(JumpItem, "height", setHeight, getHeight, xmlelement, mode);
68        XMLPortParam(JumpItem, "width", setWidth, getWidth, xmlelement, mode);
69    }
70
71    void JumpItem::tick(float dt)
72    {
73        SUPER(JumpItem, tick, dt);
74        // Get the current position, velocity and acceleration of the item.
75        Vector3 position = getWorldPosition();
76        Vector3 velocity = getVelocity();
77
78        if ((position.x < leftBoundary_ && velocity.x < 0) || (position.x > rightBoundary_ && velocity.x > 0))
79        {
80            velocity.x = -velocity.x;
81        }
82
83        if ((position.z < lowerBoundary_ && velocity.z < 0) || (position.z > upperBoundary_ && velocity.z > 0))
84        {
85            velocity.z = -velocity.z;
86        }
87
88        // Set the position, velocity and acceleration of the item, if they have changed.
89        if (velocity != getVelocity())
90        {
91            setVelocity(velocity);
92        }
93    }
94
95    void JumpItem::setProperties(float newLeftBoundary, float newRightBoundary, float newLowerBoundary, float newUpperBoundary, float newHSpeed, float newVSpeed)
96    {
97        leftBoundary_ = newLeftBoundary;
98        rightBoundary_ = newRightBoundary;
99        lowerBoundary_ = newLowerBoundary;
100        upperBoundary_ = newUpperBoundary;
101
102        setVelocity(Vector3(newHSpeed,0,newVSpeed));
103    }
104
105    void JumpItem::setFigure(JumpFigure* newFigure)
106    {
107        figure_ = newFigure;
108    }
109
110    void JumpItem::touchFigure()
111    {
112
113    }
114}
Note: See TracBrowser for help on using the repository browser.