コード例 #1
0
void RegularBattleScene::onHpChange(int spot, int)
{
    info.animatedSpot = spot;
    if (isPlayer(spot) && info.percentage[spot]) {
        info.animatedValue = gui.bars[spot]->value() * data()->poke(spot).totalLife() / 100;
    } else {
        info.animatedValue = gui.bars[spot]->value();
    }
    pause();
    animateHpBar();
}
コード例 #2
0
void RegularBattleScene::animateHpBar()
{
    int spot = info.animatedSpot;

    if (spot == -1) {
        return;
    }

    int current = info.animatedValue;

    const int goal = data()->poke(spot).life();

    QSettings s;
    if (!s.value("Battle/AnimateHp").toBool()) {
        updateHp(spot);
        info.animatedSpot = -1;
        unpause();
        return;
    }

    if (goal == current) {
        info.animatedSpot = -1;
        QTimer::singleShot(120, this, SLOT(unpause()));
        return;
    }

    /* We deal with true HP. 30 msec per 3 hp / % */
    bool trueHP = isPlayer(spot);
    int incr = trueHP ? 3 : 1;

    int newHp = goal < current ? std::max(goal, current - incr) : std::min(goal, current+incr);
    info.animatedValue = newHp;

    updateHp(spot, newHp);

    //Recursive call to update the hp bar 30msecs later
    QTimer::singleShot(30, this, SLOT(animateHpBar()));
}