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 | |
---|
35 | namespace 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 | this->bSteadiedPosition_ = false; |
---|
49 | |
---|
50 | this->registerVariables(); |
---|
51 | } |
---|
52 | |
---|
53 | void PongBat::registerVariables() |
---|
54 | { |
---|
55 | registerVariable(this->speed_); |
---|
56 | registerVariable(this->fieldHeight_); |
---|
57 | registerVariable(this->length_); |
---|
58 | } |
---|
59 | |
---|
60 | void PongBat::tick(float dt) |
---|
61 | { |
---|
62 | if (this->hasLocalController()) |
---|
63 | { |
---|
64 | if (this->movement_ != 0) |
---|
65 | { |
---|
66 | this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_; |
---|
67 | |
---|
68 | if (this->bMoveLocal_) |
---|
69 | this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0)); |
---|
70 | else |
---|
71 | this->setVelocity(0, 0, this->movement_); |
---|
72 | |
---|
73 | this->movement_ = 0; |
---|
74 | this->bSteadiedPosition_ = false; |
---|
75 | } |
---|
76 | else if (!this->bSteadiedPosition_) |
---|
77 | { |
---|
78 | // To ensure network synchronicity |
---|
79 | this->setVelocity(0, 0, 0); |
---|
80 | this->setPosition(this->getPosition()); |
---|
81 | this->bSteadiedPosition_ = true; |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | SUPER(PongBat, tick, dt); |
---|
86 | |
---|
87 | Vector3 position = this->getPosition(); |
---|
88 | if (position.z > this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2) |
---|
89 | position.z = this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2; |
---|
90 | if (position.z < -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2) |
---|
91 | position.z = -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2; |
---|
92 | if (position != this->getPosition()) |
---|
93 | this->setPosition(position); |
---|
94 | } |
---|
95 | |
---|
96 | void PongBat::moveFrontBack(const Vector2& value) |
---|
97 | { |
---|
98 | this->bMoveLocal_ = false; |
---|
99 | this->movement_ -= value.x; |
---|
100 | } |
---|
101 | |
---|
102 | void PongBat::moveRightLeft(const Vector2& value) |
---|
103 | { |
---|
104 | this->bMoveLocal_ = true; |
---|
105 | this->movement_ = value.x; |
---|
106 | } |
---|
107 | |
---|
108 | void PongBat::changedPlayer() |
---|
109 | { |
---|
110 | this->setVelocity(0, 0, 0); |
---|
111 | } |
---|
112 | } |
---|