Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5885


Ignore:
Timestamp:
Oct 6, 2009, 1:51:56 AM (15 years ago)
Author:
landauf
Message:

Somehow the code in PongBall was double… simplified this and instead added GameMode::isMaster() as a condition in two ifs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/modules/pong/PongBall.cc

    r5881 r5885  
    9696        SUPER(PongBall, tick, dt);
    9797
    98         if (GameMode::isMaster())
    99         {
    100             Vector3 position = this->getPosition();
    101             Vector3 velocity = this->getVelocity();
    102 
    103             if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
    104             {
    105                 velocity.z = -velocity.z;
    106                 if (GameMode::playsSound())
    107                     this->sidesound_->play();
    108 
    109                 if (position.z > this->fieldHeight_ / 2)
    110                     position.z = this->fieldHeight_ / 2;
    111                 if (position.z < -this->fieldHeight_ / 2)
    112                     position.z = -this->fieldHeight_ / 2;
    113             }
    114 
    115             if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
    116             {
    117                 float distance = 0;
    118 
    119                 if (this->bat_)
    120                 {
    121                     if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
    122                     {
    123                         distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
    124                         if (fabs(distance) <= 1)
    125                         {
    126                             position.x = this->fieldWidth_ / 2;
    127                             velocity.x = -velocity.x;
    128                             velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    129                             if (GameMode::playsSound())
    130                                 this->batsound_->play();
    131                         }
    132                         else if (position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
    133                         {
    134                             if (this->getGametype() && this->bat_[0])
    135                             {
    136                                 this->getGametype()->playerScored(this->bat_[0]->getPlayer());
    137                                 if (GameMode::playsSound())
    138                                     this->scoresound_->play();
    139                                 return;
    140                             }
    141                         }
    142                     }
    143                     if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
    144                     {
    145                         distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
    146                         if (fabs(distance) <= 1)
    147                         {
    148                             position.x = -this->fieldWidth_ / 2;
    149                             velocity.x = -velocity.x;
    150                             velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    151                             if (GameMode::playsSound())
    152                                 this->batsound_->play();
    153                         }
    154                         else if (position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
    155                         {
    156                             if (this->getGametype() && this->bat_[1])
    157                             {
    158                                 if (GameMode::playsSound())
    159                                     this->scoresound_->play();
    160                                 this->getGametype()->playerScored(this->bat_[1]->getPlayer());
    161                                 return;
    162                             }
    163                         }
    164                     }
    165                 }
    166             }
    167 
    168             if (velocity != this->getVelocity())
    169                 this->setVelocity(velocity);
    170             if (position != this->getPosition())
    171                 this->setPosition(position);
    172         }
    173         else
    174         {
    175           Vector3 position = this->getPosition();
    176           Vector3 velocity = this->getVelocity();
    177 
    178           if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
    179           {
     98        Vector3 position = this->getPosition();
     99        Vector3 velocity = this->getVelocity();
     100
     101        if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
     102        {
    180103            velocity.z = -velocity.z;
    181104            if (GameMode::playsSound())
     
    183106
    184107            if (position.z > this->fieldHeight_ / 2)
    185               position.z = this->fieldHeight_ / 2;
     108                position.z = this->fieldHeight_ / 2;
    186109            if (position.z < -this->fieldHeight_ / 2)
    187               position.z = -this->fieldHeight_ / 2;
    188           }
    189 
    190           if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
    191           {
     110                position.z = -this->fieldHeight_ / 2;
     111        }
     112
     113        if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
     114        {
    192115            float distance = 0;
    193116
    194117            if (this->bat_)
    195118            {
    196               if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
    197               {
    198                 distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
    199                 if (fabs(distance) <= 1)
     119                if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
    200120                {
    201                   position.x = this->fieldWidth_ / 2;
    202                   velocity.x = -velocity.x;
    203                   if (GameMode::playsSound())
    204                     this->batsound_->play();
    205                   velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     121                    distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
     122                    if (fabs(distance) <= 1)
     123                    {
     124                        position.x = this->fieldWidth_ / 2;
     125                        velocity.x = -velocity.x;
     126                        velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     127                        if (GameMode::playsSound())
     128                            this->batsound_->play();
     129                    }
     130                    else if (GameMode::isMaster() && position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     131                    {
     132                        if (this->getGametype() && this->bat_[0])
     133                        {
     134                            this->getGametype()->playerScored(this->bat_[0]->getPlayer());
     135                            if (GameMode::playsSound())
     136                                this->scoresound_->play();
     137                            return;
     138                        }
     139                    }
    206140                }
    207               }
    208               if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
    209               {
    210                 distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
    211                 if (fabs(distance) <= 1)
     141                if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
    212142                {
    213                   position.x = -this->fieldWidth_ / 2;
    214                   velocity.x = -velocity.x;
    215                   if (GameMode::playsSound())
    216                     this->batsound_->play();
    217                   velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     143                    distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
     144                    if (fabs(distance) <= 1)
     145                    {
     146                        position.x = -this->fieldWidth_ / 2;
     147                        velocity.x = -velocity.x;
     148                        velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     149                        if (GameMode::playsSound())
     150                            this->batsound_->play();
     151                    }
     152                    else if (GameMode::isMaster() && position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     153                    {
     154                        if (this->getGametype() && this->bat_[1])
     155                        {
     156                            if (GameMode::playsSound())
     157                                this->scoresound_->play();
     158                            this->getGametype()->playerScored(this->bat_[1]->getPlayer());
     159                            return;
     160                        }
     161                    }
    218162                }
    219               }
    220163            }
    221           }
    222 
    223           if (velocity != this->getVelocity())
     164        }
     165
     166        if (velocity != this->getVelocity())
    224167            this->setVelocity(velocity);
    225           if (position != this->getPosition())
     168        if (position != this->getPosition())
    226169            this->setPosition(position);
    227         }
    228170    }
    229171
Note: See TracChangeset for help on using the changeset viewer.