Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/OrxoKart_HS18/src/modules/orxokart/OrxoKart.cc @ 12111

Last change on this file since 12111 was 12111, checked in by ottka, 5 years ago

stop timer after round

File size: 6.7 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 *      Manuel Meier
24 *   Co-authors:
25 *      Cyrill Burgener
26 *
27 */
28
29/**
30    @file OrxoKart.cc
31    @brief Implementation of the OrxoKart class. Sets up the whole Minigame
32*/
33
34#include "OrxoKart.h"
35#include "OrxoKartFlag.h"
36#include "OrxoKartKart.h"
37#include "OrxoKartOrigin.h"
38#include "OrxoKartTile.h"
39#include "core/CoreIncludes.h"
40
41namespace orxonox
42{
43    RegisterUnloadableClass(OrxoKart);
44
45    OrxoKart::OrxoKart(Context* context) : Gametype(context)
46    {
47        RegisterObject(OrxoKart);
48
49        this->origin_ = nullptr;
50        this->numberOfFlags_ = 1;
51        this->firstTick_ = true;
52
53        this->setHUDTemplate("OrxoKartHUD");
54    }
55
56    void OrxoKart::tick(float dt)
57    { 
58        SUPER(OrxoKart, tick, dt);
59
60        if(this->firstTick_ && this->origin_)
61        {
62            this->firstTick_ = false;
63            this->wayPoints = std::vector<OrxoKartTile*>(3, nullptr);
64
65            int n = this->origin_->getNumCells();
66            int s = this->origin_->getCellSize();
67            int map_1[] =   {1,1,1,1,1,1,1,1,0,0,0
68                            ,1,0,0,0,0,0,0,1,1,1,0
69                            ,1,0,1,1,1,1,0,0,0,1,1
70                            ,1,1,1,0,0,1,1,0,0,0,1
71                            ,0,0,0,0,0,0,1,0,1,1,1
72                            ,1,1,1,1,1,1,1,0,1,0,0
73                            ,1,0,0,0,0,0,0,0,1,0,0
74                            ,1,0,0,0,0,0,0,0,1,0,0
75                            ,1,1,1,1,1,0,0,0,1,1,1
76                            ,0,0,0,0,1,0,0,0,0,0,1
77                            ,0,0,0,0,1,1,1,2,1,1,1};
78
79            int map_2[] =  {1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
80                            1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,
81                            1,0,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,
82                            1,0,1,0,0,0,0,0,0,0,1,0,1,0,1,1,1,1,1,1,1,1,1,0,0,
83                            1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,0,
84                            1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,0,
85                            1,0,1,0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,
86                            1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,0,1,0,0,
87                            1,0,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,0,
88                            1,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0,0,
89                            1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,
90                            0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,
91                            0,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,1,
92                            0,1,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,0,0,0,0,1,
93                            0,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,1,
94                            0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,1,
95                            0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,
96                            0,1,0,1,1,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,
97                            0,1,0,1,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,
98                            0,1,0,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,
99                            0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
100                            0,1,0,1,0,1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,
101                            0,1,1,1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,
102                            0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,1,1,1,0,1,
103                            0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,2,1,1,1,0,1,1,1};
104
105
106
107            int *levelcodeArray =  map_1;
108
109            // int z = 0;
110            //Generate floor according to levelcode
111            for(int i=0; i<n; i++){
112                for(int j=0; j<n; j++){
113                    if (int type = levelcodeArray[i*n + j]) {
114                        OrxoKartTile* tile = new OrxoKartTile(origin_->getContext());
115                        tile->init((n-1-i)*s, j*s, s, type);
116                        // tiles.push_back(tile);
117                        //++z;
118                        if ( i == 10 && j == 4 )
119                            wayPoints.at(0) = tile;
120
121                        if ( i == 0 && j == 0) 
122                            wayPoints.at(1) = tile;
123                        if ( i == 10 && j == 7)
124                            wayPoints.at(2) = tile;
125                    }
126                }   
127            }
128            //bottom flag
129           
130            OrxoKartFlag* flag = new OrxoKartFlag(origin_->getContext());
131            flag->init(n, s);
132            flag_ = flag;
133           
134
135
136           
137
138        } //firsttick end
139        /*
140        for (std::vector<OrxoKartTile*>::iterator it = tiles.begin(); it != tiles.end(); ++it ) {
141            if ((*it)->getCollided())
142                tiles.erase(it);
143        }
144        if (tiles.empty())
145            numberOfFlags_ = 0;
146        */
147        if (wayPointCounter >= 3)
148            numberOfFlags_ = 0;
149        else if (wayPointCounter < 3 && wayPointCounter >= 0 && wayPoints.at(wayPointCounter) != nullptr) {
150            if (wayPoints.at(wayPointCounter)->getCollided()) {
151                for (int i = 0; i < 3; ++i) {
152                    wayPoints.at(i)->setCollided(false);
153                }
154                ++wayPointCounter;
155            }
156        }
157        else {
158            orxout() << " Should not happen, look in OrxoKart.cc";
159        }
160
161
162
163
164
165        // Check if ship collided with the flag
166        if(flag_->getCollided()){
167            OrxoKartKart* player = flag_->getObjectofCollision();
168            player->setPosition(Vector3(80*0, 20, 80*8));
169            player->setOrientation(Quaternion(1, 0, 0, 0));   // 0, 0, 0
170            player->setVelocity(Vector3(0,0,0));
171            player->setAcceleration(Vector3(0,0,0));
172            flag_->setCollided(false); 
173            wayPointCounter = 0;
174
175
176            // flag_->destroyLater();
177           // flags_.erase (flags_.begin()+i);
178            //numberOfFlags_ = 0;
179        }
180       
181    }
182}
Note: See TracBrowser for help on using the repository browser.