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 | * Joel Lingg |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "StoryModeController.h" |
---|
30 | |
---|
31 | namespace orxonox { |
---|
32 | RegisterClass(StoryModeController); |
---|
33 | |
---|
34 | StoryModeController::StoryModeController(Context * context): SpaceShip(context) { |
---|
35 | |
---|
36 | RegisterObject(StoryModeController); |
---|
37 | |
---|
38 | //initiate all variables according to our needs |
---|
39 | selectedPos_ = new SMCoord(0); |
---|
40 | moveForward_ = false; |
---|
41 | moveBackward_ = false; |
---|
42 | boostPressed_ = false; |
---|
43 | init_ = true; |
---|
44 | dtime_ = 50; |
---|
45 | time_ = dtime_ + 1; |
---|
46 | updatePosition(); |
---|
47 | |
---|
48 | } |
---|
49 | StoryModeController::~StoryModeController() { |
---|
50 | delete selectedPos_; |
---|
51 | selectedPos_ = nullptr; |
---|
52 | |
---|
53 | } |
---|
54 | |
---|
55 | //Pre:selectedPos_ needs to be defined |
---|
56 | // Post: the position of the camera will be updated |
---|
57 | void StoryModeController::updatePosition() { |
---|
58 | Vector3 pos = selectedPos_ -> get3dcoordinate(); |
---|
59 | setPosition(pos); |
---|
60 | } |
---|
61 | |
---|
62 | //Pre: @index integer |
---|
63 | //post: our new position is updated in selectedPos_ |
---|
64 | void StoryModeController::setLocation(int index) { |
---|
65 | selectedPos_ -> set(index); |
---|
66 | } |
---|
67 | |
---|
68 | //Function which is repeated anz dt. |
---|
69 | void StoryModeController::tick(float dt) { |
---|
70 | //Passing arguments to SpaceShip |
---|
71 | SUPER(StoryModeController, tick, dt); |
---|
72 | |
---|
73 | Camera * camera = this -> getCamera(); |
---|
74 | |
---|
75 | if (init_ && camera != nullptr) { |
---|
76 | camera -> setPosition(0, 0, 200); |
---|
77 | camera -> setOrientation(Vector3::UNIT_Z, Degree(0)); |
---|
78 | init_ = false; |
---|
79 | } |
---|
80 | |
---|
81 | //As I dont want to update positions every time (to prevent multiple key presses) time_ is raised untill a sertain dtime_ |
---|
82 | time_++; |
---|
83 | if (time_ >= dtime_) { |
---|
84 | |
---|
85 | time_ = 0; |
---|
86 | |
---|
87 | if (moveForward_ == true) { |
---|
88 | moveForward_ = false; |
---|
89 | selectedPos_ -> set(selectedPos_ -> getIndex() + 1); |
---|
90 | updatePosition(); |
---|
91 | } |
---|
92 | |
---|
93 | if (moveBackward_ == true) { |
---|
94 | moveBackward_ = false; |
---|
95 | selectedPos_ -> set(selectedPos_ -> getIndex() - 1); |
---|
96 | updatePosition(); |
---|
97 | } |
---|
98 | |
---|
99 | if (boostPressed_ == true) { |
---|
100 | boostPressed_ = false; |
---|
101 | chooseGame(); |
---|
102 | } |
---|
103 | |
---|
104 | //updates the cameraposition |
---|
105 | if (camera != nullptr) { |
---|
106 | |
---|
107 | camera -> setPosition(0, 0, 200); |
---|
108 | camera -> setOrientation(Vector3::UNIT_Z, Degree(0)); |
---|
109 | |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | //Post: The game is choosen acording to the index in selectedPos_. This one must be extended if more games want to be loaded |
---|
116 | void StoryModeController::chooseGame() { |
---|
117 | int ind = selectedPos_ -> getIndex(); |
---|
118 | std::string name = "changeGame "; |
---|
119 | switch (ind) { |
---|
120 | case 0: |
---|
121 | name = name + "gallery.oxw"; |
---|
122 | break; |
---|
123 | case 1: |
---|
124 | name = name + "pong.oxw"; |
---|
125 | break; |
---|
126 | case 2: |
---|
127 | name = name + "towerDefense.oxw"; |
---|
128 | break; |
---|
129 | case 3: |
---|
130 | name = name + "SOB.oxw"; |
---|
131 | break; |
---|
132 | |
---|
133 | default: |
---|
134 | name = name + "MapExample.oxw"; |
---|
135 | break; |
---|
136 | } |
---|
137 | CommandExecutor::execute(name); |
---|
138 | |
---|
139 | } |
---|
140 | |
---|
141 | //decides if we move left or right |
---|
142 | void StoryModeController::moveRightLeft(const Vector2 & value) { |
---|
143 | if (!moveForward_ && !moveBackward_ && !boostPressed_) { |
---|
144 | if (value.x > 0) { |
---|
145 | moveForward_ = false; |
---|
146 | moveBackward_ = true; |
---|
147 | } else { |
---|
148 | moveBackward_ = false; |
---|
149 | moveForward_ = true; |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | } |
---|
154 | |
---|
155 | //decides to choose the game |
---|
156 | void StoryModeController::boost(bool bBoost) { |
---|
157 | if (!moveForward_ && !moveBackward_ && !boostPressed_) { |
---|
158 | boostPressed_ = true; |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | //Some functions I didn't use, but can be used to enhance your map. Just orientate at the function above |
---|
163 | void StoryModeController::rotateYaw(const Vector2 & value) {} |
---|
164 | void StoryModeController::rotatePitch(const Vector2 & value) {} |
---|
165 | void StoryModeController::rotateRoll(const Vector2 & value) {} |
---|
166 | void StoryModeController::moveFrontBack(const Vector2 & value) {} |
---|
167 | void StoryModeController::fire(unsigned int a) {} |
---|
168 | void StoryModeController::fired(unsigned int b) {} |
---|
169 | |
---|
170 | } |
---|