- Timestamp:
- May 4, 2017, 3:17:59 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/SuperOrxoBros_FS17/src/modules/superorxobros/SOBFigure.cc
r11405 r11412 41 41 42 42 #include "SOBMushroom.h" 43 #include "SOBGumba.h" 43 44 #include "SOB.h" 45 #include "SOBFlagstone.h" 44 46 45 47 namespace orxonox … … 66 68 pitch_ = 0.0; 67 69 70 predead_ = false; 68 71 dead_ = false; 69 72 gotPowerUp_ = false; … … 79 82 isColliding_ = true; 80 83 SOBMushroom* mush = orxonox_cast<SOBMushroom*>(otherObject); 81 // ADD ANOTHER OBJECT FOR BAD GUMBAS AND REMOVE POWERUP OR KILL PLAYER ON COLLISION WITHOUT Z-ACCELERATION 84 SOBGumba* gumba = orxonox_cast<SOBGumba*>(otherObject); 85 SOBFlagstone* flagstone = orxonox_cast<SOBFlagstone*>(otherObject); 86 82 87 if (mush != nullptr && !(mush->hasCollided_)) { 83 88 otherObject->destroyLater(); … … 87 92 mush->hasCollided_ = true; 88 93 89 } 90 91 return true; 92 } 93 94 95 96 void SOBFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode) 97 { 98 SUPER(SOBFigure, XMLPort, xmlelement, mode); 99 100 } 101 102 103 104 void SOBFigure::tick(float dt) 105 { 106 SUPER(SOBFigure, tick, dt); 107 108 if (particlespawner_ == NULL) { 109 for (WorldEntity* object : this->getAttachedObjects()) 110 { 111 if (object->isA(Class(ParticleSpawner))) 112 particlespawner_ = object; 113 114 } 115 116 } 117 118 119 120 121 122 123 if (firePressed_ == false) { 124 gravityAcceleration_ = 350.0; 125 126 } 127 128 if (hasLocalController()) 129 { 130 Vector3 velocity = getVelocity(); 131 Vector3 position = getPosition(); 132 133 134 if (position.z < -100) 135 dead_ = true; 136 137 if (dead_) { 138 velocity.x = 0; 139 velocity.z = 0; 140 setVelocity(velocity); 141 return; 142 } 143 144 145 int maxvelocity_x = 100; 146 int speedAddedPerTick = 5; 147 int camMaxOffset = 25; 148 149 timeSinceLastFire_ += dt; 150 lastSpeed_z = velocity.z; 94 } else if (gumba != nullptr && !(gumba->hasCollided_)) { 95 96 if (getVelocity().z >= -20) { 97 Vector3 vel = getVelocity(); 98 vel.y = -80; 99 vel.z = 200; 100 setVelocity(vel); 101 predead_=true; 102 } else { 103 gumba->destroyLater(); 104 gumba->hasCollided_ = true; 105 SOB* SOBGame = orxonox_cast<SOB*>(getGametype()); 106 SOBGame->addGumba(); 107 108 109 } 110 } 111 112 if (flagstone != nullptr && !(flagstone->hasCollided_)) { 113 flagstone->hasCollided_ = true; 114 115 } 116 117 return true; 118 } 119 120 121 122 void SOBFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode) 123 { 124 SUPER(SOBFigure, XMLPort, xmlelement, mode); 125 126 } 127 128 129 int SOBFigure::sgn(float x) { 130 131 if (x < 0.0) return -1; 132 return 1; 133 } 134 135 void SOBFigure::tick(float dt) 136 { 137 SUPER(SOBFigure, tick, dt); 138 139 if (particlespawner_ == NULL) { 140 for (WorldEntity* object : this->getAttachedObjects()) 141 { 142 if (object->isA(Class(ParticleSpawner))) 143 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; 151 188 152 189 153 190 154 191 //Handle the rocket fire from the jetpack 155 156 157 158 192 if (velocity.z > 40) 193 particlespawner_->setVisible(true); 194 else 195 particlespawner_->setVisible(false); 159 196 160 197 //If player hits space and does not move in z-dir 161 162 198 if (firePressed_ && isColliding_ && std::abs(velocity.z) < 0.1 && std::abs(lastSpeed_z) < 0.1) { 199 gravityAcceleration_ = 100.0; 163 200 velocity.z = 110; //150 164 201 } … … 169 206 //Left-right movement with acceleration 170 207 float rot = getOrientation().getRoll().valueDegrees(); 208 orxout() << rot << endl; 171 209 if (moveRightPressed_) { 172 if (rot < 0.0) 173 setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() + dt*Radian(6)); 210 if (!(rot < 5.0 && -5.0 < rot)) 211 setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() - sgn(rot)*dt*Radian(6)); 212 174 213 175 214 if (std::abs(velocity.x) < maxvelocity_x) { 176 215 velocity.x += speedAddedPerTick; 177 216 178 179 180 181 182 // if (pitch_ > 0.0) {183 // pitch -= turn_fac*dt);184 // }185 217 } 186 218 } else if (moveLeftPressed_) { 187 if (rot >= 0.0) 188 setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() + dt*Radian(6)); 219 if (!(abs(rot) > 175.0 )) 220 setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() + sgn(rot)*dt*Radian(6)); 221 222 189 223 190 224 if (std::abs(velocity.x) < maxvelocity_x) {
Note: See TracChangeset
for help on using the changeset viewer.