Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/TixyTaxyTorxy_HS18/src/modules/TixyTaxyTorxy/TixyTaxyTorxyField.cc @ 12086

Last change on this file since 12086 was 12086, checked in by sastocke, 5 years ago

switching towers

File size: 9.9 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 */
28
29/**
30    @file TixyTaxyTorxy
31TixyTaxyTorxyField.cc
32    @brief Implementation of the TixyTaxyTorxy
33TixyTaxyTorxyField class.
34*/
35
36#include "TixyTaxyTorxyField.h"
37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
39#include "TixyTaxyTorxy.h"
40
41namespace orxonox
42{
43    RegisterClass(TixyTaxyTorxyField);
44    int counter=0;
45    /**
46    @brief
47        Constructor. Registers and initializes the object and checks whether the gametype is actually TixyTaxyTorxy
48TixyTaxyTorxy.
49    */
50TixyTaxyTorxyField::TixyTaxyTorxyField(Context* context) : MovableEntity(context)
51    {
52        RegisterObject(TixyTaxyTorxyField);
53
54        tower_ = nullptr;
55        type_ = TixyTaxyTorxyFieldType::FREE;
56        center_ = nullptr;
57        upgrade_ = 0;
58        setPosition(0,0,0);                           
59        modelGround_ = new Model(getContext());
60        modelGround_->setScale(25);
61        modelGround_->pitch(Degree(90));
62        attach(modelGround_);
63        modelObject_ = new Model(getContext());
64        modelObject_->setScale(25);
65        modelObject_->pitch(Degree(90));
66        attach(modelObject_);
67        setAngle(0);
68    }
69
70    /**
71    @brief
72        Method to create a TixyTaxyTorxy
73TixyTaxyTorxyField through XML.
74    */
75    void TixyTaxyTorxyField::XMLPort(Element& xmlelement, XMLPort::Mode mode)
76    {
77        SUPER(TixyTaxyTorxyField, XMLPort, xmlelement, mode);
78
79        //XMLPortParam(TixyTaxyTorxyField, "width", setWidth, getWidth, xmlelement, mode);
80
81    }
82
83    void TixyTaxyTorxyField::setCenterpoint(TixyTaxyTorxyCenterpoint* center)
84    {
85        center_ = center;
86    }
87
88    // void TixyTaxyTorxyField::upgrade()
89    // {
90    //     if (canUpgrade() == true)
91    //     {
92    //         destroyTower();
93    //         createTower(getUpgrade() + 1);
94    //     }
95    // }
96
97    // int TixyTaxyTorxyField::getUpgrade()
98    // {
99    //     return upgrade_;
100    // }
101
102    // TixyTaxyTorxyFieldType TixyTaxyTorxyField::getType()
103    // {
104    //     return type_;
105    // }
106
107    void TixyTaxyTorxyField::setUpgrade(int upgrade)
108    {
109       //  upgrade_= counter%2;
110       // if (upgrade < 0)
111       //  {
112       //      upgrade_ = 0;
113       //  }   
114       //  else if (upgrade > 5)
115       //  {
116       //      upgrade = 5;
117       //  }
118       //  else
119       //  {
120       //      upgrade_ = upgrade;
121        }
122
123                                 
124    // }
125
126    // bool TixyTaxyTorxyField::canUpgrade()
127    // {
128    //     if (tower_ != nullptr && upgrade_ < 5)
129    //     {
130    //         return true;
131    //     }
132
133    //     return false;
134    // }
135
136    void TixyTaxyTorxyField::setAngle(int newAngle)
137    {
138        if (modelGround_ != nullptr)
139        {
140            switch (newAngle)
141            {
142            case 0:
143                modelGround_->yaw(Degree(0));
144                angle_ = 0;
145                break;
146            case 1:
147                modelGround_->yaw(Degree(90));
148                angle_ = 1;
149                break;   
150            case 2:
151                modelGround_->yaw(Degree(180));
152                angle_ = 2;
153                break;   
154            case 3:
155                modelGround_->yaw(Degree(270));
156                angle_ = 3;
157                break;                                           
158            }
159        }
160
161        if (modelObject_ != nullptr)
162        {
163            switch (newAngle)
164            {
165            case 0:
166                modelObject_->yaw(Degree(0));
167                angle_ = 0;
168                break;
169            case 1:
170                modelObject_->yaw(Degree(90));
171                angle_ = 1;
172                break;   
173            case 2:
174                modelObject_->yaw(Degree(180));
175                angle_ = 2;
176                break;   
177            case 3:
178                modelObject_->yaw(Degree(270));
179                angle_ = 3;
180                break;                                           
181            }
182        }
183       
184    }
185
186    int TixyTaxyTorxyField::getAngle()
187    {
188        return angle_;
189    }
190
191    void TixyTaxyTorxyField::createFree(int orientation)
192    {           
193        modelGround_->setMeshSource("TD_F1.mesh");
194        tower_ = nullptr;
195        type_ = TixyTaxyTorxyFieldType::FREE;
196        setUpgrade(0);
197        setAngle(orientation);
198    }
199
200    void TixyTaxyTorxyField::createStart(int orientation)
201    {     
202        modelGround_->setMeshSource("TD_S5.mesh");
203        tower_ = nullptr;
204        type_ = TixyTaxyTorxyFieldType::START;
205        setUpgrade(0);
206        setAngle(orientation);   
207    }
208
209
210    void TixyTaxyTorxyField::createEnd(int orientation)
211    {     
212        modelGround_->setMeshSource("TD_S4.mesh");
213        tower_ = nullptr;
214        type_ = TixyTaxyTorxyFieldType::END;
215        setUpgrade(0);
216        setAngle(orientation);
217    }   
218
219    void TixyTaxyTorxyField::createStraight(int orientation)
220    {     
221        modelGround_->setMeshSource("TD_S1.mesh");
222        tower_ = nullptr;
223        type_ = TixyTaxyTorxyFieldType::STREET;
224        setUpgrade(0);
225        setAngle(orientation);
226    } 
227
228    void TixyTaxyTorxyField::createRCurve(int orientation)
229    {     
230        modelGround_->setMeshSource("TD_S2.mesh");
231        tower_ = nullptr;
232        type_ = TixyTaxyTorxyFieldType::STREET;
233        setUpgrade(0);
234        setAngle(orientation);
235    } 
236
237    void TixyTaxyTorxyField::createLCurve(int orientation)
238    {   
239        modelGround_->setMeshSource("TD_S3.mesh");
240        tower_ = nullptr;
241        type_ = TixyTaxyTorxyFieldType::STREET;
242        setUpgrade(0);
243        setAngle(orientation);
244    } 
245
246    void TixyTaxyTorxyField::createObstacle(int orientation)
247    {   
248        modelGround_->setMeshSource("TD_F1.mesh");
249        modelObject_->setMeshSource("TD_O1.mesh");
250        tower_ = nullptr;
251        type_ = TixyTaxyTorxyFieldType::OBSTACLE;
252        setUpgrade(0);
253        setAngle(orientation);
254    }
255
256    void TixyTaxyTorxyField::createTower(int upgrade)
257    {       
258        counter++;
259        if (tower_ == nullptr)
260        {
261            if(counter%2==0){
262            modelGround_->setMeshSource("TD_T1.mesh");
263            tower_ = new TixyTaxyTorxyTower(center_->getContext());
264            attach(tower_);
265
266            }else{
267            modelGround_->setMeshSource("TD_T2.mesh");
268            tower_ = new TixyTaxyTorxyTower(center_->getContext());
269            attach(tower_);
270        }
271
272
273            // type_ = TixyTaxyTorxyFieldType::TOWER;
274            // setUpgrade(upgrade);
275            // if (upgrade_ > 0 && modelObject_ != nullptr)
276            // {
277            //     modelObject_->setMeshSource("TD_T2.mesh");                   
278            //     tower_->addTemplate(center_->getTower1Template());
279            //     switch (counter%2 +1)
280            //     {
281            //         case 1:
282            //             modelObject_->setMeshSource("TD_T1.mesh");                   
283            //             tower_->addTemplate(center_->getTower1Template());
284            //             break;
285            //         case 2:
286            //             modelObject_->setMeshSource("TD_T2.mesh");
287            //             tower_->addTemplate(center_->getTower2Template());
288            //             break;
289            //         case 3:
290            //             modelObject_->setMeshSource("TD_T3.mesh");
291            //             tower_->addTemplate(center_->getTower3Template());
292            //             break;
293            //         case 4:
294            //             modelObject_->setMeshSource("TD_T4.mesh");
295            //             tower_->addTemplate(center_->getTower4Template());
296            //             break;
297            //         case 5:
298            //             modelObject_->setMeshSource("TD_T5.mesh");
299            //             tower_->addTemplate(center_->getTower5Template());
300            //             break;
301            //     }
302            // }
303        }                           
304    }
305
306    void TixyTaxyTorxyField::destroyTower()
307    {
308        if (tower_ != nullptr)
309        {
310            tower_->destroy();
311            tower_ = nullptr;
312        }
313    }
314
315    void TixyTaxyTorxyField::create(char object, char param)
316    {
317        int paramInt = atoi(&param);
318        switch (object)
319        {
320            case 'F':
321                createFree(paramInt);
322                break;
323            case 'I':               
324                createStraight(paramInt);
325                break;
326            case 'R':               
327                createRCurve(paramInt);
328                break; 
329            case 'L':               
330                createLCurve(paramInt);
331                break;
332            case 'X':               
333                createStart(paramInt);
334                break;     
335            case 'O':               
336                createEnd(paramInt);
337                break;
338            case 'Y':               
339                createObstacle(paramInt);
340                break;                 
341            case 'T':                               
342                createTower(paramInt);               
343                break;                                                                                                         
344        }
345    }
346}
Note: See TracBrowser for help on using the repository browser.