Changeset 8630 for code/branches/spacerace/src/modules/gametypes
- Timestamp:
- May 27, 2011, 11:01:24 PM (14 years ago)
- Location:
- code/branches/spacerace/src/modules/gametypes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/spacerace/src/modules/gametypes/RaceCheckPoint.cc
r8617 r8630 38 38 CreateFactory(RaceCheckPoint); 39 39 40 RaceCheckPoint::RaceCheckPoint(BaseObject* creator): 41 DistanceTrigger(creator), 42 RadarViewable(creator, static_cast<WorldEntity*>(this)) 40 RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this)) 43 41 { 44 45 46 47 48 49 50 42 RegisterObject(RaceCheckPoint); 43 44 this->bCheckpointIndex_ = 0; 45 this->bIsLast_ = false; 46 this->bTimeLimit_ = 0; 47 48 this->setRadarObjectColour(ColourValue::Blue); 51 49 this->setRadarObjectShape(RadarViewable::Triangle); 52 50 this->setRadarVisibility(false); … … 59 57 void RaceCheckPoint::tick(float dt) 60 58 { 61 Trigger::tick(dt); 62 63 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 64 if (this->getCheckpointIndex() == gametype->getCheckpointsReached()) this->setRadarVisibility(true); 65 else this->setRadarVisibility(false); 59 SUPER(RaceCheckPoint, tick, dt); 60 61 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 62 if (this->getCheckpointIndex() == gametype->getCheckpointsReached()) 63 this->setRadarVisibility(true); 64 else 65 this->setRadarVisibility(false); 66 66 } 67 67 … … 69 69 void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) 70 70 { 71 72 73 74 75 71 SUPER(RaceCheckPoint, XMLPort, xmlelement, mode); 72 73 XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0); 74 XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false); 75 XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0); 76 76 } 77 77 78 78 void RaceCheckPoint::triggered(bool bIsTriggered) 79 79 { 80 DistanceTrigger::triggered(bIsTriggered); 81 82 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 83 if (gametype) 84 { 85 if (this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered) 86 { 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()) 94 { 95 gametype->end(); 96 } 97 else 98 { 99 gametype->newCheckpointReached(); 100 this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red. 101 } 102 } 103 } 80 DistanceTrigger::triggered(bIsTriggered); 81 82 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 83 if (gametype && this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered) 84 { 85 gametype->clock_.capture(); 86 float time = gametype->clock_.getSecondsPrecise(); 87 if (this->bTimeLimit_!=0 && time > this->bTimeLimit_) 88 { 89 gametype->timeIsUp(); 90 gametype->end(); 91 } 92 else if (this->getLast()) 93 gametype->end(); 94 else 95 { 96 gametype->newCheckpointReached(); 97 this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red. 98 } 99 } 104 100 } 105 101 106 102 void RaceCheckPoint::setTimelimit(float timeLimit) 107 { 108 109 110 111 112 113 114 const std::string& message = "\nYou have " + multi_cast<std::string>(this->bTimeLimit_)115 + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1) + "\n\n";116 COUT(0) << message;117 118 119 120 103 { 104 this->bTimeLimit_ = timeLimit; 105 if (this->bTimeLimit_ != 0) 106 { 107 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 108 if (gametype) 109 { 110 const std::string& message = "You have " + multi_cast<std::string>(this->bTimeLimit_) 111 + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1) + "\n"; 112 COUT(3) << message; 113 const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message); 114 } 115 } 116 } 121 117 122 118 } -
code/branches/spacerace/src/modules/gametypes/RaceCheckPoint.h
r8616 r8630 34 34 #include "objects/triggers/DistanceTrigger.h" 35 35 #include "interfaces/RadarViewable.h" 36 #include <boost/concept_check.hpp>36 //#include <boost/concept_check.hpp> 37 37 38 38 namespace orxonox … … 40 40 /** 41 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!!!42 The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level. 43 !!! Don't forget to control the indexes of your check points and to set one last check point!!! 44 44 */ 45 45 class _ObjectsExport RaceCheckPoint : public DistanceTrigger, public RadarViewable 46 46 { 47 public:48 49 50 51 52 53 54 protected:55 56 57 58 59 60 61 62 63 64 65 66 67 68 { return this; }69 70 private:71 72 73 47 public: 48 RaceCheckPoint(BaseObject* creator); 49 virtual ~RaceCheckPoint(); 50 51 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 52 virtual void tick(float dt); 53 54 protected: 55 virtual void triggered(bool bIsTriggered); 56 inline void setLast(bool isLast) 57 { this->bIsLast_ = isLast; } 58 inline bool getLast() 59 { return this->bIsLast_; } 60 inline void setCheckpointIndex(int checkpointIndex) 61 { this->bCheckpointIndex_ = checkpointIndex; } 62 inline int getCheckpointIndex() 63 { return this->bCheckpointIndex_; } 64 virtual void setTimelimit(float timeLimit); 65 inline float getTimeLimit() 66 { return this->bTimeLimit_;} 67 inline const WorldEntity* getWorldEntity() const 68 { return this; } 69 70 private: 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. 74 74 75 75 }; 76 76 } 77 77 78 #endif 78 #endif /* _RaceCheckPoint_H__ */ -
code/branches/spacerace/src/modules/gametypes/SpaceRace.cc
r8624 r8630 41 41 SpaceRace::SpaceRace(BaseObject* creator) : Gametype(creator) 42 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); 43 RegisterObject(SpaceRace); 44 this->bCheckpointsReached_ = 0; 45 this->bTimeIsUp_ = false; 46 this->numberOfBots_ = 0; 52 47 } 53 48 54 49 void SpaceRace::end() 55 50 { 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 lose!\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 } 51 this->Gametype::end(); 52 53 if (this->bTimeIsUp_) 54 { 55 this->clock_.capture(); 56 int s = this->clock_.getSeconds(); 57 int ms = this->clock_.getMilliseconds()-1000*s; 58 const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n" 59 + "You didn't reach the check point " + multi_cast<std::string>(this->bCheckpointsReached_+1) 60 + " before the time limit. You lose!"; 61 COUT(3) << message; 62 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 63 Host::Broadcast(message); 64 } 65 else 66 { 67 this->clock_.capture(); 68 int s = this->clock_.getSeconds(); 69 int ms = this->clock_.getMilliseconds()-1000*s; 70 const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s) 71 + "." + multi_cast<std::string>(ms) + " seconds."; 72 COUT(3) << message << std::endl; 73 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 74 Host::Broadcast(message); 75 float time = this->clock_.getSecondsPrecise(); 76 this->scores_.insert(time); 77 std::set<float>::iterator it; 78 for (it=this->scores_.begin(); it!=this->scores_.end(); it++) 79 COUT(3) << multi_cast<std::string>(*it) << std::endl; 80 } 83 81 } 84 82 85 83 void SpaceRace::start() 86 84 { 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; 85 Gametype::start(); 86 87 std::string message("The match has started! Reach the check points as quickly as possible!"); 88 COUT(3) << message << std::endl; 92 89 Host::Broadcast(message); 93 90 } … … 95 92 void SpaceRace::newCheckpointReached() 96 93 { 97 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 103 104 COUT(0) << message << std::endl;105 106 94 this->bCheckpointsReached_++; 95 this->clock_.capture(); 96 int s = this->clock_.getSeconds(); 97 int ms = this->clock_.getMilliseconds()-1000*s; 98 const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached()) 99 + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) 100 + " seconds.\n"; 101 COUT(3) << message; 102 const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message); 103 Host::Broadcast(message); 107 104 } 108 105 -
code/branches/spacerace/src/modules/gametypes/SpaceRace.h
r8616 r8630 42 42 /** 43 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.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 45 */ 46 46 class _OrxonoxExport SpaceRace : public Gametype 47 47 { 48 public: 49 SpaceRace(BaseObject* creator); 50 virtual ~SpaceRace() {} 51 52 virtual void tick(float dt); 53 54 virtual void start(); 55 virtual void end(); 56 57 virtual void newCheckpointReached(); 58 59 inline void setCheckpointsReached(int n) 60 { this->bCheckpointsReached_ = n;} 61 inline int getCheckpointsReached() 62 { return this->bCheckpointsReached_; } 63 inline void timeIsUp() 64 { this->bTimeIsUp_ = true;} 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. 66 protected: 67 68 private: 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. 48 friend class RaceCheckPoint; 49 50 public: 51 SpaceRace(BaseObject* creator); 52 virtual ~SpaceRace() {} 53 54 virtual void start(); 55 virtual void end(); 56 57 virtual void newCheckpointReached(); 58 59 inline void setCheckpointsReached(int n) 60 { this->bCheckpointsReached_ = n;} 61 inline int getCheckpointsReached() 62 { return this->bCheckpointsReached_; } 63 inline void timeIsUp() 64 { this->bTimeIsUp_ = true;} 65 66 protected: 67 68 private: 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. 72 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. 72 73 }; 73 74 } 74 75 75 #endif 76 #endif /* _SpaceRace_H__ */
Note: See TracChangeset
for help on using the changeset viewer.