Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.cc @ 9138

Last change on this file since 9138 was 9138, checked in by mentzerf, 12 years ago

Fixed the oxw file (some more):

  • the playfield now lies in the x,y layer, the camera is at z = 20, as it should be
  • the towers are now longer to be able to see if they fit the playfield marks (they do!)
  • moved the playfield, so that towers x,y can easily be mapped to the playfield coordinates. e.g. adding a tower at 0,4 results in -8,-4, the corners of the playfield are at 8,8 / -8,-8 / -8,8 / 8,-8
  • the centerpoint is marked with a cylinder
File size: 5.8 KB
Line 
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 * 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 *
55 */
56
57#include "TowerDefense.h"
58#include "Tower.h"
59#include "TowerDefenseCenterpoint.h"
60
61#include "worldentities/SpawnPoint.h"
62#include "worldentities/pawns/Pawn.h"
63#include "worldentities/pawns/SpaceShip.h"
64
65#include "chat/ChatManager.h"
66
67/* Part of a temporary hack to allow the player to add towers */
68#include "core/command/ConsoleCommand.h"
69
70namespace orxonox
71{
72    CreateUnloadableFactory(TowerDefense);
73       
74        TowerDefense::TowerDefense(BaseObject* creator) : Deathmatch(creator)
75    {
76        RegisterObject(TowerDefense);
77               
78                /* Temporary hack to allow the player to add towers */
79                this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) );
80               
81    }
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       
99    void TowerDefense::start()
100    {
101        Deathmatch::start();
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");
116    }
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        {
130                if (x > 15 || y > 15 || x < 0 || y < 0)
131                {
132                        orxout() << "Can not add Tower: x and y should be between 0 and 15" << endl;
133                        return;
134                }
135               
136                orxout()<< "Will add tower at (" << x << "," << y << ")" << endl;
137               
138                Tower* newTower = new Tower(this->center_);
139                newTower->addTemplate(this->center_->getTowerTemplate());
140               
141                this->center_->attach(newTower);
142               
143                newTower->setPosition(x-8,y-8,0);
144                newTower->setGame(this);
145               
146                // TODO: create Tower mesh
147                // TODO: load Tower mesh
148        }
149       
150        void TowerDefense::tick(float dt)
151    {
152        SUPER(TowerDefense, tick, dt);
153               
154        static bool test = false;
155        if (!test)
156        {
157                        orxout()<< "First tick." <<endl;
158        }
159        test = true;
160    }
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         }*/
211}
Note: See TracBrowser for help on using the repository browser.