[Orxonox-commit 7227] r11841 - in code/branches/RacingBots_FS18/src: libraries/tools modules/gametypes

andera at orxonox.net andera at orxonox.net
Thu Mar 29 16:02:42 CEST 2018


Author: andera
Date: 2018-03-29 16:02:41 +0200 (Thu, 29 Mar 2018)
New Revision: 11841

Modified:
   code/branches/RacingBots_FS18/src/libraries/tools/Timer.cc
   code/branches/RacingBots_FS18/src/libraries/tools/Timer.h
   code/branches/RacingBots_FS18/src/modules/gametypes/SpaceRace.cc
   code/branches/RacingBots_FS18/src/modules/gametypes/SpaceRace.h
Log:
added countdown

Modified: code/branches/RacingBots_FS18/src/libraries/tools/Timer.cc
===================================================================
--- code/branches/RacingBots_FS18/src/libraries/tools/Timer.cc	2018-03-29 13:57:54 UTC (rev 11840)
+++ code/branches/RacingBots_FS18/src/libraries/tools/Timer.cc	2018-03-29 14:02:41 UTC (rev 11841)
@@ -199,14 +199,6 @@
         executor->getFunctor()->setSafeMode(true);
     }
 
-    /*void Timer::setTimer(float interval, bool bKillAfterCall)
-    {
-         this->setInterval(interval);
-         this->bActive_ = true;
-         this->time_ = this->interval_;
-        this->bKillAfterCall_ = bKillAfterCall;
-    }
-    */
 
     /**
         @brief Calls the executor and destroys the timer if requested.

Modified: code/branches/RacingBots_FS18/src/libraries/tools/Timer.h
===================================================================
--- code/branches/RacingBots_FS18/src/libraries/tools/Timer.h	2018-03-29 13:57:54 UTC (rev 11840)
+++ code/branches/RacingBots_FS18/src/libraries/tools/Timer.h	2018-03-29 14:02:41 UTC (rev 11841)
@@ -112,6 +112,7 @@
 
             void run();
 
+
             /// Re-starts the timer: The executor will be called after @a interval seconds.
             inline void startTimer()
                 { this->bActive_ = true; this->time_ = this->interval_; }

Modified: code/branches/RacingBots_FS18/src/modules/gametypes/SpaceRace.cc
===================================================================
--- code/branches/RacingBots_FS18/src/modules/gametypes/SpaceRace.cc	2018-03-29 13:57:54 UTC (rev 11840)
+++ code/branches/RacingBots_FS18/src/modules/gametypes/SpaceRace.cc	2018-03-29 14:02:41 UTC (rev 11841)
@@ -69,7 +69,10 @@
 #include "SpaceRaceBot.h"
 #include "items/Engine.h"
 #include <vector>
+#include <iostream>
+#include <string>
 
+
 namespace orxonox
 {
     RegisterUnloadableClass(SpaceRace);
@@ -99,7 +102,7 @@
         startpos[3] =100;
         startpos[4] =-40;
         startpos[5] =100;
-        
+         
         startpos[6] =100;
         startpos[7] =-40;
         startpos[8] =-100;
@@ -136,21 +139,78 @@
             c += 3;
         }
 
+        std::string message("Use headphones to hear the countdown! It is useful to start with a boost!");
 
-        std::string message("Use headphones to hear the countdown!");
         this->getGametypeInfo()->sendAnnounceMessage(message);
         ChatManager::message(message);
+        
+        
+        /*for(int i=10; i>0;i=i-1){
+            startmessage(i);
+        }*/
 
 
+        //after 11 seconds , countdownFinished function is called to activate bots` engines
+        //Timer* countdownTimer = new Timer();
+        //countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this)));
 
-        //after 11 seconds , countdownFinished function is called to activate bots` engines
-        Timer* countdownTimer = new Timer();
-        countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this)));
+        /*
+        while(countdownTimer->getRemainingTime()!=0){
+            if(countdownTimer->getRemainingTime()==1){
+                startmessage(1);
+            }
+        }*/
         
+
+
+
+        
+
+        
+        /*unsigned long long float time_notification=countdownTimer.getRealMicroSeconds();
+        while(this->bTimeIsUp_==false){
+
+        std::ostream stream;
+        stream<<time_notification;
+        std::string chat_notification(stream.str());
+        this->getGametypeInfo()->sendAnnounceMessage(chat_notification);
+        ChatManager::message(chat_notification);
+
+        }*/
+
+        
     }
 
+    
 
+    void SpaceRace::tick(float dt) {
+        SUPER(SpaceRace, tick, dt);
+        this->time_passed -= dt;
 
+        if (countdown_mode) {
+
+            //orxout() << "time: " <<(int) time_passed << "s" << endl;
+            std::string message=std::to_string((int)time_passed);
+            this->getGametypeInfo()->sendAnnounceMessage(message);
+            if (time_passed <= 1) {
+                this->countdownFinished();
+                this->countdown_mode = false;
+            }
+        }
+
+    }
+        
+    void SpaceRace::startmessage(int second){
+
+        std::string message=std::to_string(second);
+        this->getGametypeInfo()->sendAnnounceMessage(message);
+        ChatManager::message(message);
+        
+        
+
+    }
+
+
     void SpaceRace::end()
     {
         this->clock_.capture();

Modified: code/branches/RacingBots_FS18/src/modules/gametypes/SpaceRace.h
===================================================================
--- code/branches/RacingBots_FS18/src/modules/gametypes/SpaceRace.h	2018-03-29 13:57:54 UTC (rev 11840)
+++ code/branches/RacingBots_FS18/src/modules/gametypes/SpaceRace.h	2018-03-29 14:02:41 UTC (rev 11841)
@@ -61,6 +61,8 @@
             virtual void countdownFinished();
             
             virtual void addBots(unsigned int amount) override; //<! overwrite function in order to bypass the addbots command.
+            virtual void tick(float dt) override;
+            virtual void startmessage(int second);
 
 
 
@@ -83,6 +85,8 @@
             virtual bool allowPawnHit(Pawn* victim, Pawn* originator) override;
             virtual bool allowPawnDamage(Pawn* victim, Pawn* originator) override;
             virtual bool allowPawnDeath(Pawn* victim, Pawn* originator) override;
+            bool countdown_mode = true;
+            float time_passed = 11.0f;
 
         private:
             bool cantMove_;                                            ///< Helper variable, used to stall the engines before the race starts.



More information about the Orxonox-commit mailing list