void AccelerationSystem::Update( double DeltaTime )
{
    for( ActorList_t::iterator it = mScene.GetActors().begin(), e = mScene.GetActors().end(); it != e; ++it )
    {
        Actor& actor = **it;
        Opt<IMoveComponent> moveC = actor.Get<IMoveComponent>();
        if ( !moveC.IsValid() )
        {
            continue;
        }
        Opt<IAccelerationComponent> accelerationC = actor.Get<IAccelerationComponent>();
        if ( !accelerationC.IsValid() )
        {
            continue;
        }

        double speed = moveC->GetSpeed().mBase.Get();
        double acceleration = accelerationC->GetAcceleration();
        speed += acceleration * DeltaTime;
        speed = ( acceleration > 0.0 ) ?
                std::min( speed, accelerationC->GetMaxSpeed() ) :
                std::max( speed, accelerationC->GetMinSpeed() );
        moveC->GetSpeed().mBase.Set( speed );
    }

}
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();
    }
}
Beispiel #3
0
std::auto_ptr<RotateMessage> RotateMessageSenderSystem::GenerateRotateMessage(Actor &actor)
{
    Opt<IRotateComponent> rotateC = actor.Get<IRotateComponent>();
    if (!rotateC.IsValid())
    {
        return std::auto_ptr<RotateMessage>();
    }
    std::auto_ptr<RotateMessage> rotateMsg(new RotateMessage);
    rotateMsg->mActorGUID=actor.GetGUID();
    rotateMsg->mSpeed=rotateC->GetSpeed();
    rotateMsg->mRotating=rotateC->IsRotating();
    return rotateMsg;
}