Beispiel #1
0
void PlayerController::updateMovementDirection(const glm::vec3& dir,
                                               const glm::vec3& rawdirection) {
    if (_currentActivity == nullptr) {
        direction = dir;
        setMoveDirection(rawdirection);
    }
}
Beispiel #2
0
Ship::Ship(const string& name, const string& collision, Sprite* body)
: PhysicNode(collision)
, m_name(name)
, m_ship(SpritePtr(body))
{
    setCamera(Painter::GetInstance()->getSceneCamera());
	setMoveDirection(vec2d(0.0f, 1.0f));
}
Beispiel #3
0
DotMatrix::DotMatrix(byte colCount, byte rowCount)
{
	_col_count = colCount;
	_row_count = rowCount;

	_bytes_per_row = _col_count / 8;
	if (_col_count % 8)
		_bytes_per_row++;

	_bytes_length = _bytes_per_row * _row_count;

	_pScreen = (byte *) malloc(sizeof(byte) * (_bytes_length + 1));
	setMoveDirection(this->BYTE_IN_COL_POSI);
}
Beispiel #4
0
void SoldierLyzc::doMove()
{
	if (getTarget()->getStatus() == E_STATUS_DEAD)
	{
		setStatus(e_battle_status_idle);
		m_direction = 0;
		return;
	}

	if (checkDistance())
	{
		//setStatus(e_battle_tatus_attack);
		double begin = getBeginDegree();
		double end = getEndDegree();
		_currentIndex = getIndexFormDegree(begin);
		_degreeIndex = getIndexFormDegree(end);
		rotate();
	} 
	else
	{
		Coord next = getNextCoord();
		if (next.x == -1 && next.y == -1)
		{
			//setStatus(e_battle_tatus_attack);
			double begin = getBeginDegree();
			double end = getEndDegree();
			_currentIndex = getIndexFormDegree(begin);
			_degreeIndex = getIndexFormDegree(end);
			rotate();
		} 
		else
		{
			//checkBeAttack();
			if (setMoveDirection(next))
			{
				runWalkAction();
			}
			auto sc = SoldierConfig::getSoldierConfig(getType());
			auto move = MoveTo::create(1/sc->move_speed, MapHelper::convertCoordToPoint(next));
			runAction(Sequence::create(move, CallFunc::create(CC_CALLBACK_0(Soldier::doMove,this)), NULL));
			setLocalZOrder(next.y);
			setCoord(next);
		}
	}
}
Beispiel #5
0
void Logic::gameRun()
{
    gameInit();
    printResult();

    while(1)
    {
        setMoveDirection(userInput());

        checkFinish();

        if(bFinished || bWin) break;

        if(bChanged) generateRandom();
        else cout<<"invalid move!"<<endl;

        bChanged = false;

        printResult();
    }
    printResult();
    goodGame();
}
Beispiel #6
0
void IngameState::tick(float dt)
{
	autolookTimer = std::max(autolookTimer - dt, 0.f);

	auto player = game->getPlayer();
	if( player && player->isInputEnabled() )
	{
		sf::Vector2f screenSize(getWindow().getSize());
		sf::Vector2f screenCenter(screenSize / 2.f);
		sf::Vector2f mouseMove;
		if (game->hasFocus())
		{
			sf::Vector2f mousePos(sf::Mouse::getPosition(getWindow()));
			sf::Vector2f deltaMouse = (mousePos - screenCenter);
			mouseMove = sf::Vector2f(deltaMouse.x / screenSize.x, deltaMouse.y / screenSize.y);
			sf::Mouse::setPosition(sf::Vector2i(screenCenter), getWindow());

			if(deltaMouse.x != 0 || deltaMouse.y != 0)
			{
				autolookTimer = kAutoLookTime;
				if (!m_invertedY) {
					mouseMove.y = -mouseMove.y;
				}
				m_cameraAngles += glm::vec2(mouseMove.x, mouseMove.y);
				m_cameraAngles.y = glm::clamp(m_cameraAngles.y, kCameraPitchLimit, glm::pi<float>() - kCameraPitchLimit);
			}
		}

		float viewDistance = 4.f;
		switch( camMode )
		{
		case IngameState::CAMERA_CLOSE:
			viewDistance = 2.f;
			break;
		case IngameState::CAMERA_NORMAL:
			viewDistance = 4.0f;
			break;
		case IngameState::CAMERA_FAR:
			viewDistance = 6.f;
			break;
		case IngameState::CAMERA_TOPDOWN:
			viewDistance = 15.f;
			break;
		default:
			viewDistance = 4.f;
		}
		
		auto target = getWorld()->pedestrianPool.find(getWorld()->state->cameraTarget);

		if( target == nullptr )
		{
			target = player->getCharacter();
		}

		glm::vec3 targetPosition = target->getPosition();
		glm::vec3 lookTargetPosition = targetPosition;
		targetPosition += glm::vec3(0.f, 0.f, 1.f);
		lookTargetPosition += glm::vec3(0.f, 0.f, 0.5f);

		btCollisionObject* physTarget = player->getCharacter()->physObject;

		auto vehicle = ( target->type() == GameObject::Character ) ? static_cast<CharacterObject*>(target)->getCurrentVehicle() : nullptr;
		if( vehicle ) {
			auto model = vehicle->model;
			float maxDist = 0.f;
			for(auto& g : model->resource->geometries) {
				float partSize = glm::length(g->geometryBounds.center) + g->geometryBounds.radius;
				maxDist = std::max(partSize, maxDist);
			}
			viewDistance = viewDistance + maxDist;
			targetPosition = vehicle->getPosition();
			lookTargetPosition = targetPosition;
			lookTargetPosition.z += (vehicle->info->handling.dimensions.z);
			targetPosition.z += (vehicle->info->handling.dimensions.z * 1.f);
			physTarget = vehicle->physBody;

			if (!m_vehicleFreeLook)
			{
				m_cameraAngles.y = kVehicleCameraPitch;
			}

			// Rotate the camera to the ideal angle if the player isn't moving it
			float velocity = vehicle->getVelocity();
			if (autolookTimer <= 0.f && glm::abs(velocity) > kAutolookMinVelocity)
			{
				auto idealYaw = -glm::roll(vehicle->getRotation()) + glm::half_pi<float>();
				const auto idealPitch = kVehicleCameraPitch;
				if (velocity < 0.f) {
					idealYaw = glm::mod(idealYaw - glm::pi<float>(), glm::pi<float>() * 2.f);
				}
				float currentYaw = glm::mod(m_cameraAngles.x, glm::pi<float>()*2);
				float currentPitch = m_cameraAngles.y;
				float deltaYaw = idealYaw - currentYaw;
				float deltaPitch = idealPitch - currentPitch;
				if (glm::abs(deltaYaw) > glm::pi<float>()) {
					deltaYaw -= glm::sign(deltaYaw) * glm::pi<float>()*2.f;
				}
				m_cameraAngles.x += glm::sign(deltaYaw) * std::min(kMaxRotationRate * dt, glm::abs(deltaYaw));
				m_cameraAngles.y += glm::sign(deltaPitch) * std::min(kMaxRotationRate * dt, glm::abs(deltaPitch));
			}
		}

		// Non-topdown camera can orbit
		if( camMode != IngameState::CAMERA_TOPDOWN )
		{
			// Determine the "ideal" camera position for the current view angles
			auto yaw = glm::angleAxis(m_cameraAngles.x, glm::vec3(0.f, 0.f,-1.f));
			auto pitch = glm::angleAxis(m_cameraAngles.y, glm::vec3(0.f, 1.f, 0.f));
			auto cameraOffset =
					yaw * pitch * glm::vec3(0.f, 0.f, viewDistance);
			cameraPosition = targetPosition + cameraOffset;
		}
		else
		{
			cameraPosition = targetPosition + glm::vec3(0.f, 0.f, viewDistance);
		}

		glm::quat angle;

		auto camtotarget = targetPosition - cameraPosition;
		auto dir = glm::normalize(camtotarget);
		float correction = glm::length(camtotarget) - viewDistance;
		if( correction < 0.f )
		{
			float innerDist = viewDistance * 0.1f;
			correction = glm::min(0.f, correction + innerDist);
		}
		cameraPosition += dir * 10.f * correction * dt;

		auto lookdir = glm::normalize(lookTargetPosition - cameraPosition);
		// Calculate the yaw to look at the target.
		float angleYaw = glm::atan(lookdir.y, lookdir.x);
		angle = glm::quat( glm::vec3(0.f, 0.f, angleYaw) );

		// Update player with camera yaw
		if( player->isInputEnabled() )
		{
			if (player->getCharacter()->getCurrentVehicle())
			{
				player->setMoveDirection(_movement);
			}
			else
			{
				float length = glm::length(_movement);
				float movementAngle = angleYaw - M_PI/2.f;
				if (length > 0.1f)
				{
					glm::vec3 direction = glm::normalize(_movement);
					movementAngle += atan2(direction.y, direction.x);
					player->setMoveDirection(glm::vec3(1.f, 0.f, 0.f));
				}
				else
				{
					player->setMoveDirection(glm::vec3(0.f));
				}
				if (player->getCharacter()->canTurn())
				{
					player->getCharacter()->rotation =
							glm::angleAxis(movementAngle, glm::vec3(0.f, 0.f, 1.f));
				}
			}
		}
		else
		{
			player->setMoveDirection(glm::vec3(0.f));
		}

		float len2d = glm::length(glm::vec2(lookdir));
		float anglePitch = glm::atan(lookdir.z, len2d);
		angle *= glm::quat( glm::vec3(0.f, -anglePitch, 0.f) );

		// Use rays to ensure target is visible from cameraPosition
		auto rayEnd = cameraPosition;
		auto rayStart = targetPosition;
		auto to = btVector3(rayEnd.x, rayEnd.y, rayEnd.z);
		auto from = btVector3(rayStart.x, rayStart.y, rayStart.z);
		ClosestNotMeRayResultCallback ray(physTarget, from, to);

		getWorld()->dynamicsWorld->rayTest(from, to, ray);
		if( ray.hasHit() && ray.m_closestHitFraction < 1.f )
		{
			cameraPosition = glm::vec3(ray.m_hitPointWorld.x(), ray.m_hitPointWorld.y(),
							ray.m_hitPointWorld.z());
			cameraPosition += glm::vec3(ray.m_hitNormalWorld.x(), ray.m_hitNormalWorld.y(),
							ray.m_hitNormalWorld.z()) * 0.1f;
		}

		_look.position = cameraPosition;
		_look.rotation = angle;
	}
}