Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 25, 2009, 3:26:06 AM (15 years ago)
Author:
landauf
Message:

added AI for the Pong gametype
improved Pong gameplay

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/objects/worldentities/PongBat.cc

    r2826 r2839  
    4646        this->length_ = 0.25;
    4747        this->fieldHeight_ = 100;
     48        this->bSteadiedPosition_ = false;
    4849
    4950        this->registerVariables();
     
    6162        if (this->hasLocalController())
    6263        {
    63             this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_;
     64            if (this->movement_ != 0)
     65            {
     66                this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_;
    6467
    65             if (this->bMoveLocal_)
    66                 this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0));
    67             else
    68                 this->setVelocity(0, 0, this->movement_);
     68                if (this->bMoveLocal_)
     69                    this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0));
     70                else
     71                    this->setVelocity(0, 0, this->movement_);
    6972
    70             this->movement_ = 0;
     73                this->movement_ = 0;
     74                this->bSteadiedPosition_ = false;
     75            }
     76            else if (!this->bSteadiedPosition_)
     77            {
     78                // To ensure network synchronicity
     79                this->setVelocity(0, 0, 0);
     80                this->setPosition(this->getPosition());
     81                this->bSteadiedPosition_ = true;
     82            }
    7183        }
    7284
    7385        SUPER(PongBat, tick, dt);
    7486
    75         if (this->hasLocalController())
    76         {
    77             Vector3 position = this->getPosition();
    78 
    79             if (position.z > this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2)
    80                 position.z = this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2;
    81             if (position.z < -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2)
    82                 position.z = -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2;
    83 
    84             if (position != this->getPosition())
    85                 this->setPosition(position);
    86         }
     87        Vector3 position = this->getPosition();
     88        if (position.z > this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2)
     89            position.z = this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2;
     90        if (position.z < -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2)
     91            position.z = -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2;
     92        if (position != this->getPosition())
     93            this->setPosition(position);
    8794    }
    8895
     
    98105        this->movement_ = value.x;
    99106    }
     107
     108    void PongBat::changedPlayer()
     109    {
     110        this->setVelocity(0, 0, 0);
     111    }
    100112}
Note: See TracChangeset for help on using the changeset viewer.