Changeset 8616 for code/branches/spacerace/src/modules
- Timestamp:
- May 26, 2011, 10:03:32 PM (13 years ago)
- Location:
- code/branches/spacerace/src/modules/gametypes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/spacerace/src/modules/gametypes/RaceCheckPoint.cc
r8552 r8616 32 32 #include "core/XMLPort.h" 33 33 #include "SpaceRace.h" 34 #include "util/Convert.h" 34 35 35 36 namespace orxonox … … 47 48 this->bTimeLimit_ = 0; 48 49 49 this->setRadarObjectColour(ColourValue:: Red);50 this->setRadarObjectShape(RadarViewable:: Dot);50 this->setRadarObjectColour(ColourValue::Blue); 51 this->setRadarObjectShape(RadarViewable::Triangle); 51 52 this->setRadarVisibility(false); 52 53 } … … 63 64 if (this->getCheckpointIndex() == gametype->getCheckpointsReached()) this->setRadarVisibility(true); 64 65 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 }73 66 } 74 67 … … 92 85 if (this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered) 93 86 { 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()) 95 94 { 96 95 gametype->end(); … … 105 104 } 106 105 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 107 122 } -
code/branches/spacerace/src/modules/gametypes/RaceCheckPoint.h
r8548 r8616 38 38 namespace orxonox 39 39 { 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 */ 40 45 class _ObjectsExport RaceCheckPoint : public DistanceTrigger, public RadarViewable 41 46 { … … 57 62 inline int getCheckpointIndex() 58 63 { 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() 62 66 { return this->bTimeLimit_;} 63 67 inline const WorldEntity* getWorldEntity() const … … 65 69 66 70 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. 70 74 71 75 }; -
code/branches/spacerace/src/modules/gametypes/SpaceRace.cc
r8573 r8616 42 42 { 43 43 RegisterObject(SpaceRace); 44 this-> checkpointsReached_ = 0;44 this->bCheckpointsReached_ = 0; 45 45 this->bTimeIsUp_ = false; 46 46 this->numberOfBots_ = 0; … … 55 55 { 56 56 Gametype::end(); 57 this->stopTimer();58 57 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); 61 67 } 62 68 else { … … 64 70 int s = this->clock_->getSeconds(); 65 71 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"; 68 74 COUT(0) << message << std::endl; 69 75 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); … … 81 87 Gametype::start(); 82 88 83 this->startTimer();84 89 clock_= new Clock(); 85 90 std::string message("The match has started! Reach the check points as quickly as possible!"); … … 90 95 void SpaceRace::newCheckpointReached() 91 96 { 92 this-> checkpointsReached_++;97 this->bCheckpointsReached_++; 93 98 this->clock_->capture(); 94 99 int s = this->clock_->getSeconds(); … … 96 101 const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached()) 97 102 + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) 98 + " seconds. ";103 + " seconds.\n"; 99 104 COUT(0) << message << std::endl; 100 105 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); -
code/branches/spacerace/src/modules/gametypes/SpaceRace.h
r8552 r8616 40 40 namespace orxonox 41 41 { 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 */ 62 46 class _OrxonoxExport SpaceRace : public Gametype 63 47 { … … 74 58 75 59 inline void setCheckpointsReached(int n) 76 { this-> checkpointsReached_ = n;}60 { this->bCheckpointsReached_ = n;} 77 61 inline int getCheckpointsReached() 78 { return this-> checkpointsReached_; }62 { return this->bCheckpointsReached_; } 79 63 inline void timeIsUp() 80 64 { 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. 82 66 protected: 83 67 84 68 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. 89 72 }; 90 73 }
Note: See TracChangeset
for help on using the changeset viewer.