Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/jump/JumpItem.cc @ 10853

Last change on this file since 10853 was 10624, checked in by landauf, 9 years ago

merged branch core7 back to trunk

  • Property svn:eol-style set to native
File size: 3.3 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/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(JumpItem);
49
50    JumpItem::JumpItem(Context* context) : MovableEntity(context)
51    {
52        RegisterObject(JumpItem);
53
54        attachedToFigure_ = false;
55
56        figure_ = 0;
57        height_ = 0.0;
58        width_ = 0.0;
59        setPosition(Vector3(0,0,0));
60        setVelocity(Vector3(0,0,0));
61        setAcceleration(Vector3(0,0,0));
62    }
63
64    JumpItem::~JumpItem()
65    {
66
67    }
68
69    void JumpItem::XMLPort(Element& xmlelement, XMLPort::Mode mode)
70    {
71        SUPER(JumpItem, XMLPort, xmlelement, mode);
72
73        XMLPortParam(JumpItem, "height", setHeight, getHeight, xmlelement, mode);
74        XMLPortParam(JumpItem, "width", setWidth, getWidth, xmlelement, mode);
75    }
76
77    void JumpItem::tick(float dt)
78    {
79        SUPER(JumpItem, tick, dt);
80        // Get the current position, velocity and acceleration of the item.
81        Vector3 position = getWorldPosition();
82        Vector3 velocity = getVelocity();
83
84        if ((position.x < leftBoundary_ && velocity.x < 0) || (position.x > rightBoundary_ && velocity.x > 0))
85        {
86            velocity.x = -velocity.x;
87        }
88
89        if ((position.z < lowerBoundary_ && velocity.z < 0) || (position.z > upperBoundary_ && velocity.z > 0))
90        {
91            velocity.z = -velocity.z;
92        }
93
94        // Set the position, velocity and acceleration of the item, if they have changed.
95        if (velocity != getVelocity())
96        {
97            setVelocity(velocity);
98        }
99    }
100
101    void JumpItem::setProperties(float newLeftBoundary, float newRightBoundary, float newLowerBoundary, float newUpperBoundary, float newHSpeed, float newVSpeed)
102    {
103        leftBoundary_ = newLeftBoundary;
104        rightBoundary_ = newRightBoundary;
105        lowerBoundary_ = newLowerBoundary;
106        upperBoundary_ = newUpperBoundary;
107
108        setVelocity(Vector3(newHSpeed,0,newVSpeed));
109    }
110
111    void JumpItem::setFigure(JumpFigure* newFigure)
112    {
113        figure_ = newFigure;
114    }
115
116    void JumpItem::touchFigure()
117    {
118
119    }
120}
Note: See TracBrowser for help on using the repository browser.