Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 22, 2014, 3:05:46 PM (10 years ago)
Author:
fvultier
Message:

new items added. improved level generator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc

    r10050 r10074  
    5858        RegisterObject(JumpPlatform);
    5959
    60         this->figure_ = 0;
     60        figure_ = 0;
    6161
    6262        //initialize sound
    6363        if (GameMode::isMaster())
    6464                 {
    65                          this->defScoreSound_ = new WorldSound(this->getContext());
    66                          this->defScoreSound_->setVolume(1.0f);
    67                          this->defBatSound_ = new WorldSound(this->getContext());
    68                          this->defBatSound_->setVolume(0.4f);
    69                          this->defBoundarySound_ = new WorldSound(this->getContext());
    70                          this->defBoundarySound_->setVolume(0.5f);
     65                         defScoreSound_ = new WorldSound(this->getContext());
     66                         defScoreSound_->setVolume(1.0f);
     67                         defBatSound_ = new WorldSound(this->getContext());
     68                         defBatSound_->setVolume(0.4f);
     69                         defBoundarySound_ = new WorldSound(this->getContext());
     70                         defBoundarySound_->setVolume(0.5f);
    7171                 }
    7272                 else
    7373                 {
    74                          this->defScoreSound_ = 0;
    75                          this->defBatSound_ = 0;
    76                          this->defBoundarySound_ = 0;
     74                         defScoreSound_ = 0;
     75                         defBatSound_ = 0;
     76                         defBoundarySound_ = 0;
    7777                 }
    7878
    79         this->setPosition(Vector3(0,0,0));
    80         this->setVelocity(Vector3(0,0,0));
    81         this->setAcceleration(Vector3(0,0,0));
     79        setPosition(Vector3(0,0,0));
     80        setVelocity(Vector3(0,0,0));
     81        setAcceleration(Vector3(0,0,0));
    8282    }
    8383
     
    8888    JumpPlatform::~JumpPlatform()
    8989    {
    90         /*if (this->isInitialized())
    91         {
    92             if (this->bDeleteBats_)
    93                 delete this->figure_;
    9490
    95             delete[] this->batID_;
    96         }*/
    9791    }
    9892
     
    10195    {
    10296        SUPER(JumpPlatform, XMLPort, xmlelement, mode);
     97
     98        XMLPortParam(JumpPlatform, "height", setHeight, getHeight, xmlelement, mode);
     99        XMLPortParam(JumpPlatform, "width", setWidth, getWidth, xmlelement, mode);
     100
    103101        XMLPortParam(JumpPlatform, "defScoreSound",  setDefScoreSound,  getDefScoreSound,  xmlelement, mode);
    104102        XMLPortParam(JumpPlatform, "defBatSound",  setDefBatSound,  getDefBatSound,  xmlelement, mode);
     
    124122            Vector3 figureVelocity = figure_->getVelocity();
    125123
    126             if(figureVelocity.z < 0 && figurePosition.x > platformPosition.x-10 && figurePosition.x < platformPosition.x+10 && figurePosition.z > platformPosition.z-4 && figurePosition.z < platformPosition.z+4)
     124            float tolerance = 3.0;
     125
     126            if(figureVelocity.z < 0 && figurePosition.x > platformPosition.x-width_/2 && figurePosition.x < platformPosition.x+width_/2 && figurePosition.z > platformPosition.z-height_/2*tolerance && figurePosition.z < platformPosition.z+height_/2)
    127127            {
    128128                touchFigure();
    129129            }
    130130        }
    131 
    132 
    133 
    134 
    135 
    136         /*
    137         // If the ball has gone over the top or bottom boundary of the playing field (i.e. the ball has hit the top or bottom delimiters).
    138         if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
    139         {
    140             defBoundarySound_->play(); //play boundary sound
    141             // Its velocity in z-direction is inverted (i.e. it bounces off).
    142             velocity.z = -velocity.z;
    143             // And its position is set as to not overstep the boundary it has just crossed.
    144             if (position.z > this->fieldHeight_ / 2)
    145                 position.z = this->fieldHeight_ / 2;
    146             if (position.z < -this->fieldHeight_ / 2)
    147                 position.z = -this->fieldHeight_ / 2;
    148 
    149             this->fireEvent();
    150         }
    151 
    152         // If the ball has crossed the left or right boundary of the playing field (i.e. a player has just scored, if the bat isn't there to parry).
    153         if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
    154         {
    155             float distance = 0;
    156 
    157             if (this->bat_ != NULL) // If there are bats.
    158             {
    159                 // If the right boundary has been crossed.
    160                 if (position.x > this->fieldWidth_ / 2 && this->bat_[1] != NULL)
    161                 {
    162                     // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)
    163                     distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
    164                     if (fabs(distance) <= 1) // If the bat is there to parry.
    165                     {
    166                         defBatSound_->play(); //play bat sound
    167                         // Set the ball to be exactly at the boundary.
    168                         position.x = this->fieldWidth_ / 2;
    169                         // Invert its velocity in x-direction (i.e. it bounces off).
    170                         velocity.x = -velocity.x;
    171                         // Adjust the velocity in the z-direction, depending on where the ball hit the bat.
    172                         velocity.z = distance * distance * sgn(distance) * JumpPlatform::MAX_REL_Z_VELOCITY * this->speed_;
    173                         acceleration = this->bat_[1]->getVelocity() * this->accelerationFactor_ * -1;
    174 
    175                         this->fireEvent();
    176                     }
    177                     // If the left player scores.
    178                     else if (GameMode::isMaster() && position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
    179                     {
    180                         defScoreSound_->play();//play score sound
    181                         if (this->getGametype() && this->bat_[0])
    182                         {
    183                             this->getGametype()->playerScored(this->bat_[0]->getPlayer());
    184                             return;
    185                         }
    186                     }
    187                 }
    188                 // If the left boundary has been crossed.
    189                 else if (position.x < -this->fieldWidth_ / 2 && this->bat_[0] != NULL)
    190                 {
    191                     // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)
    192                     distance = (position.z - this->figure_->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
    193                     if (fabs(distance) <= 1) // If the bat is there to parry.
    194                     {
    195                         defBatSound_->play(); //play bat sound
    196                         // Set the ball to be exactly at the boundary.
    197                         position.x = -this->fieldWidth_ / 2;
    198                         // Invert its velocity in x-direction (i.e. it bounces off).
    199                         velocity.x = -velocity.x;
    200                         // Adjust the velocity in the z-direction, depending on where the ball hit the bat.
    201                         velocity.z = distance * distance * sgn(distance) * JumpPlatform::MAX_REL_Z_VELOCITY * this->speed_;
    202                         acceleration = this->bat_[0]->getVelocity() * this->accelerationFactor_ * -1;
    203 
    204                         this->fireEvent();
    205                     }
    206                     // If the right player scores.
    207                     else if (GameMode::isMaster() && position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
    208                     {
    209                         defScoreSound_->play();//play score sound
    210                         if (this->getGametype() && this->bat_[1])
    211                         {
    212                             this->getGametype()->playerScored(this->bat_[1]->getPlayer());
    213                             return;
    214                         }
    215                     }
    216                 }
    217             }
    218         }
    219         */
    220131    }
    221132
    222     /**
    223     @brief
    224         Set the bats for the ball.
    225     @param bats
    226         An array (of size 2) of weak pointers, to be set as the new bats.
    227     */
    228133    void JumpPlatform::setFigure(WeakPtr<JumpFigure> newFigure)
    229134    {
    230135        figure_ = newFigure;
    231     }
    232 
    233     void JumpPlatform::accelerateFigure()
    234     {
    235         figure_->JumpFromPlatform(this);
    236136    }
    237137
Note: See TracChangeset for help on using the changeset viewer.