Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups/src/orxonox/objects/worldentities/PongBat.cc @ 2948

Last change on this file since 2948 was 2826, checked in by landauf, 16 years ago

merged miniprojects branch back to trunk

  • Property svn:eol-style set to native
File size: 2.9 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "PongBat.h"
31
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
34
35namespace orxonox
36{
37    CreateFactory(PongBat);
38
39    PongBat::PongBat(BaseObject* creator) : ControllableEntity(creator)
40    {
41        RegisterObject(PongBat);
42
43        this->movement_ = 0;
44        this->bMoveLocal_ = false;
45        this->speed_ = 60;
46        this->length_ = 0.25;
47        this->fieldHeight_ = 100;
48
49        this->registerVariables();
50    }
51
52    void PongBat::registerVariables()
53    {
54        registerVariable(this->speed_);
55        registerVariable(this->speed_);
56        registerVariable(this->speed_);
57    }
58
59    void PongBat::tick(float dt)
60    {
61        if (this->hasLocalController())
62        {
63            this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_;
64
65            if (this->bMoveLocal_)
66                this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0));
67            else
68                this->setVelocity(0, 0, this->movement_);
69
70            this->movement_ = 0;
71        }
72
73        SUPER(PongBat, tick, dt);
74
75        if (this->hasLocalController())
76        {
77            Vector3 position = this->getPosition();
78
79            if (position.z > this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2)
80                position.z = this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2;
81            if (position.z < -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2)
82                position.z = -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2;
83
84            if (position != this->getPosition())
85                this->setPosition(position);
86        }
87    }
88
89    void PongBat::moveFrontBack(const Vector2& value)
90    {
91        this->bMoveLocal_ = false;
92        this->movement_ -= value.x;
93    }
94
95    void PongBat::moveRightLeft(const Vector2& value)
96    {
97        this->bMoveLocal_ = true;
98        this->movement_ = value.x;
99    }
100}
Note: See TracBrowser for help on using the repository browser.