Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2970


Ignore:
Timestamp:
May 11, 2009, 5:00:55 PM (15 years ago)
Author:
Aurelian
Message:

Added timer in class gametype, timer working in asteroids, modified checkpoint with firstCheckPoint… working! yeepa ;-)

Location:
code/branches/gametypes/src/orxonox
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gametypes/src/orxonox/objects/gametypes/Asteroids.cc

    r2936 r2970  
    4343    {
    4444        RegisterObject(Asteroids);
     45        this->firstCheckpointReached_ = false;
     46        this->timeLimit_ = 30;
    4547    }
     48
     49    void Asteroids::tick(float dt)
     50    {
     51        SUPER(Asteroids, tick, dt);
     52 
     53        if (firstCheckpointReached_)
     54        {
     55            this->timeLimit_ = this->time_;
     56            this->startTimer();
     57        }
     58
     59        if (this->time_ < 0 && !this->hasEnded())
     60        {
     61            this->end();
     62        }
     63       
     64    }
     65
    4666
    4767    void Asteroids::start()
  • code/branches/gametypes/src/orxonox/objects/gametypes/Asteroids.h

    r2905 r2970  
    4242            virtual ~Asteroids() {}
    4343
     44            virtual void tick(float dt);
     45
    4446            virtual void start();
    4547            virtual void end();
     48           
     49            inline void firstCheckpointReached(bool reached)
     50              { this->firstCheckpointReached_ = reached; }
     51
     52        private:
     53            bool firstCheckpointReached_;
     54            bool gameEnded_;
     55
    4656    };
    4757}
  • code/branches/gametypes/src/orxonox/objects/gametypes/Gametype.cc

    r2952 r2970  
    6060        this->numberOfBots_ = 0;
    6161
     62        this->timeLimit_ = 0;
     63        this->time_ = 0;
     64        this->timerIsActive_ = false;
     65
    6266        this->initialStartCountdown_ = 3;
    6367
     
    8791    {
    8892        SUPER(Gametype, tick, dt);
     93
     94        //count timer
     95        if (timerIsActive_)
     96        {
     97            if (this->timeLimit_ == 0)
     98                this->time_ += dt;
     99            else
     100                this->time_ -= dt;
     101        }
    89102
    90103        if (this->gtinfo_.bStartCountdownRunning_ && !this->gtinfo_.bStarted_)
     
    393406        }
    394407    }
     408
     409    void Gametype::addTime(float t)
     410    {
     411        if (this->timeLimit_ == 0)
     412          this->time_ -= t;
     413        else
     414          this->time_ += t;
     415    }
     416
     417    void Gametype::removeTime(float t)
     418    {
     419        if (this->timeLimit_ == 0)
     420          this->time_ += t;
     421        else
     422          this->time_ -= t;
     423    }
     424
     425    void Gametype::resetTimer()
     426    {
     427        this->resetTimer(timeLimit_);
     428    }
     429
     430    void Gametype::resetTimer(float t)
     431    {
     432        this->timeLimit_ = t;
     433        this->time_ = t;
     434    }
    395435}
  • code/branches/gametypes/src/orxonox/objects/gametypes/Gametype.h

    r2952 r2970  
    126126                { return this->players_.size(); }
    127127
     128            virtual void addTime(float t);
     129            virtual void removeTime(float t);
     130
     131            inline  void startTimer()
     132              { this->timerIsActive_ = true; }
     133
     134            inline void stopTimer()
     135              { this->timerIsActive_ = false; }
     136
     137            inline float getTime()
     138              { return this->time_; }
     139
     140            inline bool getTimerIsActive()
     141              { return timerIsActive_; }
     142
     143            virtual void resetTimer();
     144            virtual void resetTimer(float t);
     145
    128146        protected:
    129147            virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
     
    140158            bool bAutoStart_;
    141159            bool bForceSpawn_;
     160
     161            float time_;
     162            float timeLimit_;
     163            bool timerIsActive_;
    142164
    143165            float initialStartCountdown_;
  • code/branches/gametypes/src/orxonox/objects/worldentities/triggers/CheckPoint.cc

    r2936 r2970  
    4747
    4848    this->setStayActive(true);
    49     this->setDistance(20);
    50     bIsDestination_ = false;
     49    this->setDistance(50);
     50    this->bIsFirst_ = false;
     51    this->bIsDestination_ = false;
    5152    this->setVisible(true);
    5253  }
     
    6061    SUPER(CheckPoint, XMLPort, xmlelement, mode);
    6162
     63    XMLPortParam(CheckPoint, "isfirst", setFirst, getFirst, xmlelement, mode).defaultValues(false);
    6264    XMLPortParam(CheckPoint, "isdestination", setDestination, getDestination, xmlelement, mode).defaultValues(false);
     65    XMLPortParam(CheckPoint, "addtime", setAddTime, getAddTime, xmlelement, mode).defaultValues(30);
    6366  }
    6467 
    65   void CheckPoint::setDestination(bool isDestination)
    66   {
    67     bIsDestination_ = isDestination;
    68   }
    69 
    70   bool CheckPoint::getDestination()
    71   {
    72     return bIsDestination_;
    73   }
    74 
    75 
    7668  void CheckPoint::triggered(bool bIsTriggered)
    7769  {
    7870    DistanceTrigger::triggered(bIsTriggered);
    7971
    80     if (bIsTriggered && bIsDestination_)
    81     {
    82       Asteroids* gametype = dynamic_cast<Asteroids*>(this->getGametype());
    83       if (gametype)
    84       {
    85         gametype->end();
    86       }
    87     }
     72    Asteroids* gametype = dynamic_cast<Asteroids*>(this->getGametype());
     73    if (gametype)
     74    {
     75        gametype->addTime(addTime_);
     76
     77        if (bIsTriggered && bIsFirst_)
     78        {
     79            gametype->firstCheckpointReached(true);
     80        }
     81     
     82        if (bIsTriggered && bIsDestination_)
     83        {
     84            gametype->end();
     85        }
     86     }
    8887  }
    8988}
  • code/branches/gametypes/src/orxonox/objects/worldentities/triggers/CheckPoint.h

    r2936 r2970  
    5757    private:
    5858      virtual void triggered(bool bIsTriggered);
    59       virtual void setDestination(bool isDestination);
    60       virtual bool getDestination();   
     59
     60      inline void setDestination(bool isDestination)
     61        { bIsDestination_ = isDestination; }
     62
     63      inline bool getDestination()
     64        { return bIsDestination_; }     
     65   
     66      inline void setFirst(bool isFirst)
     67        { this->bIsFirst_ = isFirst; }
     68
     69      inline bool getFirst()
     70        { return this->bIsFirst_; }
     71
     72      inline void setAddTime(float time)
     73        { this->addTime_ = time; }
     74
     75      inline bool getAddTime()
     76        { return this->addTime_; }
    6177     
     78      bool bIsFirst_;
    6279      bool bIsDestination_;
     80      float addTime_;
    6381  };
    6482}
  • code/branches/gametypes/src/orxonox/overlays/hud/CMakeLists.txt

    r2710 r2970  
    55  HUDSpeedBar.cc
    66  HUDHealthBar.cc
     7  HUDTimer.cc
    78  ChatOverlay.cc
    89  GametypeStatus.cc
Note: See TracChangeset for help on using the changeset viewer.