Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 26, 2009, 9:20:57 PM (16 years ago)
Author:
landauf
Message:

merged netp3 branch back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/objects/worldentities/PongBall.cc

    r2896 r3084  
    3232#include "core/CoreIncludes.h"
    3333#include "core/GameMode.h"
    34 #include "objects/worldentities/PongBat.h"
    3534#include "objects/gametypes/Gametype.h"
    3635
     
    4746        this->speed_ = 0;
    4847        this->bat_ = 0;
     48        this->batID_ = new unsigned int[2];
     49        this->batID_[0] = OBJECTID_UNKNOWN;
     50        this->batID_[1] = OBJECTID_UNKNOWN;
    4951        this->relMercyOffset_ = 0.05;
     52       
     53        this->registerVariables();
     54    }
     55   
     56    void PongBall::registerVariables()
     57    {
     58        registerVariable( this->fieldWidth_ );
     59        registerVariable( this->fieldHeight_ );
     60        registerVariable( this->batlength_ );
     61        registerVariable( this->speed_ );
     62        registerVariable( this->relMercyOffset_ );
     63        registerVariable( this->batID_[0] );
     64        registerVariable( this->batID_[1], variableDirection::toclient, new NetworkCallback<PongBall>( this, &PongBall::applyBats) );
    5065    }
    5166
     
    119134                this->setPosition(position);
    120135        }
     136        else
     137        {
     138          Vector3 position = this->getPosition();
     139          Vector3 velocity = this->getVelocity();
     140
     141          if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
     142          {
     143            velocity.z = -velocity.z;
     144
     145            if (position.z > this->fieldHeight_ / 2)
     146              position.z = this->fieldHeight_ / 2;
     147            if (position.z < -this->fieldHeight_ / 2)
     148              position.z = -this->fieldHeight_ / 2;
     149          }
     150
     151          if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
     152          {
     153            float distance = 0;
     154
     155            if (this->bat_)
     156            {
     157              if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
     158              {
     159                distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     160                if (fabs(distance) <= 1)
     161                {
     162                  position.x = this->fieldWidth_ / 2;
     163                  velocity.x = -velocity.x;
     164                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     165                }
     166              }
     167              if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
     168              {
     169                distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     170                if (fabs(distance) <= 1)
     171                {
     172                  position.x = -this->fieldWidth_ / 2;
     173                  velocity.x = -velocity.x;
     174                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     175                }
     176              }
     177            }
     178          }
     179
     180          if (velocity != this->getVelocity())
     181            this->setVelocity(velocity);
     182          if (position != this->getPosition())
     183            this->setPosition(position);
     184        }
    121185    }
    122186
Note: See TracChangeset for help on using the changeset viewer.