- Timestamp:
- May 11, 2017, 3:18:27 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/SuperOrxoBros_FS17/src/modules/superorxobros/SOBFigure.cc
r11412 r11416 21 21 * 22 22 * Author: 23 * Fabien Vultier23 * Julien Kindle 24 24 * Co-authors: 25 * ...25 * 26 26 * 27 27 */ … … 44 44 #include "SOB.h" 45 45 #include "SOBFlagstone.h" 46 #include "SOBCastlestone.h" 46 47 47 48 namespace orxonox … … 54 55 55 56 // initialize variables 56 57 gravityAcceleration_ = 350.0; 58 59 //Vars for movement of player 57 60 moveUpPressed_ = false; 58 61 moveDownPressed_ = false; … … 60 63 moveDownPressed_ = false; 61 64 firePressed_ = false; 65 66 //Times and turning 62 67 timeSinceLastFire_ = 0.0; 63 68 lastSpeed_z = 0.0; 69 pitch_ = 0.0; 70 timeCounter_ = 0; 71 72 //Properties of player 73 gotPowerUp_ = false; 64 74 isColliding_ = true; 65 75 particlespawner_ = NULL; 66 76 67 gravityAcceleration_ = 350.0; 68 pitch_ = 0.0; 69 77 //Properties of players life 70 78 predead_ = false; 71 79 dead_ = false; 72 gotPowerUp_ = false; 80 lvlEnded_ = false; 81 reachedLvlEndState_ = 0; 82 73 83 74 setAngularFactor(0.0); 75 this->enableCollisionCallback(); 84 setAngularFactor(0.0); //Means player doesn't turn on collision, so he doesn't fall over while walking over the ground 85 this->enableCollisionCallback(); // Turns on that on every collision function collidesAgainst is executed 76 86 } 77 87 … … 81 91 82 92 isColliding_ = true; 93 94 //Orxocast returns object with casted type if otherObject has that class, and if not a nullptr 83 95 SOBMushroom* mush = orxonox_cast<SOBMushroom*>(otherObject); 84 96 SOBGumba* gumba = orxonox_cast<SOBGumba*>(otherObject); 85 97 SOBFlagstone* flagstone = orxonox_cast<SOBFlagstone*>(otherObject); 86 98 SOBCastlestone* castlestone = orxonox_cast<SOBCastlestone*>(otherObject); 99 100 //Check if otherObject is a powerup 87 101 if (mush != nullptr && !(mush->hasCollided_)) { 88 102 otherObject->destroyLater(); 89 103 gotPowerUp_ = true; 90 SOB* SOBGame = orxonox_cast<SOB*>(getGametype()); 91 SOBGame->addMushroom(); 92 mush->hasCollided_ = true; 93 104 SOB* SOBGame = orxonox_cast<SOB*>(getGametype()); //Get the Gametype 105 SOBGame->addMushroom(); // Tell the gametype to increase points 106 mush->hasCollided_ = true; // needed because of destroyLater takes some time and player should receive points only once 107 108 //Check if otherObject is a Gumba (that walking enemies) 94 109 } else if (gumba != nullptr && !(gumba->hasCollided_)) { 95 110 111 //If player jumps on its head, kill it, else, kill the player 96 112 if (getVelocity().z >= -20) { 97 113 Vector3 vel = getVelocity(); … … 100 116 setVelocity(vel); 101 117 predead_=true; 118 102 119 } else { 103 120 gumba->destroyLater(); … … 110 127 } 111 128 112 if (flagstone != nullptr && !(flagstone->hasCollided_)) { 113 flagstone->hasCollided_ = true; 114 115 } 129 //Purpose is that if player hits the flag, he should walk into the castle at the end of the level. For that we use SOBCastlestone 130 if (reachedLvlEndState_ == 0 && flagstone != nullptr && !(flagstone->hasCollided_)) { 131 flagstone->hasCollided_ = true; 132 reachedLvlEndState_ = 1; 133 SOB* SOBGame = orxonox_cast<SOB*>(getGametype()); 134 SOBGame->addPoints(flagstone->getPoints()); 135 136 } 137 if (castlestone != nullptr && !(castlestone->hasCollided_)) { 138 castlestone->hasCollided_ = true; 139 reachedLvlEndState_++; 140 141 } 116 142 117 143 return true; … … 119 145 120 146 121 122 void SOBFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode) 123 { 124 SUPER(SOBFigure, XMLPort, xmlelement, mode); 125 126 } 127 128 147 //Self implemented sign function that returns either 1 or -1 (and never 0) 129 148 int SOBFigure::sgn(float x) { 130 131 149 if (x < 0.0) return -1; 132 150 return 1; 133 151 } 134 152 153 //For those of you who don't have an idea: the tick function is called about 50 times/sec 135 154 void SOBFigure::tick(float dt) 136 155 { 137 156 SUPER(SOBFigure, tick, dt); 138 157 158 159 bool inputAllowed = true; 160 161 //the particle spawner that generates the fire from the backpack when pressed 139 162 if (particlespawner_ == NULL) { 140 163 for (WorldEntity* object : this->getAttachedObjects()) 141 164 { 142 if (object->isA(Class(ParticleSpawner)))165 if (object->isA(Class(ParticleSpawner))) 143 166 particlespawner_ = object; 144 145 } 146 147 } 148 149 150 151 152 153 154 if (firePressed_ == false) { 155 gravityAcceleration_ = 350.0; 156 157 } 158 159 if (hasLocalController()) 160 { 161 Vector3 velocity = getVelocity(); 162 Vector3 position = getPosition(); 163 164 if (!predead_) 165 velocity.y = 0; 166 if (position.z < -100) { 167 dead_ = true; 168 169 } 170 171 if (dead_) { 172 velocity.x = 0; 173 velocity.z = 0; 174 setVelocity(velocity); 175 SOB* SOBGame = orxonox_cast<SOB*>(getGametype()); 176 if (firePressed_) 177 SOBGame->restart(); 178 return; 179 } 180 181 182 int maxvelocity_x = 100; 183 int speedAddedPerTick = 5; 184 int camMaxOffset = 25; 185 186 timeSinceLastFire_ += dt; 187 lastSpeed_z = velocity.z; 167 } 168 } 169 170 171 //Behavior on level end - this is like described above for the movement from the player when hit the flag. He moves then into the castle 172 if (reachedLvlEndState_ != 0) { 173 timeCounter_+= dt; 174 inputAllowed = false; 175 } 176 if (reachedLvlEndState_ == 1 && timeCounter_ >= 1.5) { 177 timeCounter_ = 0; 178 reachedLvlEndState_ = 2; 179 } 180 181 182 //if input blocked, then cancel every movement operation 183 if (!inputAllowed) { 184 moveUpPressed_ = false; 185 moveDownPressed_ = false; 186 moveLeftPressed_ = false; 187 moveRightPressed_ = false; 188 } 189 190 //set the gravityto standard 350 191 if (firePressed_ == false) { 192 gravityAcceleration_ = 350.0; 193 194 } 195 196 if (hasLocalController()) 197 { 198 Vector3 velocity = getVelocity(); 199 Vector3 position = getPosition(); 200 201 if (!predead_) 202 velocity.y = 0; 203 if (position.z < -100) { 204 dead_ = true; 205 } 206 207 208 if (dead_) { 209 velocity.x = 0; 210 velocity.z = 0; 211 setVelocity(velocity); 212 SOB* SOBGame = orxonox_cast<SOB*>(getGametype()); 213 if (firePressed_) 214 SOBGame->restart(); 215 return; 216 } 217 218 219 int maxvelocity_x = 100; 220 int speedAddedPerTick = 5; 221 int camMaxOffset = 25; 222 223 timeSinceLastFire_ += dt; 224 lastSpeed_z = velocity.z; 188 225 189 226 190 227 191 228 //Handle the rocket fire from the jetpack 192 if (velocity.z > 40) 193 particlespawner_->setVisible(true); 194 else 195 particlespawner_->setVisible(false); 229 if (velocity.z > 40) 230 particlespawner_->setVisible(true); 231 else 232 particlespawner_->setVisible(false); 233 196 234 197 235 //If player hits space and does not move in z-dir 198 if (firePressed_ && isColliding_ && std::abs(velocity.z) < 0.1 && std::abs(lastSpeed_z) < 0.1) {199 gravityAcceleration_ = 100.0;236 if (inputAllowed && firePressed_ && isColliding_ && std::abs(velocity.z) < 0.1 && std::abs(lastSpeed_z) < 0.1) { 237 gravityAcceleration_ = 100.0; 200 238 velocity.z = 110; //150 201 239 } 202 203 // rotate(1,getOrientation()* WorldEntity::FRONT)204 240 205 241 206 242 //Left-right movement with acceleration 207 243 float rot = getOrientation().getRoll().valueDegrees(); 208 orxout() << rot << endl;209 244 if (moveRightPressed_) { 210 245 if (!(rot < 5.0 && -5.0 < rot)) 211 246 setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() - sgn(rot)*dt*Radian(6)); 212 213 247 214 248 if (std::abs(velocity.x) < maxvelocity_x) { … … 230 264 231 265 266 //Again another EndOfLevel behavior 267 if (reachedLvlEndState_ == 1) 268 velocity.x = -2; 269 if (reachedLvlEndState_ == 2) 270 velocity.x = 30; 271 if (reachedLvlEndState_ == 3) { 272 velocity.x = 0; 273 velocity.y = 20; 274 } 275 if (reachedLvlEndState_ == 4) { 276 lvlEnded_ = true; 277 dead_ = true; 278 } 279 280 //velocity = acc. * time 232 281 velocity.z -= gravityAcceleration_*dt; 233 282 setVelocity(velocity); 234 283 235 284 236 //Camera operation 285 //Camera operation - the camera should always follow the player in a specific region 237 286 Camera* cam = getCamera(); 238 287 Vector3 campos = cam->getPosition(); … … 252 301 } 253 302 254 // Move through the left and right screen boundaries 255 256 //setPosition(position); 257 258 // Reset key variables 303 304 305 // Reset key variables 259 306 moveUpPressed_ = false; 260 307 moveDownPressed_ = false; 261 308 moveLeftPressed_ = false; 262 309 moveRightPressed_ = false; 263 moveDownPressed_ = false; 310 264 311 isColliding_ = false; 265 312 … … 270 317 271 318 272 319 //The following functions read the input of the player and then set the bools for the movement 273 320 void SOBFigure::moveFrontBack(const Vector2& value) 274 321 { … … 299 346 } 300 347 301 302 303 304 305 348 void SOBFigure::boost(bool boost) 306 349 { 307 350 firePressed_ = boost; 308 351 } 309 } 352 353 354 }
Note: See TracChangeset
for help on using the changeset viewer.