Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/spacerace/src/modules/gametypes/SpaceRace.cc @ 8616

Last change on this file since 8616 was 8616, checked in by msalomon, 13 years ago

RaceCheckPoints with a time limit and the version of the level for the presentation.

File size: 3.5 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 *     Mauro Salomon
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "SpaceRace.h"
30
31#include "core/CoreIncludes.h"
32#include "network/Host.h"
33#include <util/Clock.h>
34#include <util/Math.h>
35#include "util/Convert.h"
36
37namespace orxonox
38{
39    CreateUnloadableFactory(SpaceRace);
40   
41    SpaceRace::SpaceRace(BaseObject* creator) : Gametype(creator)
42    {
43        RegisterObject(SpaceRace);
44        this->bCheckpointsReached_ = 0;
45        this->bTimeIsUp_ = false;
46        this->numberOfBots_ = 0;
47    }
48   
49    void SpaceRace::tick(float dt)
50    {
51        Gametype::tick(dt);
52    }
53   
54    void SpaceRace::end()
55    {
56        Gametype::end();
57        if (this->bTimeIsUp_) {
58            this->clock_->capture();
59            int s = this->clock_->getSeconds();
60            int ms = this->clock_->getMilliseconds()-1000*s;
61            const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
62                                         + "You didn't reach the check point" + multi_cast<std::string>(this->bCheckpointsReached_+1)
63                                         + " before the time limit. You loose!\n";
64            COUT(0) << message;
65            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
66            Host::Broadcast(message);
67        }
68        else {
69            this->clock_->capture();
70            int s = this->clock_->getSeconds();
71            int ms = this->clock_->getMilliseconds()-1000*s;
72            const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
73                                          + "." + multi_cast<std::string>(ms) + " seconds.\n";
74            COUT(0) << message << std::endl;
75            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
76            Host::Broadcast(message);
77            float time = this->clock_->getSecondsPrecise();
78            this->scores_.insert(time);
79            std::set<float>::iterator it;
80            for (it=this->scores_.begin(); it!=this->scores_.end(); it++)
81            COUT(0) <<  multi_cast<std::string>(*it) << std::endl;
82        }
83    }
84
85    void SpaceRace::start()
86    {
87        Gametype::start();
88       
89        clock_= new Clock();
90        std::string message("The match has started! Reach the check points as quickly as possible!");
91        COUT(0) << message << std::endl;
92        Host::Broadcast(message);
93    }
94   
95    void SpaceRace::newCheckpointReached()
96    {
97        this->bCheckpointsReached_++;
98        this->clock_->capture();
99        int s = this->clock_->getSeconds();
100        int ms = this->clock_->getMilliseconds()-1000*s;
101        const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached()) 
102                                      + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
103                                      + " seconds.\n";
104        COUT(0) << message << std::endl;
105        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
106        Host::Broadcast(message);
107    }
108
109}
Note: See TracBrowser for help on using the repository browser.