- Timestamp:
- Apr 4, 2019, 4:37:19 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/BallGun/BallProjectile.cc
r12254 r12281 38 38 #include "tools/ParticleInterface.h" 39 39 #include "Scene.h" 40 #include "core/command/Executor.h" 41 #include "util/Convert.h" 40 42 41 43 namespace orxonox … … 43 45 RegisterClass(BallProjectile); 44 46 45 BallProjectile::BallProjectile(Context* context) : Projectile(context)47 BallProjectile::BallProjectile(Context* context) : BillboardProjectile(context) 46 48 { 47 49 RegisterObject(BallProjectile); 48 49 this->particles_ = nullptr; 50 orxout() << "It's a bird, it's a plane' it's a BallParticle..." << endl; 51 this->textureIndex_ = 1; 52 this->setMass(0.1f); 53 this->maxTextureIndex_ = 8; 50 54 this->setDestroyAfterCollision(false); //I want the ball to bounce, not to be destroyed 51 55 … … 53 57 } 54 58 55 BallProjectile::~BallProjectile()59 void BallProjectile::registerVariables() 56 60 { 57 if (this->isInitialized() && this->particles_) 58 { 59 this->detachOgreObject(this->particles_->getParticleSystem()); 60 delete this->particles_; 61 } 61 registerVariable(this->materialBase_); 62 } 63 64 /** 65 @brief 66 Set the material. 67 @param material 68 The name of the material. Material names with 1 to 8 appended must exist. 69 */ 70 void BallProjectile::setMaterial(const std::string& material) 71 { 72 this->materialBase_ = material; 73 74 BillboardProjectile::setMaterial(material + multi_cast<std::string>(this->textureIndex_)); 75 } 76 77 /** 78 @brief 79 Change the texture. 80 */ 81 void BallProjectile::changeTexture() 82 { 83 this->textureIndex_++; 84 if (this->textureIndex_ > this->maxTextureIndex_) 85 this->textureIndex_ = 1; 86 87 this->setMaterial(this->materialBase_); 62 88 } 63 89 … … 68 94 Vector3 contactPosition = this->getPosition(); 69 95 70 if (positionOtherObject.y < 0) { 71 this->destroy(); 72 } 73 else { 96 //if (positionOtherObject.y < 0) { 97 //this.destroy() 98 //} 99 //else { 100 74 101 int distance_X = positionOtherObject.x - contactPosition.x; 102 int distance_Y = positionOtherObject.y - contactPosition.y; 75 103 76 104 if (distance_X < 0) 77 distance_X = -distance_X; 78 79 int distance_Y = positionOtherObject.y - contactPosition.y; 105 distance_Y = -distance_Y; 106 80 107 81 108 if (distance_Y < 0) 82 distance_ Y = -distance_Y;109 distance_X = -distance_X; 83 110 84 111 if (distance_X < distance_Y) … … 90 117 velocity.y = -velocity.y; 91 118 } 92 }119 //} 93 120 } 94 95 121 96 122 /** … … 110 136 */ 111 137 138 /* 139 bool BallProjectile::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) 140 { 141 orxout() << "I collided against something" << endl; 142 return this->processCollision(otherObject, contactPoint, cs); 143 } 144 */ 145 146 bool BallProjectile::processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape*) 147 { 112 148 113 bool BallProjectile::processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs)114 {115 if (GameMode::isMaster())116 {149 orxout() << "wanna bounce..." << endl; 150 bool result = BasicProjectile::processCollision(otherObject, contactPoint, cs); 151 Bounce(otherObject, contactPoint, cs); 152 orxout() << "BOUNCED!" << endl; 117 153 118 Pawn* victim = orxonox_cast<Pawn*>(otherObject); // If otherObject isn't a Pawn, then victim is nullptr 119 120 WorldEntity* entity = orxonox_cast<WorldEntity*>(this); 121 assert(entity); // The projectile must not be a WorldEntity. 122 123 // If visual effects after destruction cause problems, put this block below the effects code block 124 if (victim) 125 { 126 victim->hit(this->getShooter(), contactPoint, cs, this->getDamage(), this->getHealthDamage(), this->getShieldDamage()); 127 victim->startShieldRechargeCountdown(); 128 } 129 130 // Visual effects for being hit, depending on whether the shield is hit or not 131 if (this->getShooter()) // If the owner does not exist (anymore?), no effects are displayed. 132 { 133 // Damping and explosion effect is only played if the victim is no Pawn (see cast above) 134 // or if the victim is a Pawn, has no shield left, is still alive and any damage goes to the health 135 if (!victim || (victim && !victim->hasShield() && victim->getHealth() > 0.0f && (this->getDamage() > 0.0f || this->getHealthDamage() > 0.0f))) 136 { 137 { 138 ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext()); 139 effect->setPosition(entity->getPosition()); 140 effect->setOrientation(entity->getOrientation()); 141 effect->setDestroyAfterLife(true); 142 effect->setSource("Orxonox/explosion3"); 143 effect->setLifetime(2.0f); 144 } 145 // Second effect with same condition 146 { 147 ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext()); 148 effect->setPosition(entity->getPosition()); 149 effect->setOrientation(entity->getOrientation()); 150 effect->setDestroyAfterLife(true); 151 effect->setSource("Orxonox/smoke4"); 152 effect->setLifetime(3.0f); 153 } 154 } 155 156 // victim->isAlive() is not false until the next tick, so getHealth() > 0 is used instead 157 if (victim && victim->hasShield() && (this->getDamage() > 0.0f || this->getShieldDamage() > 0.0f) && victim->getHealth() > 0.0f) 158 { 159 ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext()); 160 effect->setDestroyAfterLife(true); 161 effect->setSource("Orxonox/Shield"); 162 effect->setLifetime(0.5f); 163 victim->attach(effect); 164 } 165 } 166 167 Bounce(otherObject, contactPoint, cs); 168 169 return true; 170 } 171 return false; 154 return result; 172 155 } 173 156 }
Note: See TracChangeset
for help on using the changeset viewer.