示例#1
0
void TopDownRaceState::render()
{
	Display::getInstance().clear();

	if(lockOn)
	{
		track_bg->drawRotated(camera.w/2, camera.h/2, -cameraAngle, camera.x, camera.y);
		car_sprite->drawRotated(0.1*toPixels(player->m_body->GetPosition().x)-camera.x, 0.1*toPixels(player->m_body->GetPosition().y)-camera.y, M_PI - player->m_body->GetAngle()-cameraAngle, 23, 48);
	}
	else
	{
		track_bg->draw(-camera.x, -camera.y);
		car_sprite->drawRotated(0.1*toPixels(player->m_body->GetPosition().x)-camera.x, 0.1*toPixels(player->m_body->GetPosition().y)-camera.y, M_PI - player->m_body->GetAngle(), 23, 48);
	}

	if(showDebug)
	{
		font->drawText(std::string("Using fgeal ")+fgeal::VERSION+" on "+fgeal::ADAPTED_LIBRARY_NAME+" "+fgeal::ADAPTED_LIBRARY_VERSION, 4, fgeal::Display::getInstance().getHeight() - font->getHeight(), fgeal::Color::CREAM);

		font2->drawText("Linear velocity:", 25, 25, fgeal::Color::WHITE);
		sprintf(buffer, "% 5.2f, % 5.2f, % 5.2f", player->m_body->GetLinearVelocity().x, player->m_body->GetLinearVelocity().y, player->m_body->GetLinearVelocity().Length());
		font->drawText(std::string(buffer), 50, 50, fgeal::Color::WHITE);

		font2->drawText("Scalar velocity:", 25, 75, fgeal::Color::WHITE);
		sprintf(buffer, "% 5.2f", sqrt(pow(player->m_body->GetLinearVelocity().x, 2) + pow(player->m_body->GetLinearVelocity().y, 2)));
		font->drawText(std::string(buffer), 150, 75, fgeal::Color::WHITE);

		font2->drawText("Angle:", 25, 100, fgeal::Color::WHITE);
		sprintf(buffer, "% 5.2f", player->m_body->GetAngle());
		font->drawText(std::string(buffer), 65, 100, fgeal::Color::WHITE);

		font2->drawText("FPS:", 25, 125, fgeal::Color::WHITE);
		sprintf(buffer, "%d", game.getFpsCount());
		font->drawText(std::string(buffer), 55, 125, fgeal::Color::WHITE);
	}

	fgeal::rest(0.01);
}
示例#2
0
void TopDownRaceState::handlePhysics(float delta)
{
	const double forceFactorAbs = 50;

	double forceFactor = 0;
	if(Keyboard::isKeyPressed(Keyboard::KEY_ARROW_DOWN))
		forceFactor = -forceFactorAbs/2;
	else if(Keyboard::isKeyPressed(Keyboard::KEY_ARROW_UP))
	{
		forceFactor = forceFactorAbs;
		int i;
		for(i=0; i<player->m_body->GetLinearVelocity().Length() / 50;i++)
			forceFactor *= 1.5;
	}

	float angle = 0;
	if(Keyboard::isKeyPressed(Keyboard::KEY_ARROW_LEFT))
		angle = -M_PI/4;
	else if(Keyboard::isKeyPressed(Keyboard::KEY_ARROW_RIGHT))
		angle = M_PI/4;

	player->update(delta, forceFactor, angle);

	//update world
	world->Step(delta, 10, 10);

	//update the camera
	camera.x = 0.1*toPixels(player->m_body->GetPosition().x) - camera.w/2;
	camera.y = 0.1*toPixels(player->m_body->GetPosition().y) - camera.h/2;

	if(lockOn)
	{
		float angleDiff = cameraAngle - (M_PI - player->m_body->GetAngle());
		cameraAngle -= angleDiff/10;
	}
}