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 | * |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | *NACHRICHT: |
---|
28 | * |
---|
29 | * Hier empfehle ich euch die gesamte Spielogik unter zu bringen. Viele Funktionen werden automatisch |
---|
30 | * bei gewissen Ereignissen aufgerufen bzw. lösen Ereignisse aus |
---|
31 | * |
---|
32 | *Z.B: |
---|
33 | * start() //wird aufgerufen, bevor das Spiel losgeht |
---|
34 | * end() //wenn man diese Funktion aufruft wird |
---|
35 | * pawnKilled() // wird aufgerufen, wenn ein Pawn stirbt (z.B: wenn ) |
---|
36 | * playerScored() // kann man aufrufen um dem Spieler Punkte zu vergeben. |
---|
37 | * |
---|
38 | * |
---|
39 | *TIPP: Eclipse hilft euch schnell auf bereits vorhanden Funktionen zuzugreifen: |
---|
40 | * einfach "this->" eingeben und kurz warten. Dann tauch eine Liste mit Vorschlägen auf. Wenn ihr jetzt weiter |
---|
41 | * tippt, werden die Vorschläge entsprechend gefiltert. |
---|
42 | * |
---|
43 | * |
---|
44 | *TIPP: schaut euch mal Tetris::createStone() an. Dort wird ein TetrisStone-Objekt (ControllableEntity) erzeugt, |
---|
45 | * ihm ein Template zugewiesen (welches vorher im Level definiert wurde und dem CenterPoint übergeben wurde) |
---|
46 | * Ähnlich könnt ihr vorgehen, um einen Turm zu erzeugen. (Zusätzlich braucht ein Turm noch einen Controller) |
---|
47 | * z.B: WaypointPatrolController. Wenn kein Team zugewiesen wurde bekämpft ein WaypointPatrolController alles, |
---|
48 | * was in seiner Reichweite liegt. |
---|
49 | * |
---|
50 | * |
---|
51 | *HUD: |
---|
52 | * Ein Gametype kann ein HUD (Head up Display haben.) Z.B: hat Pong eine Anzeige welcher Spieler wieviele Punkte hat. |
---|
53 | * Generell kann man a) Grafiken oder b) Zeichen in einer HUD anzeigen. |
---|
54 | * Fuer den ersten Schritt reicht reiner Text. |
---|
55 | * |
---|
56 | * a) |
---|
57 | * PongScore.cc uebernehmen und eigene Klasse draus machen. |
---|
58 | * Wenn ihr bloss anzeigen wollt wieviele Punkte der Spieler bereits erspielt hat (Punkte = Kapital fuer neue Tuerme) dann orientiert ihr euch an |
---|
59 | * TetrisScore.cc (im pCuts branch): http://www.orxonox.net/browser/code/branches/pCuts/src/modules/tetris/TetrisScore.cc |
---|
60 | * Ich habe TetrisScore lediglich dazu gebraucht, um eine Variable auf dem HUD auszugeben. Ein Objekt fuer statischen Text gibt es bereits. |
---|
61 | * |
---|
62 | * b) |
---|
63 | * Im naesten Schritt erstellt man die Vorlage fuer das HUD-Objekt: siehe /data/overlays/pongHUD |
---|
64 | * OverlayText ist eine Vorlage fuer statischen text zb: "Points Scored:". Aus mir nicht erklaerlichen Gruenden sollte man die OverlayText |
---|
65 | * Objekte immer erst nach dem PongScore anlegen. |
---|
66 | * |
---|
67 | * c) Im TixyTaxyTorxy |
---|
68 | TixyTaxyTorxy gamtype muss im Constructor noch das HUD-Template gesetzt werden. |
---|
69 | * |
---|
70 | * d) in CMakeLists.txt noch das Module includen das fuer die Overlays zustaendig ist. Siehe das gleiche File im Pong module. |
---|
71 | * |
---|
72 | * |
---|
73 | * |
---|
74 | */ |
---|
75 | #include "TixyTaxyTorxy.h" |
---|
76 | #include "TixyTaxyTorxyTower.h" |
---|
77 | #include "TixyTaxyTorxyCenterpoint.h" |
---|
78 | #include "worldentities/SpawnPoint.h" |
---|
79 | #include "controllers/WaypointController.h" |
---|
80 | #include "graphics/Model.h" |
---|
81 | #include "infos/PlayerInfo.h" |
---|
82 | #include "chat/ChatManager.h" |
---|
83 | #include "core/CoreIncludes.h" |
---|
84 | #include "Highscore.h" |
---|
85 | |
---|
86 | namespace orxonox |
---|
87 | { |
---|
88 | RegisterUnloadableClass(TixyTaxyTorxy); |
---|
89 | |
---|
90 | |
---|
91 | TixyTaxyTorxy::TixyTaxyTorxy(Context* context) : TeamDeathmatch(context) |
---|
92 | { |
---|
93 | RegisterObject(TixyTaxyTorxy); |
---|
94 | |
---|
95 | selecter = nullptr; |
---|
96 | this->player_ = nullptr; |
---|
97 | this->setHUDTemplate("TixyTaxyTorxyHUD"); |
---|
98 | this->waveNumber_ = 0; |
---|
99 | this->timeSinceLastSpawn_ = 0.0; |
---|
100 | this->timeUntilNextWave_ = 0.0; |
---|
101 | this->credit_ = 0; |
---|
102 | this->lifes_ = 0; |
---|
103 | this->waveSize_ = 0; |
---|
104 | offset_ = Vector3(0,0,10); |
---|
105 | } |
---|
106 | |
---|
107 | TixyTaxyTorxy::~TixyTaxyTorxy() |
---|
108 | { |
---|
109 | if (this->isInitialized()) |
---|
110 | { |
---|
111 | |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | void TixyTaxyTorxy::setCenterpoint(TixyTaxyTorxyCenterpoint *centerpoint) |
---|
116 | { |
---|
117 | this->center_ = centerpoint; |
---|
118 | } |
---|
119 | |
---|
120 | void TixyTaxyTorxy::start() |
---|
121 | { |
---|
122 | if (center_ != nullptr) // There needs to be a TixyTaxyTorxyCenterpoint, i.e. the area the game takes place. |
---|
123 | { |
---|
124 | if (selecter == nullptr) |
---|
125 | { |
---|
126 | selecter = new TixyTaxyTorxySelecter(this->center_->getContext()); |
---|
127 | } |
---|
128 | selecter->addTemplate(center_->getSelecterTemplate()); |
---|
129 | center_->attach(selecter); |
---|
130 | } |
---|
131 | else // If no centerpoint was specified, an error is thrown and the level is exited. |
---|
132 | { |
---|
133 | orxout(internal_error) << "Jump: No Centerpoint specified." << endl; |
---|
134 | return; |
---|
135 | } |
---|
136 | |
---|
137 | createFields(); |
---|
138 | TeamDeathmatch::start(); |
---|
139 | |
---|
140 | //set initial credits, lifes and WaveNumber |
---|
141 | this->setCredit(1000); |
---|
142 | this->setLifes(100); |
---|
143 | this->timeSinceLastSpawn_ = 0.0; |
---|
144 | this->timeUntilNextWave_ = 5.0; |
---|
145 | this->waveSize_ = 0; |
---|
146 | this->setWaveNumber(0); |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | void TixyTaxyTorxy::end() |
---|
151 | { |
---|
152 | if (Highscore::exists()) |
---|
153 | { |
---|
154 | int score = this->getWaveNumber(); |
---|
155 | Highscore::getInstance().storeScore("Tower Defense", score, this->getPlayer()); |
---|
156 | } |
---|
157 | TeamDeathmatch::end(); |
---|
158 | ChatManager::message("Match is over! Gameover!"); |
---|
159 | |
---|
160 | } |
---|
161 | |
---|
162 | void TixyTaxyTorxy::spawnPlayer(PlayerInfo* player) |
---|
163 | { |
---|
164 | assert(player); |
---|
165 | player_ = player; |
---|
166 | |
---|
167 | if (selecter->getPlayer() == nullptr) |
---|
168 | { |
---|
169 | player_->startControl(selecter); |
---|
170 | players_[player].state_ = PlayerState::Alive; |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | /** |
---|
175 | @brief |
---|
176 | Get the player. |
---|
177 | @return |
---|
178 | Returns a pointer to the player. If there is no player, nullptr is returned. |
---|
179 | */ |
---|
180 | PlayerInfo* TixyTaxyTorxy::getPlayer(void) const |
---|
181 | { |
---|
182 | return this->player_; |
---|
183 | } |
---|
184 | |
---|
185 | //not working yet |
---|
186 | void TixyTaxyTorxy::addTower(int x,int y) |
---|
187 | { |
---|
188 | TixyTaxyTorxyCoordinate* coord = new TixyTaxyTorxyCoordinate(x,y); |
---|
189 | x = coord->GetX(); |
---|
190 | y = coord->GetY(); |
---|
191 | |
---|
192 | int cost = center_->getTowerCost(1); |
---|
193 | |
---|
194 | if (fields_[x][y]->isFree() == true && getCredit() >= cost) |
---|
195 | { |
---|
196 | payCredit(cost); |
---|
197 | fields_[x][y]->createTower(1); |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret") |
---|
202 | so towers have ability if the turrets |
---|
203 | */ |
---|
204 | |
---|
205 | void TixyTaxyTorxy::upgradeTower(int x, int y) |
---|
206 | { |
---|
207 | // TixyTaxyTorxyCoordinate* coord = new TixyTaxyTorxyCoordinate(x,y); |
---|
208 | // x = coord->GetX(); |
---|
209 | // y = coord->GetY(); |
---|
210 | |
---|
211 | // int cost = 100; |
---|
212 | |
---|
213 | // if (fields_[x][y]->isFree() == false && fields_[x][y]->canUpgrade() == true && getCredit() >= cost) |
---|
214 | // { |
---|
215 | // payCredit(cost); |
---|
216 | // fields_[x][y]->upgrade(); |
---|
217 | // } |
---|
218 | } |
---|
219 | |
---|
220 | void TixyTaxyTorxy::tick(float dt) |
---|
221 | { |
---|
222 | SUPER(TixyTaxyTorxy, tick, dt); |
---|
223 | |
---|
224 | if (hasStarted() == false || player_ == nullptr) |
---|
225 | { |
---|
226 | return; |
---|
227 | } |
---|
228 | timeUntilNextWave_ -= dt; |
---|
229 | timeSinceLastSpawn_ += dt; |
---|
230 | |
---|
231 | //build/upgrade tower at selecter position |
---|
232 | if (selecter != nullptr && selecter->buildTower_ == true) |
---|
233 | { |
---|
234 | selecter->buildTower_ = false; |
---|
235 | |
---|
236 | // if (getField(selecter->selectedPos_)->canUpgrade() == true) |
---|
237 | // { |
---|
238 | // upgradeTower(selecter->selectedPos_->GetX(), selecter->selectedPos_->GetY()); |
---|
239 | // } |
---|
240 | |
---|
241 | addTower(selecter->selectedPos_->GetX(), selecter->selectedPos_->GetY()); |
---|
242 | |
---|
243 | } |
---|
244 | |
---|
245 | |
---|
246 | } |
---|
247 | |
---|
248 | void TixyTaxyTorxy::createFields() |
---|
249 | { |
---|
250 | assert(center_); |
---|
251 | TixyTaxyTorxyCoordinate coord(0,0); |
---|
252 | TixyTaxyTorxyCoordinate startCoord(0,0); |
---|
253 | std::string fields = center_->getFields(); |
---|
254 | int pos = 0; |
---|
255 | for (int j = 15; j >= 0; --j) |
---|
256 | { |
---|
257 | for (int i = 0; i < 16; ++i) |
---|
258 | { |
---|
259 | coord.Set(i,j); |
---|
260 | fields_[i][j] = new TixyTaxyTorxyField(center_->getContext()); |
---|
261 | fields_[i][j]->setCenterpoint(center_); |
---|
262 | center_->attach(fields_[i][j]); |
---|
263 | fields_[i][j]->setPosition(coord.get3dcoordinate()); |
---|
264 | fields_[i][j]->create(fields.at(pos), fields.at(pos+1)); |
---|
265 | pos += 2; |
---|
266 | |
---|
267 | } |
---|
268 | } |
---|
269 | } |
---|
270 | |
---|
271 | } |
---|