Example #1
0
void Entity::hurtMe( int iHurtValue ) { 
    if(m_isDead) {
        return;
    }
    CCLOG("hurtMe iHurtValue=%d, HP=%d", iHurtValue, getiHP());
    /* 最小伤害值为1 */
    if(iHurtValue <= getiDefense()) {
        iHurtValue = 1;
    }

    int iCurHP = getiHP();      /* 当前HP */
    int iAfterHP = iCurHP - iHurtValue; /* 被攻击后的HP */

	onHurt(iHurtValue);

    if(iAfterHP > 0) {
        setiHP(iAfterHP);
    }
    else {
        CCLOG("onDead");
        m_isDead = true;
        /* 死亡 */
        onDead();
    }

}
Example #2
0
bool Hurtable::hurt(int d)
{
    if (hasFlags(EntityFlags::INVUNERABLE) || hurtFlash > 0.f)
        return false;

    if (tmd->isAnimated() && tmd->hasAnimation("hurt"))
    {
        anim.play("hurt", [&]()
        {
            anim.play("idle");
        });
    }
    else
    {
        hurtFlash = 0.14f;
    }

    setHealth(getHealth() - d);
    onHurt(d);

    return true;
}