Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12183 was 12168, checked in by emustafa, 6 years ago

still on controlls

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