void EnemyEntity::SetHurt(Vector2 pos)
{
    AnimatedSprite2D* animatesprite = GetComponent<AnimatedSprite2D>();
    if(animatesprite->GetAnimation()!= "hurt")
    {
        animatesprite->SetAnimation("hurt", LM_FORCE_CLAMPED);
        isBusy = true;
        CurrentTime = 0;
        life-=2;
        if(life >= 0)
        {
            timeBusy = 0.26f;
            RigidBody2D* body = GetComponent<RigidBody2D>();
            if(pos.x_>node_->GetPosition2D().x_)
                body->ApplyLinearImpulse(Vector2(-0.5f,0.5f),node_->GetPosition2D(),true );
            else
                body->ApplyLinearImpulse(Vector2(0.5f,0.5f),node_->GetPosition2D(),true );
        }
        else{
            isDead = true;
            animatesprite->SetAnimation("dead", LM_FORCE_CLAMPED);
            timeBusy = 2.0f;
            node_->RemoveComponent<RigidBody2D>();
        }

    }
}
void EnemyEntity::SetAtack()
{
    AnimatedSprite2D* animatesprite = GetComponent<AnimatedSprite2D>();
    if(animatesprite->GetAnimation()!= "atack")
    {
        animatesprite->SetAnimation("atack", LM_FORCE_CLAMPED);
        isBusy = true;
        isCharge = true;
        CurrentTime = 0;
        timeBusy = 1.0f;
        timeChargue = 0.8f;
    }
}
void EnemyEntity::Update(float timeStep)
{
    if(isBusy && isDead)
    {
        CurrentTime+= timeStep;
        if(CurrentTime > timeChargue)
        {
            using namespace EnemyDied;
            VariantMap& eventData = GetEventDataMap();
            eventData[P_NODE] = node_;
            SendEvent(E_ENEMYDIED, eventData);
            isBusy = false;
        }
        return;
    }

    if(isDead)
        return;

    UpdateCast();
    RigidBody2D* body = GetComponent<RigidBody2D>();
    float y = body->GetLinearVelocity().y_;

    if(isBusy)
    {
        CurrentTime+= timeStep;
        if(isCharge)
        {
            if(CurrentTime > timeChargue)
            {
                isCharge = false;
                Shoot();
                isCooldDown = true;
                timeCoolDown = 1;
            }
        }
        if(CurrentTime > timeBusy)
        {
            isBusy = false;
            CurrentTime = 0;
        }
    }
    else
    {
        AnimatedSprite2D* animatesprite = GetComponent<AnimatedSprite2D>();
        if(isCooldDown)
        {
            if(animatesprite->GetAnimation()!= "idle")
            {
                animatesprite->SetAnimation("idle", LM_DEFAULT);
            }
            CurrentTime+= timeStep;
            if(CurrentTime > timeCoolDown)
                isCooldDown = false;
        }
        else
        {
            if(animatesprite->GetAnimation()!= "walk")
            {
                animatesprite->SetAnimation("walk", LM_DEFAULT);
            }
            body->SetLinearVelocity(Vector2::ZERO);
            body->SetLinearVelocity(Vector2(vel.x_, y));
        }
    }
}