Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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/objects/gametypes
Files:
4 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_;
Note: See TracChangeset for help on using the changeset viewer.