void BounceCollisionSubSystem::Update( Actor& actor, double DeltaTime ) { Opt<BounceCollisionComponent> bounceCC = actor.Get<BounceCollisionComponent>(); if (mShotCollisionSubSystem.IsValid()&&bounceCC->IsUseShotCollision()) { mShotCollisionSubSystem->Update(actor, DeltaTime); } }
void BounceCollisionSubSystem::Collide( Actor& actor, Actor& other ) { Opt<BounceCollisionComponent> bounceCC = actor.Get<BounceCollisionComponent>(); if (mShotCollisionSubSystem.IsValid() && bounceCC->IsUseShotCollision()) { mShotCollisionSubSystem->Collide(actor, other); } //TODO: for now its wallcc should be a bouncableComponent or this should be a collision class Opt<WallCollisionComponent> wallCC = other.Get<WallCollisionComponent>(); if( !wallCC.IsValid() ) { return; } Opt<IPositionComponent> positionC = actor.Get<IPositionComponent>(); Opt<IMoveComponent> moveC = actor.Get<IMoveComponent>(); Opt<IPositionComponent> otherPositionC = other.Get<IPositionComponent>(); Opt<ICollisionComponent> otherCC = other.Get<ICollisionComponent>(); if ( !otherPositionC.IsValid() || !otherCC.IsValid() || !positionC.IsValid() ) { return; } double const dx = otherPositionC->GetX() - positionC->GetX(); double const dy = otherPositionC->GetY() - positionC->GetY(); const double h = moveC->GetHeading(); double c = cos( h ); double s = sin( h ); double at = atan2( s, c ); double at2 = atan2( c, s ); if( std::abs( dx ) > std::abs( dy ) ) { c *= -1; } else if( std::abs( dx ) < std::abs( dy ) ) { s *= -1; } moveC->SetHeading( atan2( s, c ) ); moveC->GetSpeed().mBase.Set( moveC->GetSpeed().mBase.Get() * ( 1.0 - bounceCC->GetSpeedLossPercent() ) ); if (bounceCC->GetHitCountToKill() > 0) { bounceCC->SetHitCountToKill(bounceCC->GetHitCountToKill() - 1); } if (bounceCC->IsResetActorsCollidedOnBounce()) { bounceCC->ResetDamagedActorIds(); } }