Example #1
0
void Player::updateDecision() {
    float temp = 0;
    b2Vec2 tempDir = b2Vec2(target.x-body->GetWorldCenter().x,target.y-body->GetWorldCenter().y);
    float up = (tempDir.x*body->GetLinearVelocity().x + tempDir.y*body->GetLinearVelocity().y);
    float down = sqrt(tempDir.x*tempDir.x+tempDir.y*tempDir.y)*sqrt(body->GetLinearVelocity().x*body->GetLinearVelocity().x+
                                                                    body->GetLinearVelocity().y*body->GetLinearVelocity().y);
    b2Vec2 velocity = body->GetLinearVelocity();
    b2Vec2 newVelocity;
    newVelocity.x = velocity.x*cos(1)+velocity.y*sin(1);
    newVelocity.y = -velocity.x*sin(1)+velocity.y*cos(1);
    float angle = acos(up/down);
    temp = acos((tempDir.x*velocity.x + tempDir.y*velocity.y)/
               (sqrt(tempDir.x*tempDir.x+tempDir.y*tempDir.y)*sqrt(velocity.x*velocity.x+velocity.y*velocity.y)));
    if(static_cast<int>(angle) != 0)
        rotateRight();
    else
        rotateStop();

    if(static_cast<int>(body->GetWorldCenter().x-target.x) == 0 &&
            static_cast<int>(body->GetWorldCenter().y-target.y) == 0)
        linearImpulse = 0;
    else
        moveUp();
    if(static_cast<unsigned>(body->GetAngle()) > 4*M_PI) {
        moveStop();
        if(!curRotState)
            moveUp();
    }
}
Example #2
0
bool MapHelperUniversal::keyPress(QKeyEvent *event)
{
    Q_UNUSED(event);
#if 0
    Q_D(MapHelperUniversal);
    switch (event->key()) {
    case Qt::Key_Q: {
        if (Qt::NoModifier == event->modifiers()) {
            move();
            qDebug() << "Move On";
        }
        else if (Qt::ShiftModifier == event->modifiers()) {
            moveStop();
            qDebug() << "Move Off";
        }
        break;
    }
    case Qt::Key_W: {
        if (Qt::NoModifier == event->modifiers()) {
            rotate();
            qDebug() << "Rotate On";
        }
        else if (Qt::ShiftModifier == event->modifiers()) {
            rotateStop();
            qDebug() << "Rotate Off";
        }
        break;
    }
    case Qt::Key_E: {
        if (Qt::NoModifier == event->modifiers()) {
            scale();
            qDebug() << "Scale On";
        }
        else if (Qt::ShiftModifier == event->modifiers()) {
            scaleStop();
            qDebug() << "Scalse Off";
        }
        break;
    }
    case Qt::Key_R: {
        if (Qt::NoModifier == event->modifiers()) {
            select();
            qDebug() << "Select On";
        }
        else if (Qt::ShiftModifier == event->modifiers()) {
            selectStop();
            qDebug() << "Select Off";
        }
        break;
    }
    case Qt::Key_T: {
        if (Qt::NoModifier == event->modifiers()) {
            edit();
            qDebug() << "Edit On";
        }
        else if (Qt::ShiftModifier == event->modifiers()) {
            editStop();
            qDebug() << "Edit Off";
        }
        break;
    }
    case Qt::Key_Y: {
        if (Qt::NoModifier == event->modifiers()) {
            create();
            qDebug() << "Create On";
        }
        else if (Qt::ShiftModifier == event->modifiers()) {
            createStop();
            qDebug() << "Create Off";
        }
        break;
    }
    case Qt::Key_A: {
        qDebug() << "Custom No On";
        d->customAction = 0;
        break;
    }
    case Qt::Key_S: {
        qDebug() << "Custom Move On";
        d->customAction = 1;
        break;
    }
    case Qt::Key_D: {
        qDebug() << "Custom Select On";
        d->customAction = 2;
        break;
    }
    case Qt::Key_F: {
        qDebug() << "Custom Edit On";
        d->customAction = 4;
        break;
    }
    case Qt::Key_G: {
        qDebug() << "Custom Create On";
        d->customAction = 3;
        break;
    }
    default:
        qDebug() << event;
        break;
    }

    QString types = "";
    foreach (MapSubHelper *sub, d->subhelpers)
        types += QString::number(sub->type()) + " ";
    qDebug() << types;
#endif

    return true;
}