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 | * Cyrill Burgener |
---|
24 | * |
---|
25 | */ |
---|
26 | |
---|
27 | /** |
---|
28 | @file HoverShip.cc |
---|
29 | @brief Implementation of the HoverShip control |
---|
30 | */ |
---|
31 | |
---|
32 | #include "HoverShip.h" |
---|
33 | #include "core/CoreIncludes.h" |
---|
34 | #include "core/XMLPort.h" |
---|
35 | |
---|
36 | #include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h> |
---|
37 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | RegisterClass(HoverShip); |
---|
41 | |
---|
42 | HoverShip::HoverShip(Context* context) : SpaceShip(context) |
---|
43 | { |
---|
44 | RegisterObject(HoverShip); |
---|
45 | enableCollisionCallback(); |
---|
46 | isFloor_ = false; |
---|
47 | jumpBoost_ = 0; |
---|
48 | } |
---|
49 | |
---|
50 | void HoverShip::moveFrontBack(const Vector2& value) |
---|
51 | { this->steering_.z -= value.x; } |
---|
52 | |
---|
53 | void HoverShip::moveRightLeft(const Vector2& value) |
---|
54 | { this->steering_.x += value.x; } |
---|
55 | |
---|
56 | void HoverShip::moveUpDown(const Vector2& value) |
---|
57 | { this->steering_.y += value.x; } |
---|
58 | |
---|
59 | void HoverShip::rotateYaw(const Vector2& value) |
---|
60 | { |
---|
61 | this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x); |
---|
62 | |
---|
63 | Pawn::rotateYaw(value); |
---|
64 | } |
---|
65 | |
---|
66 | void HoverShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
67 | { |
---|
68 | SUPER(HoverShip, XMLPort, xmlelement, mode); |
---|
69 | |
---|
70 | XMLPortParam(HoverShip, "jumpBoost", setJumpBoost, getJumpBoost, xmlelement, mode); |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | @brief |
---|
75 | Removed, does nothing. |
---|
76 | @param value |
---|
77 | */ |
---|
78 | void HoverShip::rotatePitch(const Vector2& value) { } |
---|
79 | |
---|
80 | /** |
---|
81 | @brief |
---|
82 | Removed, does nothing. |
---|
83 | @param value |
---|
84 | */ |
---|
85 | void HoverShip::rotateRoll(const Vector2& value) { } |
---|
86 | |
---|
87 | /** |
---|
88 | @brief |
---|
89 | Checks if the ship is touching the floor. The ship can only jump if there is contact with someting beneath it. |
---|
90 | */ |
---|
91 | bool HoverShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) |
---|
92 | { |
---|
93 | SpaceShip::collidesAgainst(otherObject, cs, contactPoint); |
---|
94 | //SUPER(HoverShip, collidesAgainst, otherObject, cs, contactPoint); |
---|
95 | |
---|
96 | if (contactPoint.m_normalWorldOnB.y() > 0.6 |
---|
97 | && this->getVelocity().y < 1) { |
---|
98 | this->isFloor_ = true; |
---|
99 | } else { |
---|
100 | this->isFloor_ = false; |
---|
101 | } |
---|
102 | |
---|
103 | return false; |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | @brief |
---|
108 | Makes the ship jump |
---|
109 | @param bBoost |
---|
110 | */ |
---|
111 | void HoverShip::boost(bool bBoost) { |
---|
112 | if (bBoost && this->isFloor_) |
---|
113 | { |
---|
114 | this->setVelocity( |
---|
115 | this->getVelocity().x, |
---|
116 | jumpBoost_, |
---|
117 | this->getVelocity().z |
---|
118 | ); |
---|
119 | this->isFloor_ = false; |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|