Пример #1
0
void PaintElementPath::setInitialBounds (int w, int h)
{
    String s;

    int x = randomPos (w);
    int y = randomPos (h);

    s << "s "
      << x << " " << y << " l "
      << (x + 30) << " " << (y + 50) << " l "
      << (x - 30) << " " << (y + 50) << " x";

    restorePathFromString (s);
}
Пример #2
0
void Monster::update()
{
    Being::update();

    if (mKillStealProtectedTimeout.justFinished())
        mOwner = NULL;

    // If dead, remove it
    if (mAction == DEAD)
    {
        if (mDecayTimeout.expired())
            GameState::enqueueRemove(this);

        return;
    }

    if (mSpecy->getUpdateCallback().isValid())
    {
        Script *script = ScriptManager::currentState();
        script->setMap(getMap());
        script->prepare(mSpecy->getUpdateCallback());
        script->push(this);
        script->execute();
    }

    // Cancel the rest when we are currently performing an attack
    if (!mAttackTimeout.expired())
        return;

    refreshTarget();

    if (!mTarget)
    {
        // We have no target - let's wander around
        if (mStrollTimeout.expired() && getPosition() == getDestination())
        {
            if (mKillStealProtectedTimeout.expired())
            {
                unsigned range = mSpecy->getStrollRange();
                if (range)
                {
                    Point randomPos(rand() % (range * 2 + 1)
                                    - range + getPosition().x,
                                    rand() % (range * 2 + 1)
                                    - range + getPosition().y);
                    // Don't allow negative destinations, to avoid rounding
                    // problems when divided by tile size
                    if (randomPos.x >= 0 && randomPos.y >= 0)
                        setDestination(randomPos);
                }
                mStrollTimeout.set(10 + rand() % 10);
            }
        }
    }

    if (mAction == ATTACK)
        processAttack();
}
Пример #3
0
void Spider::restart( const QList<KCard*> & cards )
{
    m_pilesWithRuns.clear();

    // make the redeal piles visible
    for (int i = 0; i < 5; ++i )
        redeals[i]->setVisible( true );

    // make the leg piles invisible
    for (int i = 0; i < 8; ++i )
        legs[i]->setVisible( false );

    recalculatePileLayouts();

    m_leg = 0;
    m_redeal = 0;

    QList<KCard*> cardList = cards;

    int column = 0;
    // deal face down cards (5 to first 4 piles, 4 to last 6)
    for ( int i = 0; i < 44; ++i )
    {
        addCardForDeal( stack[column], cardList.takeLast(), m_stackFaceup == 1, randomPos() );
        column = (column + 1) % 10;
    }
    // deal face up cards, one to each pile
    for ( int i = 0; i < 10; ++i )
    {
        addCardForDeal( stack[column], cardList.takeLast(), true, randomPos() );
        column = (column + 1) % 10;
    }
    // deal the remaining cards into 5 'redeal' piles
    for ( int column = 0; column < 5; ++column )
        for ( int i = 0; i < 10; ++i )
            addCardForDeal( redeals[column], cardList.takeLast(), false, randomPos() );

    startDealAnimation();

    emit newCardsPossible(true);
}
Пример #4
0
void MonsterComponent::update(Entity &entity)
{
    if (mKillStealProtectedTimeout.justFinished())
        mOwner = nullptr;

    auto *beingComponent = entity.getComponent<BeingComponent>();

    // If dead, remove it
    if (beingComponent->getAction() == DEAD)
    {
        if (mDecayTimeout.expired())
            GameState::enqueueRemove(&entity);

        return;
    }

    if (mSpecy->getUpdateCallback().isValid())
    {
        Script *script = ScriptManager::currentState();
        script->prepare(mSpecy->getUpdateCallback());
        script->push(&entity);
        script->execute(entity.getMap());
    }

    refreshTarget(entity);

    // Cancel the rest when we have a target
    if (entity.getComponent<CombatComponent>()->getTarget())
        return;

    const Point &position =
            entity.getComponent<ActorComponent>()->getPosition();

    // We have no target - let's wander around
    if (mStrollTimeout.expired() &&
            position == beingComponent->getDestination())
    {
        if (mKillStealProtectedTimeout.expired())
        {
            unsigned range = mSpecy->getStrollRange();
            if (range)
            {
                Point randomPos(rand() % (range * 2 + 1) - range + position.x,
                                rand() % (range * 2 + 1) - range + position.y);
                // Don't allow negative destinations, to avoid rounding
                // problems when divided by tile size
                if (randomPos.x >= 0 && randomPos.y >= 0)
                    beingComponent->setDestination(entity, randomPos);
            }
            mStrollTimeout.set(10 + rand() % 10);
        }
    }
}