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 | * Florian Zinggeler |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file InvaderShip.cc |
---|
31 | @brief Implementation of the InvaderShip class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "InvaderShip.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/XMLPort.h" |
---|
38 | |
---|
39 | namespace orxonox |
---|
40 | { |
---|
41 | RegisterClass(InvaderShip); |
---|
42 | |
---|
43 | /** |
---|
44 | @brief |
---|
45 | Constructor. Registers and initializes the object. |
---|
46 | */ |
---|
47 | InvaderShip::InvaderShip(Context* context) : SpaceShip(context) |
---|
48 | { |
---|
49 | RegisterObject(InvaderShip); |
---|
50 | |
---|
51 | speed = 500; |
---|
52 | damping = 10; |
---|
53 | } |
---|
54 | |
---|
55 | void InvaderShip::tick(float dt) |
---|
56 | { |
---|
57 | // If the bat is controlled (but not over the network). |
---|
58 | if (this->hasLocalController()) |
---|
59 | { |
---|
60 | this->setVelocity(Vector3(1000 + velocity.y, 0, velocity.x)); // |
---|
61 | //this->setVelocity(this->getOrientation() * Vector3(1, 0, 0)); |
---|
62 | } |
---|
63 | lastTimeFront += dt * damping; |
---|
64 | lastTimeLeft += dt * damping; |
---|
65 | velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); |
---|
66 | velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); |
---|
67 | |
---|
68 | if (isFireing) |
---|
69 | ControllableEntity::fire(0); |
---|
70 | |
---|
71 | SUPER(InvaderShip, tick, dt); |
---|
72 | } |
---|
73 | |
---|
74 | void InvaderShip::moveFrontBack(const Vector2& value) |
---|
75 | { |
---|
76 | orxout(internal_error) << "move backfront" << value.x << value.y << endl; |
---|
77 | //velocity.y = value.y * speed * 10; |
---|
78 | lastTimeFront = 0; |
---|
79 | desiredVelocity.y = value.y * speed * 10; |
---|
80 | } |
---|
81 | |
---|
82 | void InvaderShip::moveRightLeft(const Vector2& value) |
---|
83 | { |
---|
84 | orxout(internal_error) << "right left front" << value.x << value.y << endl; |
---|
85 | lastTimeLeft = 0; |
---|
86 | desiredVelocity.x = value.x * speed; |
---|
87 | // velocity.x = value.x * speed; |
---|
88 | } |
---|
89 | void InvaderShip::boost(bool bBoost) |
---|
90 | { |
---|
91 | isFireing = bBoost; |
---|
92 | } |
---|
93 | } |
---|