Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/portals/src/modules/pong/PongBat.cc @ 8484

Last change on this file since 8484 was 5781, checked in by rgrieder, 15 years ago

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

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