[9098] | 1 | /* |
---|
[9112] | 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
[9098] | 4 | * |
---|
[9112] | 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 | * Ich habe die Klasse Deathmatch einfach per Copy&Paste&Rename als Vorlage für euren Deathmatch genommen. |
---|
| 29 | * Ein Deathmatch erbt vom Gametype. Der einzige Unterschied zum Gametype ist, dass hier ein bisschen |
---|
| 30 | * Textausgabe stattfindet. Sollte das Später nicht erwünscht sein, könnt ihr einfach die Gametype-Klasse |
---|
| 31 | * an die Stelle von Deathmatch setzten. |
---|
| 32 | * |
---|
| 33 | * Hier empfehle ich euch die gesamte Spielogik unter zu bringen. Viele Funktionen werden automatisch |
---|
| 34 | * bei gewissen Ereignissen aufgerufen bzw. lösen Ereignisse aus |
---|
| 35 | * |
---|
| 36 | *Z.B: |
---|
| 37 | * start() //wird aufgerufen, bevor das Spiel losgeht |
---|
| 38 | * end() //wenn man diese Funktion aufruft wird |
---|
| 39 | * pawnKilled() // wird aufgerufen, wenn ein Pawn stirbt (z.B: wenn ) |
---|
| 40 | * playerScored() // kann man aufrufen um dem Spieler Punkte zu vergeben. |
---|
| 41 | * |
---|
| 42 | * |
---|
| 43 | * |
---|
| 44 | *TIPP: Eclipse hilft euch schnell auf bereits vorhanden Funktionen zuzugreifen: |
---|
| 45 | * einfach "this->" eingeben und kurz warten. Dann tauch eine Liste mit Vorschlägen auf. Wenn ihr jetzt weiter |
---|
| 46 | * tippt, werden die Vorschläge entsprechend gefiltert. |
---|
| 47 | * |
---|
| 48 | * |
---|
| 49 | *TIPP: schaut euch mal Tetris::createStone() an. Dort wird ein TetrisStone-Objekt (ControllableEntity) erzeugt, |
---|
| 50 | * ihm ein Template zugewiesen (welches vorher im Level definiert wurde und dem CenterPoint übergeben wurde) |
---|
| 51 | * Ähnlich könnt ihr vorgehen, um einen Turm zu erzeugen. (Zusätzlich braucht ein Turm noch einen Controller) |
---|
| 52 | * z.B: WaypointPatrolController. Wenn kein Team zugewiesen wurde bekämpft ein WaypointPatrolController alles, |
---|
| 53 | * was in seiner Reichweite liegt. |
---|
| 54 | * |
---|
[9098] | 55 | */ |
---|
| 56 | |
---|
[9112] | 57 | #include "TowerDefense.h" |
---|
[9137] | 58 | #include "Tower.h" |
---|
| 59 | #include "TowerDefenseCenterpoint.h" |
---|
| 60 | |
---|
[9122] | 61 | #include "worldentities/SpawnPoint.h" |
---|
| 62 | #include "worldentities/pawns/Pawn.h" |
---|
[9129] | 63 | #include "worldentities/pawns/SpaceShip.h" |
---|
[9098] | 64 | |
---|
[9138] | 65 | #include "chat/ChatManager.h" |
---|
| 66 | |
---|
[9136] | 67 | /* Part of a temporary hack to allow the player to add towers */ |
---|
| 68 | #include "core/command/ConsoleCommand.h" |
---|
| 69 | |
---|
[9112] | 70 | namespace orxonox |
---|
| 71 | { |
---|
| 72 | CreateUnloadableFactory(TowerDefense); |
---|
[9136] | 73 | |
---|
| 74 | TowerDefense::TowerDefense(BaseObject* creator) : Deathmatch(creator) |
---|
[9112] | 75 | { |
---|
| 76 | RegisterObject(TowerDefense); |
---|
[9136] | 77 | |
---|
| 78 | /* Temporary hack to allow the player to add towers */ |
---|
| 79 | this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) ); |
---|
| 80 | |
---|
[9112] | 81 | } |
---|
[9136] | 82 | |
---|
| 83 | TowerDefense::~TowerDefense() |
---|
| 84 | { |
---|
| 85 | if (this->isInitialized()) |
---|
| 86 | { |
---|
| 87 | if( this->dedicatedAddTower_ ) |
---|
| 88 | delete this->dedicatedAddTower_; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | void TowerDefense::setCenterpoint(TowerDefenseCenterpoint *centerpoint) |
---|
| 93 | { |
---|
| 94 | orxout() << "got a centerpoint..." << endl; |
---|
| 95 | |
---|
| 96 | this->center_ = centerpoint; |
---|
| 97 | } |
---|
| 98 | |
---|
[9112] | 99 | void TowerDefense::start() |
---|
| 100 | { |
---|
| 101 | Deathmatch::start(); |
---|
[9138] | 102 | |
---|
| 103 | orxout()<< "Adding towers for debug..." <<endl; |
---|
| 104 | |
---|
| 105 | addTower(0,15); |
---|
| 106 | addTower(15,0); |
---|
| 107 | |
---|
| 108 | for (int i = 0 ; i <= 15; i++) |
---|
| 109 | { |
---|
| 110 | addTower(i,i); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | orxout()<< "Done" <<endl; |
---|
| 114 | |
---|
| 115 | ChatManager::message("Use the console command addTower x y to add towers"); |
---|
[9112] | 116 | } |
---|
[9136] | 117 | |
---|
| 118 | /* |
---|
| 119 | void TowerDefense::end() |
---|
| 120 | { |
---|
| 121 | Deathmatch::end(); |
---|
| 122 | |
---|
| 123 | std::string message("The match has ended."); |
---|
| 124 | ChatManager::message(message); |
---|
| 125 | } |
---|
| 126 | */ |
---|
| 127 | |
---|
| 128 | void TowerDefense::addTower(int x, int y) |
---|
| 129 | { |
---|
[9138] | 130 | if (x > 15 || y > 15 || x < 0 || y < 0) |
---|
[9136] | 131 | { |
---|
[9138] | 132 | orxout() << "Can not add Tower: x and y should be between 0 and 15" << endl; |
---|
[9136] | 133 | return; |
---|
| 134 | } |
---|
| 135 | |
---|
[9138] | 136 | orxout()<< "Will add tower at (" << x << "," << y << ")" << endl; |
---|
[9136] | 137 | |
---|
[9137] | 138 | Tower* newTower = new Tower(this->center_); |
---|
| 139 | newTower->addTemplate(this->center_->getTowerTemplate()); |
---|
[9136] | 140 | |
---|
[9137] | 141 | this->center_->attach(newTower); |
---|
| 142 | |
---|
[9138] | 143 | newTower->setPosition(x-8,y-8,0); |
---|
[9137] | 144 | newTower->setGame(this); |
---|
| 145 | |
---|
[9136] | 146 | // TODO: create Tower mesh |
---|
| 147 | // TODO: load Tower mesh |
---|
| 148 | } |
---|
| 149 | |
---|
[9123] | 150 | void TowerDefense::tick(float dt) |
---|
| 151 | { |
---|
| 152 | SUPER(TowerDefense, tick, dt); |
---|
[9136] | 153 | |
---|
[9123] | 154 | static bool test = false; |
---|
| 155 | if (!test) |
---|
[9129] | 156 | { |
---|
[9123] | 157 | orxout()<< "First tick." <<endl; |
---|
[9116] | 158 | } |
---|
[9123] | 159 | test = true; |
---|
| 160 | } |
---|
[9136] | 161 | |
---|
| 162 | /* |
---|
| 163 | void TowerDefense::playerEntered(PlayerInfo* player) |
---|
| 164 | { |
---|
| 165 | Deathmatch::playerEntered(player); |
---|
| 166 | |
---|
| 167 | const std::string& message = player->getName() + " entered the game"; |
---|
| 168 | ChatManager::message(message); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | bool TowerDefense::playerLeft(PlayerInfo* player) |
---|
| 172 | { |
---|
| 173 | bool valid_player = Deathmatch::playerLeft(player); |
---|
| 174 | |
---|
| 175 | if (valid_player) |
---|
| 176 | { |
---|
| 177 | const std::string& message = player->getName() + " left the game"; |
---|
| 178 | ChatManager::message(message); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | return valid_player; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | void TowerDefense::pawnKilled(Pawn* victim, Pawn* killer) |
---|
| 186 | { |
---|
| 187 | if (victim && victim->getPlayer()) |
---|
| 188 | { |
---|
| 189 | std::string message; |
---|
| 190 | if (killer) |
---|
| 191 | { |
---|
| 192 | if (killer->getPlayer()) |
---|
| 193 | message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName(); |
---|
| 194 | else |
---|
| 195 | message = victim->getPlayer()->getName() + " was killed"; |
---|
| 196 | } |
---|
| 197 | else |
---|
| 198 | message = victim->getPlayer()->getName() + " died"; |
---|
| 199 | |
---|
| 200 | ChatManager::message(message); |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | Deathmatch::pawnKilled(victim, killer); |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | void TowerDefense::playerScored(PlayerInfo* player) |
---|
| 207 | { |
---|
| 208 | Gametype::playerScored(player); |
---|
| 209 | |
---|
| 210 | }*/ |
---|
[9098] | 211 | } |
---|