示例#1
0
void LocationManager::goTo(QString destination) {

    if (destination.startsWith("@")) {
        // remove '@' and go to user
        goToUser(destination.remove(0, 1));
        return;
    }

    if (destination.startsWith("#")) {
        // remove '#' and go to named place
        goToPlace(destination.remove(0, 1));
        return;
    }

    // go to coordinate destination or to Username
    if (!goToDestination(destination)) {
        destination = QString(QUrl::toPercentEncoding(destination));

        JSONCallbackParameters callbackParams;
        callbackParams.jsonCallbackReceiver = this;
        callbackParams.jsonCallbackMethod = "goToAddressFromResponse";
        AccountManager::getInstance().authenticatedRequest(GET_ADDRESSES.arg(destination),
                                                           QNetworkAccessManager::GetOperation,
                                                           callbackParams);
    }
}
示例#2
0
void Enemy::aggressive(btDiscreteDynamicsWorld* dynamicsWorld, vec3* playerPosition, bool &isPlayerDead)
{
	if (seesPlayer(dynamicsWorld, playerPosition))
	{
		lastSeenPlayerPosition.x = playerPosition->x;
		lastSeenPlayerPosition.y = playerPosition->y;
		lastSeenPlayerPosition.z = playerPosition->z;
		seeing_count = 0;
	}
	goToPlace(&lastSeenPlayerPosition);

	if (abs(position.x - lastSeenPlayerPosition.x) <= 0.3f && abs(position.z - lastSeenPlayerPosition.z) <= 0.3f && seesPlayer(dynamicsWorld, playerPosition) == false || seeing_count >= 200)
	{
		seeing_count = 0;
		model->setAnimation(walk);
		state = State::WALKING;
		return;
	}

	seeing_count++;


	if (distanceBetween2Points(position.x, position.z, playerPosition->x, playerPosition->z) < shot_distance && seesPlayer(dynamicsWorld, playerPosition) && shotCount == 0)
	{
		rigidBody->setLinearVelocity(btVector3(0, 0, 0));
		if (isPointing == false)
		{
			isPointing = true;
			model->setAnimation(holdWeapon);
		}
		shot(dynamicsWorld, playerPosition, isPlayerDead);
		shotCount++;
	}
	else
	{
		if (shotCount == shot_anim_length && (distanceBetween2Points(position.x, position.z, playerPosition->x, playerPosition->z) > shot_distance || seesPlayer(dynamicsWorld, playerPosition) == false))
		{
			if (isPointing == true)
			{
				isPointing = false;
				model->setAnimation(run);
			}
			movement();
		}

		shotCount++;
		if (shotCount == breakBetweenShots)
			shotCount = 0;
	}
}
示例#3
0
void LocationManager::goTo(QString destination) {
    const QString USER_DESTINATION_TYPE = "user";
    const QString PLACE_DESTINATION_TYPE = "place";
    const QString OTHER_DESTINATION_TYPE = "coordinate_or_username";
    
    if (destination.startsWith("@")) {
        // remove '@' and go to user
        QString destinationUser = destination.remove(0, 1);
        UserActivityLogger::getInstance().wentTo(USER_DESTINATION_TYPE, destinationUser);
        goToUser(destinationUser);
        return;
    }

    if (destination.startsWith("#")) {
        // remove '#' and go to named place
        QString destinationPlace = destination.remove(0, 1);
        UserActivityLogger::getInstance().wentTo(PLACE_DESTINATION_TYPE, destinationPlace);
        goToPlace(destinationPlace);
        return;
    }

    // go to coordinate destination or to Username
    if (!goToDestination(destination)) {
        destination = QString(QUrl::toPercentEncoding(destination));
        UserActivityLogger::getInstance().wentTo(OTHER_DESTINATION_TYPE, destination);
        
        JSONCallbackParameters callbackParams;
        callbackParams.jsonCallbackReceiver = this;
        callbackParams.jsonCallbackMethod = "goToAddressFromResponse";
        callbackParams.errorCallbackReceiver = this;
        callbackParams.errorCallbackMethod = "handleAddressLookupError";
        
        AccountManager::getInstance().authenticatedRequest(GET_ADDRESSES.arg(destination),
                                                           QNetworkAccessManager::GetOperation,
                                                           callbackParams);
    }
}
示例#4
0
void Enemy::aware(btDiscreteDynamicsWorld* dynamicsWorld, vec3* playerPosition, const string playerState)
{
	if (seesPlayer(dynamicsWorld, playerPosition))
	{
		lastSeenPlayerPosition.x = playerPosition->x;
		lastSeenPlayerPosition.y = playerPosition->y;
		lastSeenPlayerPosition.z = playerPosition->z;
		model->setAnimation(run);
		state = State::AGGRESSIVE;
		return;
	}
	else if (hearsPlayer(playerPosition, playerState))
	{
		lastSeenPlayerPosition.x = playerPosition->x;
		lastSeenPlayerPosition.y = playerPosition->y;
		lastSeenPlayerPosition.z = playerPosition->z;
		seeing_count = 0;
	}
	goToPlace(&lastSeenPlayerPosition);

	if (abs(position.x - lastSeenPlayerPosition.x) <= 0.3f && abs(position.z - lastSeenPlayerPosition.z) <= 0.3f && seesPlayer(dynamicsWorld, playerPosition) == false || seeing_count == 200)
	{
		model->setAnimation(walk);
		state = State::WALKING;
	}

	if (nearToCollision(dynamicsWorld))
	{
		direction.x += 0.3f;
		direction.z -= 0.3f;
	}

	seeing_count++;
	movement();

}