Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 12, 2009, 8:20:07 PM (15 years ago)
Author:
rgrieder
Message:

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/pong/PongBall.cc

    r5781 r5929  
    3333#include "gametypes/Gametype.h"
    3434#include "PongBat.h"
    35 #include "sound/SoundBase.h"
    3635
    3736namespace orxonox
     
    4140    const float PongBall::MAX_REL_Z_VELOCITY = 1.5;
    4241
    43     PongBall::PongBall(BaseObject* creator) : MovableEntity(creator)
     42    PongBall::PongBall(BaseObject* creator)
     43        : MovableEntity(creator)
    4444    {
    4545        RegisterObject(PongBall);
    4646
    4747        this->speed_ = 0;
     48        this->accelerationFactor_ = 1.0f;
    4849        this->bat_ = 0;
    4950        this->batID_ = new unsigned int[2];
     
    5354
    5455        this->registerVariables();
     56    }
    5557
    56         this->sidesound_ = new SoundBase(this);
    57         this->sidesound_->loadFile("sounds/pong_side.wav");
    58 
    59         this->batsound_ = new SoundBase(this);
    60         this->batsound_->loadFile("sounds/pong_bat.wav");
    61 
    62         this->scoresound_ = new SoundBase(this);
    63         this->scoresound_->loadFile("sounds/pong_score.wav");
     58    PongBall::~PongBall()
     59    {
    6460    }
    6561
     
    7975        SUPER(PongBall, tick, dt);
    8076
    81         if (GameMode::isMaster())
     77        Vector3 position = this->getPosition();
     78        Vector3 velocity = this->getVelocity();
     79        Vector3 acceleration = this->getAcceleration();
     80
     81        if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
    8282        {
    83             Vector3 position = this->getPosition();
    84             Vector3 velocity = this->getVelocity();
     83            velocity.z = -velocity.z;
     84            if (position.z > this->fieldHeight_ / 2)
     85                position.z = this->fieldHeight_ / 2;
     86            if (position.z < -this->fieldHeight_ / 2)
     87                position.z = -this->fieldHeight_ / 2;
    8588
    86             if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
     89            this->fireEvent();
     90        }
     91
     92        if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
     93        {
     94            float distance = 0;
     95
     96            if (this->bat_)
    8797            {
    88                 velocity.z = -velocity.z;
    89                 this->sidesound_->play();
    90 
    91                 if (position.z > this->fieldHeight_ / 2)
    92                     position.z = this->fieldHeight_ / 2;
    93                 if (position.z < -this->fieldHeight_ / 2)
    94                     position.z = -this->fieldHeight_ / 2;
    95             }
    96 
    97             if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
    98             {
    99                 float distance = 0;
    100 
    101                 if (this->bat_)
     98                if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
    10299                {
    103                     if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
     100                    distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
     101                    if (fabs(distance) <= 1)
    104102                    {
    105                         distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
    106                         if (fabs(distance) <= 1)
     103                        position.x = this->fieldWidth_ / 2;
     104                        velocity.x = -velocity.x;
     105                        velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     106                        acceleration = this->bat_[1]->getVelocity() * this->accelerationFactor_ * -1;
     107                       
     108                        this->fireEvent();
     109                    }
     110                    else if (GameMode::isMaster() && position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     111                    {
     112                        if (this->getGametype() && this->bat_[0])
    107113                        {
    108                             position.x = this->fieldWidth_ / 2;
    109                             velocity.x = -velocity.x;
    110                             velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    111                             this->batsound_->play();
    112                         }
    113                         else if (position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
    114                         {
    115                             if (this->getGametype() && this->bat_[0])
    116                             {
    117                                 this->getGametype()->playerScored(this->bat_[0]->getPlayer());
    118                                 this->scoresound_->play();
    119                                 return;
    120                             }
     114                            this->getGametype()->playerScored(this->bat_[0]->getPlayer());
     115                            return;
    121116                        }
    122117                    }
    123                     if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
     118                }
     119                if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
     120                {
     121                    distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
     122                    if (fabs(distance) <= 1)
    124123                    {
    125                         distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
    126                         if (fabs(distance) <= 1)
     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                        acceleration = this->bat_[0]->getVelocity() * this->accelerationFactor_ * -1;
     128
     129                        this->fireEvent();
     130                    }
     131                    else if (GameMode::isMaster() && position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     132                    {
     133                        if (this->getGametype() && this->bat_[1])
    127134                        {
    128                             position.x = -this->fieldWidth_ / 2;
    129                             velocity.x = -velocity.x;
    130                             velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    131                             this->batsound_->play();
    132                         }
    133                         else if (position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
    134                         {
    135                             if (this->getGametype() && this->bat_[1])
    136                             {
    137                                 this->scoresound_->play();
    138                                 this->getGametype()->playerScored(this->bat_[1]->getPlayer());
    139                                 return;
    140                             }
     135                            this->getGametype()->playerScored(this->bat_[1]->getPlayer());
     136                            return;
    141137                        }
    142138                    }
    143139                }
    144140            }
     141        }
    145142
    146             if (velocity != this->getVelocity())
    147                 this->setVelocity(velocity);
    148             if (position != this->getPosition())
    149                 this->setPosition(position);
    150         }
    151         else
    152         {
    153           Vector3 position = this->getPosition();
    154           Vector3 velocity = this->getVelocity();
    155 
    156           if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
    157           {
    158             velocity.z = -velocity.z;
    159             this->sidesound_->play();
    160 
    161             if (position.z > this->fieldHeight_ / 2)
    162               position.z = this->fieldHeight_ / 2;
    163             if (position.z < -this->fieldHeight_ / 2)
    164               position.z = -this->fieldHeight_ / 2;
    165           }
    166 
    167           if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
    168           {
    169             float distance = 0;
    170 
    171             if (this->bat_)
    172             {
    173               if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
    174               {
    175                 distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
    176                 if (fabs(distance) <= 1)
    177                 {
    178                   position.x = this->fieldWidth_ / 2;
    179                   velocity.x = -velocity.x;
    180                   this->batsound_->play();
    181                   velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    182                 }
    183               }
    184               if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
    185               {
    186                 distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
    187                 if (fabs(distance) <= 1)
    188                 {
    189                   position.x = -this->fieldWidth_ / 2;
    190                   velocity.x = -velocity.x;
    191                   this->batsound_->play();
    192                   velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
    193                 }
    194               }
    195             }
    196           }
    197 
    198           if (velocity != this->getVelocity())
     143        if (acceleration != this->getAcceleration())
     144            this->setAcceleration(acceleration);
     145        if (velocity != this->getVelocity())
    199146            this->setVelocity(velocity);
    200           if (position != this->getPosition())
     147        if (position != this->getPosition())
    201148            this->setPosition(position);
    202         }
    203149    }
    204150
Note: See TracChangeset for help on using the changeset viewer.