Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 26, 2011, 10:03:32 PM (14 years ago)
Author:
msalomon
Message:

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

Location:
code/branches/spacerace/src/modules/gametypes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/spacerace/src/modules/gametypes/RaceCheckPoint.cc

    r8552 r8616  
    3232#include "core/XMLPort.h"
    3333#include "SpaceRace.h"
     34#include "util/Convert.h"
    3435
    3536namespace orxonox
     
    4748        this->bTimeLimit_ = 0;
    4849       
    49         this->setRadarObjectColour(ColourValue::Red);
    50         this->setRadarObjectShape(RadarViewable::Dot);
     50        this->setRadarObjectColour(ColourValue::Blue);
     51        this->setRadarObjectShape(RadarViewable::Triangle);
    5152        this->setRadarVisibility(false);
    5253    }
     
    6364        if (this->getCheckpointIndex() == gametype->getCheckpointsReached()) this->setRadarVisibility(true);
    6465        else  this->setRadarVisibility(false);
    65        
    66         if (this->bTimeLimit_ != 0 && gametype->getTimerIsActive()) {
    67           float time = gametype->getTime() - this->bTimeLimit_;
    68           if (time > 0) {
    69             gametype->timeIsUp();
    70             gametype->end();
    71           }
    72         }
    7366    }
    7467
     
    9285            if (this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered)
    9386            {
    94                 if (this->getLast())
     87                gametype->clock_->capture();
     88                float time = gametype->clock_->getSecondsPrecise();
     89                if (this->bTimeLimit_!=0 && time > this->bTimeLimit_) {
     90                  gametype->timeIsUp();
     91                  gametype->end();
     92                }
     93                else if (this->getLast())
    9594                {
    9695                  gametype->end();
     
    105104    }
    106105   
     106    void RaceCheckPoint::setTimelimit(float timeLimit)
     107            {
     108              this->bTimeLimit_ = timeLimit;
     109              if (this->bTimeLimit_ != 0)
     110              {
     111                  SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
     112                  if (gametype)
     113                  {
     114                     const std::string& message =  "You have " + multi_cast<std::string>(this->bTimeLimit_)
     115                                                   + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1) + "\n";
     116                     COUT(0) << message;
     117                     const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message);
     118                  }
     119              }
     120            }
     121   
    107122}
  • code/branches/spacerace/src/modules/gametypes/RaceCheckPoint.h

    r8548 r8616  
    3838namespace orxonox
    3939{
     40  /**
     41  @brief
     42  The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level.
     43  !!! Don't forget to controll the indexes of your check points and to set one last check point!!!
     44  */
    4045    class _ObjectsExport RaceCheckPoint : public DistanceTrigger, public RadarViewable
    4146    {
     
    5762        inline int getCheckpointIndex()
    5863            { return this->bCheckpointIndex_; }
    59         inline void setTimelimit(int timeLimit)
    60             { this->bTimeLimit_ = timeLimit;}
    61         inline int getTimeLimit()
     64        virtual void setTimelimit(float timeLimit);
     65        inline float getTimeLimit()
    6266            { return this->bTimeLimit_;}
    6367        inline const WorldEntity* getWorldEntity() const
     
    6569       
    6670    private:
    67         int bCheckpointIndex_;
    68         bool bIsLast_;
    69         int bTimeLimit_;
     71        int bCheckpointIndex_; //The index of this check point. This value will be compared with the number of check points reached in the level. The check points must be indexed in ascending order beginning from zero and without any jumps between the indexes.
     72        bool bIsLast_; //True if this check point is the last of the level. There can be only one last check point for each level and there must be a last check point in the level.
     73        float bTimeLimit_; //The time limit (from the start of the level) to reach this check point. If the check point is reached after this time, the game ends and the player looses.
    7074     
    7175    };
  • code/branches/spacerace/src/modules/gametypes/SpaceRace.cc

    r8573 r8616  
    4242    {
    4343        RegisterObject(SpaceRace);
    44         this->checkpointsReached_ = 0;
     44        this->bCheckpointsReached_ = 0;
    4545        this->bTimeIsUp_ = false;
    4646        this->numberOfBots_ = 0;
     
    5555    {
    5656        Gametype::end();
    57         this->stopTimer();
    5857        if (this->bTimeIsUp_) {
    59             COUT(0) << "Time is up" << std::endl;
    60             const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage("Time is up");
     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);
    6167        }
    6268        else {
     
    6470            int s = this->clock_->getSeconds();
    6571            int ms = this->clock_->getMilliseconds()-1000*s;
    66             const std::string& message = "You have reached the last check point after "+ multi_cast<std::string>(s) +
    67                                           "." + multi_cast<std::string>(ms) + " seconds.";
     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";
    6874            COUT(0) << message << std::endl;
    6975            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     
    8187        Gametype::start();
    8288       
    83         this->startTimer();
    8489        clock_= new Clock();
    8590        std::string message("The match has started! Reach the check points as quickly as possible!");
     
    9095    void SpaceRace::newCheckpointReached()
    9196    {
    92         this->checkpointsReached_++;
     97        this->bCheckpointsReached_++;
    9398        this->clock_->capture();
    9499        int s = this->clock_->getSeconds();
     
    96101        const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached())
    97102                                      + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
    98                                       + " seconds.";
     103                                      + " seconds.\n";
    99104        COUT(0) << message << std::endl;
    100105        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
  • code/branches/spacerace/src/modules/gametypes/SpaceRace.h

    r8552 r8616  
    4040namespace orxonox
    4141{
    42 /*    class PlayerScore {
    43         public:
    44             PlayerScore() {
    45                 this->name = "";
    46                 this->time =0;
    47             }
    48             PlayerScore(std::string name, float time) {
    49                 this->name_ = name;
    50                 this->time_ = time;
    51             }
    52             PlayerScore(float time) {
    53                 this->name_ = "Player";
    54                 this->time_ = time;
    55             }
    56        
    57         private:
    58             std::string name_;
    59             float time_;
    60     };*/
    61        
     42  /**
     43  @brief
     44  The SpaceRace class enables the creation of a space race level, where the player has to reach check points in a given order.
     45  */
    6246    class _OrxonoxExport SpaceRace : public Gametype
    6347    {
     
    7458           
    7559            inline void setCheckpointsReached(int n)
    76                 { this->checkpointsReached_ = n;}
     60                { this->bCheckpointsReached_ = n;}
    7761            inline int getCheckpointsReached()
    78                 { return this->checkpointsReached_; }
     62                { return this->bCheckpointsReached_; }
    7963            inline void timeIsUp()
    8064                { this->bTimeIsUp_ = true;}
    81            
     65            Clock *clock_; //The clock starts running at the beginning of the game. It is used to give the time at each check point, the give the time at the end of the game, and to stop the game if a check point is reached too late.
    8266        protected:
    8367           
    8468        private:
    85             int checkpointsReached_;
    86             std::set<float> scores_;
    87             Clock *clock_;
    88             bool bTimeIsUp_;
     69            int bCheckpointsReached_; //The current number of check points reached by the player.
     70            std::set<float> scores_; //The times of the players are saved in a set.
     71            bool bTimeIsUp_; //True if one of the check points is reached too late.
    8972    };
    9073}
Note: See TracChangeset for help on using the changeset viewer.