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 | /** |
---|
30 | @file JumpEnemy.cc |
---|
31 | @brief Implementation of the JumpEnemy class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "JumpEnemy.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/GameMode.h" |
---|
38 | #include "graphics/Model.h" |
---|
39 | #include "gametypes/Gametype.h" |
---|
40 | |
---|
41 | #include "JumpFigure.h" |
---|
42 | |
---|
43 | #include "sound/WorldSound.h" |
---|
44 | #include "core/XMLPort.h" |
---|
45 | |
---|
46 | namespace orxonox |
---|
47 | { |
---|
48 | RegisterClass(JumpEnemy); |
---|
49 | |
---|
50 | /** |
---|
51 | @brief |
---|
52 | Constructor. Registers and initializes the object. |
---|
53 | */ |
---|
54 | JumpEnemy::JumpEnemy(Context* context) : MovableEntity(context) |
---|
55 | { |
---|
56 | RegisterObject(JumpEnemy); |
---|
57 | |
---|
58 | this->figure_ = 0; |
---|
59 | setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
---|
60 | this->setPosition(Vector3(0,0,0)); |
---|
61 | this->setVelocity(Vector3(0,0,0)); |
---|
62 | this->setAcceleration(Vector3(0,0,0)); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | @brief |
---|
67 | Destructor. |
---|
68 | */ |
---|
69 | JumpEnemy::~JumpEnemy() |
---|
70 | { |
---|
71 | /*if (this->isInitialized()) |
---|
72 | { |
---|
73 | if (this->bDeleteBats_) |
---|
74 | delete this->figure_; |
---|
75 | |
---|
76 | delete[] this->batID_; |
---|
77 | }*/ |
---|
78 | } |
---|
79 | |
---|
80 | //xml port for loading sounds |
---|
81 | void JumpEnemy::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
82 | { |
---|
83 | SUPER(JumpEnemy, XMLPort, xmlelement, mode); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | @brief |
---|
88 | Is called every tick. |
---|
89 | Handles the movement of the ball and its interaction with the boundaries and bats. |
---|
90 | @param dt |
---|
91 | The time since the last tick. |
---|
92 | */ |
---|
93 | void JumpEnemy::tick(float dt) |
---|
94 | { |
---|
95 | SUPER(JumpEnemy, tick, dt); |
---|
96 | |
---|
97 | // Get the current position, velocity and acceleration of the enemy. |
---|
98 | Vector3 position = getPosition(); |
---|
99 | Vector3 velocity = getVelocity(); |
---|
100 | |
---|
101 | if ((position.x < leftBoundary_ && velocity.x < 0) || (position.x > rightBoundary_ && velocity.x > 0)) |
---|
102 | { |
---|
103 | velocity.x = -velocity.x; |
---|
104 | } |
---|
105 | |
---|
106 | if ((position.z < lowerBoundary_ && velocity.z < 0) || (position.z > upperBoundary_ && velocity.z > 0)) |
---|
107 | { |
---|
108 | velocity.z = -velocity.z; |
---|
109 | } |
---|
110 | |
---|
111 | // Set the position, velocity and acceleration of the enemy, if they have changed. |
---|
112 | if (velocity != getVelocity()) |
---|
113 | setVelocity(velocity); |
---|
114 | if (position != getPosition()) |
---|
115 | setPosition(position); |
---|
116 | |
---|
117 | |
---|
118 | } |
---|
119 | |
---|
120 | void JumpEnemy::setProperties(float newLeftBoundary, float newRightBoundary, float newLowerBoundary, float newUpperBoundary, float newHSpeed, float newVSpeed) |
---|
121 | { |
---|
122 | leftBoundary_ = newLeftBoundary; |
---|
123 | rightBoundary_ = newRightBoundary; |
---|
124 | lowerBoundary_ = newLowerBoundary; |
---|
125 | upperBoundary_ = newUpperBoundary; |
---|
126 | |
---|
127 | this->setVelocity(Vector3(newHSpeed,0,newVSpeed)); |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | @brief |
---|
132 | Set the bats for the ball. |
---|
133 | @param bats |
---|
134 | An array (of size 2) of weak pointers, to be set as the new bats. |
---|
135 | */ |
---|
136 | void JumpEnemy::setFigure(WeakPtr<JumpFigure> newFigure) |
---|
137 | { |
---|
138 | figure_ = newFigure; |
---|
139 | } |
---|
140 | |
---|
141 | void JumpEnemy::touchFigure() |
---|
142 | { |
---|
143 | |
---|
144 | } |
---|
145 | } |
---|