Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 25, 2009, 3:26:06 AM (16 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/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
Note: See TracChangeset for help on using the changeset viewer.