Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12149 was 12149, checked in by thomkell, 5 years ago

final

File size: 12.4 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 *
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
68TixyTaxyTorxy 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#include <iostream>
86#include "TixyTaxyTorxyField.h"
87using namespace std;
88
89namespace orxonox
90{
91
92    RegisterUnloadableClass(TixyTaxyTorxy);
93
94
95
96   
97TixyTaxyTorxy::TixyTaxyTorxy(Context* context) : TeamDeathmatch(context)
98    {
99        RegisterObject(TixyTaxyTorxy);
100
101        selecter = nullptr;
102        this->player_ = nullptr;
103        this->setHUDTemplate("TixyTaxyTorxyHUD");
104        this->waveNumber_ = 0;
105        this->timeSinceLastSpawn_ = 0.0;
106        this->timeUntilNextWave_ = 0.0;
107        this->credit_ = 0;
108        this->lifes_ = 0;
109        this->waveSize_ = 0;
110        offset_ = Vector3(0,0,10);
111
112    }
113
114TixyTaxyTorxy::~TixyTaxyTorxy()
115    {
116
117
118        if (this->isInitialized())
119        {
120
121        }
122    }
123
124    void TixyTaxyTorxy::setCenterpoint(TixyTaxyTorxyCenterpoint *centerpoint)
125    {
126        this->center_ = centerpoint;
127    }
128
129    void TixyTaxyTorxy::start()
130    {       
131        if (center_ != nullptr) // There needs to be a TixyTaxyTorxyCenterpoint, i.e. the area the game takes place.
132        {
133            if (selecter == nullptr)
134            {
135                selecter = new TixyTaxyTorxySelecter(this->center_->getContext());               
136            }
137            selecter->addTemplate(center_->getSelecterTemplate());
138            center_->attach(selecter);
139        }
140        else // If no centerpoint was specified, an error is thrown and the level is exited.
141        {
142            orxout(internal_error) << "Jump: No Centerpoint specified." << endl;
143            return;
144        }
145
146        createFields();
147        TeamDeathmatch::start();
148
149        //set initial credits, lifes and WaveNumber
150        this->setCredit(1000);
151        this->setLifes(100);       
152        this->timeSinceLastSpawn_ = 0.0;
153        this->timeUntilNextWave_ = 5.0;
154        this->waveSize_ = 0;
155        this->setWaveNumber(0);
156    }
157
158   
159    void TixyTaxyTorxy::end()
160    {
161        if (Highscore::exists())
162        {
163            int score = this->getWaveNumber();
164            Highscore::getInstance().storeScore("Tower Defense", score, this->getPlayer());
165        }
166        TeamDeathmatch::end();
167        ChatManager::message("Match is over! Gameover!");
168
169    }
170
171    void TixyTaxyTorxy::spawnPlayer(PlayerInfo* player)
172    {
173        assert(player);
174        player_ = player;
175
176        if (selecter->getPlayer() == nullptr)
177        {
178            player_->startControl(selecter);
179            players_[player].state_ = PlayerState::Alive;
180        } 
181    }
182
183    /**
184    @brief
185        Get the player.
186    @return
187        Returns a pointer to the player. If there is no player, nullptr is returned.
188    */
189    PlayerInfo* TixyTaxyTorxy::getPlayer(void) const
190    {
191        return this->player_;
192    }
193
194    //not working yet
195    void TixyTaxyTorxy::addTower(int x,int y)
196    {
197        int mini;
198         
199        TixyTaxyTorxyCoordinate* coord = new TixyTaxyTorxyCoordinate(x,y);
200        x = coord->GetX();
201        y = coord->GetY();
202        mini = coord->Getmini();
203
204        orxout() <<"addTower("<<x<<", "<<y<<") "<<mini<<"" <<endl;
205        int cost = center_->getTowerCost(1);
206
207        if (fields_[x][y]->isFree())
208        {
209            payCredit(cost);
210            fields_[x][y]->createTower(1);
211        }
212   
213    bool player1=player2=0;
214    int A1,B1,C1,D1,E1,F1,G1,H1,I1;
215    int A2,B2,C2,D2,E2,F2,G2,H2,I2;
216    A1=B1=C1=D1=E1=F1=G1=H1=I1=0;
217    A2=B2=C2=D2=E2=F2=G2=H2=I2=0;
218
219
220
221    if (checkMinigame(0,10) == 1) A1=1;
222    if (checkMinigame(4,10) == 1) B1=2;
223    if (checkMinigame(8,10) == 1) C1=4;
224    if (checkMinigame(0,6) == 1) D1=8;
225    if (checkMinigame(4,6) == 1) E1=16;
226    if (checkMinigame(8,6) == 1) F1=32;
227    if (checkMinigame(0,2) == 1) G1=64;
228    if (checkMinigame(4,2) == 1) H1=128;
229    if (checkMinigame(8,2) == 1) I1=256;
230
231    if (checkMinigame(0,10) == 2) A2=1;
232    if (checkMinigame(4,10) == 2) B2=2;
233    if (checkMinigame(8,10) == 2) C2=4;
234    if (checkMinigame(0,6) == 2) D2=8;
235    if (checkMinigame(4,6) == 2) E2=16;
236    if (checkMinigame(8,6) == 2) F2=32;
237    if (checkMinigame(0,2) == 2) G2=64;
238    if (checkMinigame(4,2) == 2) H2=128;
239    if (checkMinigame(8,2) == 2) I2=256;
240
241    orxout()<<"A1: "<<A1<<"B1: "<<B1<<endl;
242
243    if(A1+B1+C1 == 7 || D1+E1+F1 == 56 || G1+H1+I1 == 448 || A1+D1+G1 == 73 || B1+E1+H1 == 146 || C1+F1+I1 == 294 || A1+E1+I1 == 273 || C1+E1+G1 == 84){
244
245        player1=1;
246        orxout()<<"player1 has won" << endl;
247    }
248
249     if(A2+B2+C2 == 7 || D2+E2+F2 == 56 || G2+H2+I2 == 448 || A2+D2+G2 == 73 || B2+E2+H2 == 146 || C2+F2+I2 == 294 || A2+E2+I2 == 273 || C2+E2+G2 == 84){
250
251        player2=1;
252        orxout()<<"player1 has won" << endl;
253    }
254    }
255
256    int TixyTaxyTorxy::checkMinigame(int x, int y){
257        if (checkRow(x,y)==1 || checkColumn(x,y)==1 || checkDiagLtR(x,y)==1 ||checkDiagRtL(x,y)==1) return 1;
258        else if (checkRow(x,y)==2 || checkColumn(x,y)==2 || checkDiagLtR(x,y)==2 || checkDiagRtL (x,y)==2) return 2;
259        return 0;
260         } 
261
262    int TixyTaxyTorxy::checkRow(int x, int y){
263        for(int i=0; i<2; i++){
264
265            if(fields_[x+i][y]-> isTower1() && fields_[x+i][y-1]-> isTower1() && fields_[x+i][y-2]-> isTower1()){
266                return 1;
267
268            }else if(fields_[x+i][y]-> isTower2() && fields_[x+i][y-1]-> isTower2() && fields_[x+i][y-2]-> isTower2()){
269                return 2;}   
270        }
271        return 0;
272
273    }
274    int TixyTaxyTorxy::checkColumn(int x, int y){
275        for(int i=0; i<2; i++){
276
277            if(fields_[x][y-i]-> isTower1() && fields_[x+1][y-i]-> isTower1() && fields_[x+2][y-i]-> isTower1()){
278                return 1;
279
280            }else if (fields_[x][y-i]-> isTower2() && fields_[x+1][y-i]-> isTower2() && fields_[x+2][y-i]-> isTower2()){
281            return 2;            }
282        }
283            return 0;
284       
285       
286    }
287    //Cheeck the diagonal achsis from top left to bottom right
288    int TixyTaxyTorxy::checkDiagLtR(int x, int y){
289
290        if (fields_[x][y]-> isTower1() && fields_[x+1][y-1]-> isTower1() && fields_[x+2][y-2]-> isTower1()){
291            return 1;
292        }
293        else if (fields_[x][y]-> isTower2() && fields_[x+1][y-1]-> isTower2() && fields_[x+2][y-2]-> isTower2()){
294            return 2;
295        }
296        return 0;
297       
298    }
299    //Cheeck the diagonal achsis from top right to bottom left
300    int TixyTaxyTorxy::checkDiagRtL (int x, int y){
301
302        if(fields_[x+2][y]-> isTower1() && fields_[x+1][y-1]-> isTower1() && fields_[x][y-2]-> isTower1()){
303            return 1;
304        }
305        else if(fields_[x+2][y]-> isTower2() && fields_[x+1][y-1]-> isTower2() && fields_[x][y-2]-> isTower2()){
306            return 2;
307        }
308       
309        else return 0;
310        }
311
312    bool TixyTaxyTorxy::getPlayer1Value(){
313    return player1;
314}
315    bool TixyTaxyTorxy::getPlayer2Value(){
316    return player2;
317}
318   
319
320
321
322
323
324
325    /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret")
326    so towers have ability if the turrets
327    */
328
329    void TixyTaxyTorxy::upgradeTower(int x, int y)
330    {   
331        // TixyTaxyTorxyCoordinate* coord = new TixyTaxyTorxyCoordinate(x,y);
332        // x = coord->GetX();
333        // y = coord->GetY();     
334
335        // int cost = 100;
336
337        // if (fields_[x][y]->isFree() == false && fields_[x][y]->canUpgrade() == true && getCredit() >= cost)
338        // {
339        //     payCredit(cost);
340        //     fields_[x][y]->upgrade();
341        // }
342    }   
343
344    void TixyTaxyTorxy::tick(float dt)
345    {
346        SUPER(TixyTaxyTorxy, tick, dt);
347
348        if (hasStarted() == false || player_ == nullptr)
349        {
350            return;
351        }
352        timeUntilNextWave_ -= dt;
353        timeSinceLastSpawn_ += dt;
354
355        //build/upgrade tower at selecter position
356        if (selecter != nullptr && selecter->buildTower_ == true)
357        {
358            selecter->buildTower_ = false;
359
360            // if (getField(selecter->selectedPos_)->canUpgrade() == true)
361            // {
362            //     upgradeTower(selecter->selectedPos_->GetX(), selecter->selectedPos_->GetY());
363            // }
364           
365            addTower(selecter->selectedPos_->GetX(), selecter->selectedPos_->GetY());
366                   
367        }
368       
369
370    }
371
372    void TixyTaxyTorxy::createFields()
373    {
374        assert(center_);
375        TixyTaxyTorxyCoordinate coord(0,0);
376        TixyTaxyTorxyCoordinate startCoord(0,0);
377        std::string fields = center_->getFields();
378        int pos = 0;
379        for (int j = 10; j >= 0; --j)
380        {
381            for (int i = 0; i < 11; ++i)
382            {
383                coord.Set(i,j);
384                fields_[i][j] = new TixyTaxyTorxyField(center_->getContext());
385                fields_[i][j]->setCenterpoint(center_);
386                center_->attach(fields_[i][j]);
387                fields_[i][j]->setPosition(coord.get3dcoordinate()); 
388                fields_[i][j]->create(fields.at(pos), fields.at(pos+1));
389                pos += 2;
390               
391            }
392        }
393    }
394   
395}
Note: See TracBrowser for help on using the repository browser.