Changeset 12294 for code/branches/OrxoBlox_FS19/src/modules/OrxoBlox
- Timestamp:
- Apr 11, 2019, 2:22:31 PM (6 years ago)
- Location:
- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc
r12288 r12294 141 141 // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to. 142 142 this->center_->attach(this->ball_); 143 this->ball_->setPosition(0, 0,0);143 this->ball_->setPosition(0,0,50); 144 144 this->ball_->setFieldDimension(this->center_->getFieldDimension()); 145 145 this->ball_->setSpeed(0); -
code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc
r12278 r12294 157 157 this->fireEvent(); 158 158 } 159 160 // 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). 159 160 //Ball hits the right or left wall and should bounce back. 161 // If the ball has crossed the left or right boundary of the playing field. 161 162 if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2) 162 163 { 163 float distance = 0; 164 165 if (this->bat_ != nullptr) // If there are bats. 166 { 167 // If the right boundary has been crossed. 168 if (position.x > this->fieldWidth_ / 2 && this->bat_[1] != nullptr) 164 //Ball hits the right Wall 165 if (position.x > this->fieldWidth_ / 2) 169 166 { 170 // 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%) 171 distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2); 172 173 174 if (fabs(distance) <= 1) // If the bat is there to parry. 175 { 176 defBatSound_->play(); //play bat sound 177 // Set the ball to be exactly at the boundary. 178 position.x = this->fieldWidth_ / 2; 179 // Invert its velocity in x-direction (i.e. it bounces off). 180 velocity.x = -velocity.x; 181 // Adjust the velocity in the z-direction, depending on where the ball hit the bat. 182 velocity.z = distance * distance * sgn(distance) * OrxoBloxBall::MAX_REL_Z_VELOCITY * this->speed_; 183 acceleration = this->bat_[1]->getVelocity() * this->accelerationFactor_ * -1; 184 185 this->fireEvent(); 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 this->fireEvent(); 186 172 } 187 173 188 // If the left player scores. 189 else if (GameMode::isMaster() && position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_)) 190 { 191 ChatManager::message("You suck!!"); 192 defScoreSound_->play();//play score sound 193 if (this->getGametype() && this->bat_[0]) 194 { 195 ChatManager::message("You suck!!"); 196 197 198 this->getGametype()->playerScored(this->bat_[0]->getPlayer()); 199 return; 200 } 201 } 202 203 204 205 206 207 } 208 // If the left boundary has been crossed. 209 else if (position.x < -this->fieldWidth_ / 2 && this->bat_[0] != nullptr) 174 //Ball hits the left wall 175 else if (position.x < -this->fieldWidth_ / 2) 210 176 { 211 // 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%)212 distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);213 if (fabs(distance) <= 1) // If the bat is there to parry.214 {215 defBatSound_->play(); //play bat sound216 177 // Set the ball to be exactly at the boundary. 217 178 position.x = -this->fieldWidth_ / 2; 218 179 // Invert its velocity in x-direction (i.e. it bounces off). 219 180 velocity.x = -velocity.x; 220 // Adjust the velocity in the z-direction, depending on where the ball hit the bat.221 velocity.z = distance * distance * sgn(distance) * OrxoBloxBall::MAX_REL_Z_VELOCITY * this->speed_;222 acceleration = this->bat_[0]->getVelocity() * this->accelerationFactor_ * -1;223 224 181 this->fireEvent(); 225 182 } 226 // If the right player scores.227 else if (GameMode::isMaster() && position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))228 {229 defScoreSound_->play();//play score sound230 if (this->getGametype() && this->bat_[1])231 {232 ChatManager::message("You suck!!");233 234 this->getGametype()->playerScored(this->bat_[1]->getPlayer());235 return;236 }237 }238 }239 }240 183 } 241 184
Note: See TracChangeset
for help on using the changeset viewer.