Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12155 was 12155, checked in by emustafa, 5 years ago

fixed speed

File size: 7.3 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->raceFinished = false;
51        this->firstTick_ = true;
52        this->numberOfShrooms = 3;
53
54        this->setHUDTemplate("OrxoKartHUD");
55    }
56
57    void OrxoKart::tick(float dt)
58    { 
59        SUPER(OrxoKart, tick, dt);
60
61        if(this->firstTick_ && this->origin_)
62        {
63            this->firstTick_ = false;
64            this->wayPoints = std::vector<OrxoKartTile*>(3, nullptr);
65
66            this->n = this->origin_->getNumCells();
67            this->s = this->origin_->getCellSize();
68            this->level = this->origin_->getLevel();
69            int map_1[] =   {1,1,1,1,1,1,1,1,0,0,0
70                            ,1,0,0,0,0,0,0,1,1,1,0
71                            ,1,0,1,1,1,1,0,0,0,1,1
72                            ,1,1,1,0,0,1,1,0,0,0,1
73                            ,0,0,0,0,0,0,1,0,1,1,1
74                            ,1,1,1,1,1,1,1,0,1,0,0
75                            ,1,0,0,0,0,0,0,0,1,0,0
76                            ,1,0,0,0,0,0,0,0,1,0,0
77                            ,1,1,1,1,1,0,0,0,1,1,1
78                            ,0,0,0,0,1,0,0,0,0,0,1
79                            ,0,0,0,0,1,1,1,2,1,1,1};
80
81            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,
82                            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,
83                            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,
84                            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,
85                            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,
86                            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,
87                            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,
88                            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,
89                            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,
90                            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,
91                            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,
92                            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,
93                            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,
94                            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,
95                            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,
96                            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,
97                            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,
98                            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,
99                            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,
100                            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,
101                            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,
102                            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,
103                            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,
104                            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,
105                            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};
106
107
108
109            int *levelcodeArray =  level==1 ? map_1 : map_2;
110
111
112
113            //OrxoKartTile* tile = new OrxoKartTile(origin_->getContext());
114            //tile->init(0*s, 4*s, s, 20, 2);
115
116
117            // int z = 0;
118            //Generate floor according to levelcode
119            for(int i=0; i<n; i++){
120                for(int j=0; j<n; j++){
121                    if (int type = levelcodeArray[i*n + j]) {
122                        OrxoKartTile* tile = new OrxoKartTile(origin_->getContext());
123                        tile->init((n-1-i)*s, j*s, s, 0, type);
124                        // tiles.push_back(tile);
125                        //++z;
126                        if (level == 1) {
127                            //map 1
128                            if ( i == 9 && j == 4 )
129                                wayPoints.at(0) = tile;
130
131                            if ( i == 0 && j == 1) 
132                                wayPoints.at(1) = tile;
133                            if ( i == 10 && j == 7)
134                                wayPoints.at(2) = tile;
135                        }
136                        else if (level == 2) {
137                            //map 2
138                            if ( i == 23 && j == 11 )
139                                wayPoints.at(0) = tile;
140
141                            if ( i == 0 && j == 1) 
142                                wayPoints.at(1) = tile;
143                            if ( i == 24 && j == 17)
144                                wayPoints.at(2) = tile;
145                        }   
146                    }
147                }   
148            }
149            //bottom flag
150           
151            OrxoKartFlag* flag = new OrxoKartFlag(origin_->getContext());
152            flag->init(n, s);
153            flag_ = flag;
154           
155
156
157           
158
159        } //firsttick end
160       
161        if (wayPointCounter >= 3)
162            raceFinished = true;
163
164        else if (wayPointCounter < 3 && wayPointCounter >= 0 && wayPoints.at(wayPointCounter) != nullptr) {
165            if (wayPoints.at(wayPointCounter)->getCollided()) {
166                for (int i = 0; i < 3; ++i) {
167                    wayPoints.at(i)->setCollided(false);
168                }
169                ++wayPointCounter;
170            }
171        }
172        else {
173            orxout() << " Should not happen, look in OrxoKart.cc";
174        }
175
176
177
178
179
180        // Check if ship collided with the flag
181        if(flag_->getCollided()){
182            player = flag_->getObjectofCollision();
183            if (level == 1)
184                player->setPosition(Vector3(s*0, 20, s*8.5));
185            if (level == 2)
186                player->setPosition(Vector3(s*0, 20, s*18.5));
187            player->setOrientation(Quaternion(1, 0, 0, 0));   // 0, 0, 0
188            player->setVelocity(Vector3(0,0,0));
189            player->setAcceleration(Vector3(0,0,0));
190            flag_->setCollided(false); 
191            wayPointCounter = 0;
192
193        }
194       
195    }
196}
Note: See TracBrowser for help on using the repository browser.