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

Location:
code/trunk/src/orxonox/objects/worldentities
Files:
6 edited

Legend:

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

    r2826 r2839  
    251251            }
    252252        }
     253
     254        this->changedPlayer();
    253255    }
    254256
     
    263265        this->bHasHumanController_ = false;
    264266        this->setObjectMode(objectDirection::toclient);
     267
     268        this->changedPlayer();
    265269
    266270        if (this->bDestroyWhenPlayerLeft_)
  • code/trunk/src/orxonox/objects/worldentities/ControllableEntity.h

    r2662 r2839  
    4949
    5050            virtual void changedGametype();
     51            virtual void changedPlayer() {}
    5152
    5253            virtual void setPlayer(PlayerInfo* player);
  • code/trunk/src/orxonox/objects/worldentities/PongBall.cc

    r2826 r2839  
    4444        this->speed_ = 0;
    4545        this->bat_ = 0;
     46        this->relMercyOffset_ = 0.05;
    4647    }
    4748
     
    6768            if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
    6869            {
    69                 velocity.x = -velocity.x;
    7070                float distance = 0;
    7171
    72                 if (position.x > this->fieldWidth_ / 2)
     72                if (this->bat_)
    7373                {
    74                     position.x = this->fieldWidth_ / 2;
    75                     if (this->bat_ && this->bat_[1])
     74                    if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
    7675                    {
    77                         distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * this->batlength_ / 2);
    78                         if (this->getGametype() && this->bat_[0] && fabs(distance) > 1)
     76                        distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     77                        if (fabs(distance) <= 1)
    7978                        {
    80                             this->getGametype()->playerScored(this->bat_[0]->getPlayer());
    81                             return;
     79                            position.x = this->fieldWidth_ / 2;
     80                            velocity.x = -velocity.x;
     81                            velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_;
     82                        }
     83                        else if (position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     84                        {
     85                            if (this->getGametype() && this->bat_[0])
     86                            {
     87                                this->getGametype()->playerScored(this->bat_[0]->getPlayer());
     88                                return;
     89                            }
     90                        }
     91                    }
     92                    if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
     93                    {
     94                        distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     95                        if (fabs(distance) <= 1)
     96                        {
     97                            position.x = -this->fieldWidth_ / 2;
     98                            velocity.x = -velocity.x;
     99                            velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_;
     100                        }
     101                        else if (position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     102                        {
     103                            if (this->getGametype() && this->bat_[1])
     104                            {
     105                                this->getGametype()->playerScored(this->bat_[1]->getPlayer());
     106                                return;
     107                            }
    82108                        }
    83109                    }
    84110                }
    85                 if (position.x < -this->fieldWidth_ / 2)
    86                 {
    87                     position.x = -this->fieldWidth_ / 2;
    88                     if (this->bat_ && this->bat_[0])
    89                     {
    90                         distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * this->batlength_ / 2);
    91                         if (this->getGametype() && this->bat_[1] && fabs(distance) > 1)
    92                         {
    93                             this->getGametype()->playerScored(this->bat_[1]->getPlayer());
    94                             return;
    95                         }
    96                     }
    97                 }
    98 
    99                 velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_;
    100111            }
    101112
  • code/trunk/src/orxonox/objects/worldentities/PongBall.h

    r2826 r2839  
    4848            void setFieldDimension(const Vector2& dimension)
    4949                { this->setFieldDimension(dimension.x, dimension.y); }
     50            Vector2 getFieldDimension() const
     51                { return Vector2(this->fieldWidth_, this->fieldHeight_); }
    5052
    5153            void setSpeed(float speed);
     
    6769            float batlength_;
    6870            PongBat** bat_;
     71            float relMercyOffset_;
    6972    };
    7073}
  • 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}
  • code/trunk/src/orxonox/objects/worldentities/PongBat.h

    r2826 r2839  
    4848            virtual void moveRightLeft(const Vector2& value);
    4949
     50            virtual void changedPlayer();
     51
    5052            void setSpeed(float speed)
    5153                { this->speed_ = speed; }
     
    6971            float length_;
    7072            float fieldHeight_;
     73            bool bSteadiedPosition_;
    7174    };
    7275}
Note: See TracChangeset for help on using the changeset viewer.