当前位置: 首页>>代码示例>>C++>>正文


C++ RenderWindow::ConvertCoords方法代码示例

本文整理汇总了C++中sf::RenderWindow::ConvertCoords方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderWindow::ConvertCoords方法的具体用法?C++ RenderWindow::ConvertCoords怎么用?C++ RenderWindow::ConvertCoords使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::RenderWindow的用法示例。


在下文中一共展示了RenderWindow::ConvertCoords方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Update

void Player::Update(sf::RenderWindow & App, class Physic & physic)
{
	if(!m_inited)
		Init(physic);


	const sf::Input & _input = App.GetInput();

	physic.GetPlayer(0)->vel = physic.GetPlayer(0)->body->GetLinearVelocity();
	physic.GetPlayer(0)->rotation = physic.GetPlayer(0)->body->GetAngle();

		if(_input.IsKeyDown(sf::Key::A)) { physic.GetPlayer(0)->rotation += -1.0f * App.GetFrameTime(); physic.GetPlayer(0)->body->SetTransform(physic.GetPlayer(0)->body->GetPosition(), physic.GetPlayer(0)->rotation); /*m_rotationDegree -= 3; m_rotation = 3; m_player.Rotate( (float)m_rotation );*/ } // turn LEFT
		if(_input.IsKeyDown(sf::Key::D)) { physic.GetPlayer(0)->rotation += 1.0f * App.GetFrameTime(); physic.GetPlayer(0)->body->SetTransform(physic.GetPlayer(0)->body->GetPosition(), physic.GetPlayer(0)->rotation); /*m_rotationDegree += 3; m_rotation = -3; m_player.Rotate( (float)m_rotation  );*/ } // turn RIGHT

		if(_input.IsKeyDown(sf::Key::W)) { m_V += 2.00  ;    }
		if(_input.IsKeyDown(sf::Key::S)) { m_V -= 1.00  ;    }
		if(_input.IsKeyDown(sf::Key::Space)) { m_V = 0.0 ;  }

		physic.GetPlayer(0)->body->SetAngularVelocity(0.f);

/*		 
			if(m_clock2.GetElapsedTime() > 1.0f)
			{
				if(_input.IsMouseButtonDown(sf::Mouse::Left))
				{
					Shoot(App);
					m_reload = true;
					m_clock2.Reset();
				}
				m_reload = false;
			}
			else
			{
				m_reload = true;
			}
		
*/
//		UpdateBullets(App);

//		m_mousePozVec.x = _input.GetMouseX();
//		m_mousePozVec.y = _input.GetMouseY();

		m_mousePozVec = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());

		m_xH = m_cannon.GetPosition().x - m_mousePozVec.x;
		m_yH = m_cannon.GetPosition().y - m_mousePozVec.y;
		m_cannonRotation =(float)(atan2(m_yH,m_xH) * 180.f / b2_pi + 180.f);


//		if(physic.GetPlayer(0)->rotation > 359) physic.GetPlayer(0)->rotation = 0;
//		if(physic.GetPlayer(0)->rotation < 0) physic.GetPlayer(0)->rotation = 359;
		

        if( m_V > m_maxPlayerSpeed ) m_V = m_maxPlayerSpeed;
        if( m_V <  m_maxPlayerBackSpeed ) m_V = m_maxPlayerBackSpeed;

		physic.GetPlayer(0)->vel.x = m_V * cos((b2_pi*(physic.GetPlayer(0)->rotation * RADTODEG ))/180.f);
        physic.GetPlayer(0)->vel.y = m_V * sin((b2_pi*(physic.GetPlayer(0)->rotation * RADTODEG ))/180.f);

//		if( m_disVec.x >= 1 || m_disVec.x <= - 1 ) { m_playerPozVec.x += int(m_disVec.x) * App.GetFrameTime(); m_disVec.x = m_disVec.x - int( m_disVec.x ); }
//      if( m_disVec.y >= 1 || m_disVec.y <= - 1 ) { m_playerPozVec.y += int(m_disVec.y) * App.GetFrameTime(); m_disVec.y = m_disVec.y - int( m_disVec.y ); }
		
		physic.GetPlayer(0)->body->SetLinearVelocity(physic.GetPlayer(0)->vel);
		
		m_player.SetPosition( physic.GetPlayer(0)->GetPosition() );
		m_player.SetRotation( -physic.GetPlayer(0)->rotation * RADTODEG );


		m_cannon.SetPosition(m_player.GetPosition());
		m_cannon.SetRotation(-m_cannonRotation);

/*
#pragma region DEBUG INFO
std::ostringstream bufor;
sf::String tdebug;
tdebug.SetFont(LoadContent::GetInstance()->m_font2);
tdebug.SetSize(20);
bufor << "\nFPS = " << _Framerate;
tdebug.SetText(bufor.str());
App.Draw(tdebug);		
#pragma endregion	
*/

		App.Draw(m_player);
		App.Draw(m_cannon);
}
开发者ID:urbanek32,项目名称:Tanks-War,代码行数:86,代码来源:Player.cpp

示例2:

void GUI::MouseTracker::update(const sf::RenderWindow& window, const sf::View& view) {
	sf::Vector2f tmp = window.ConvertCoords(x, y, &view);
	position.x = tmp.x;
	position.y = tmp.y;
}
开发者ID:tzaeru,项目名称:PutkaRTS,代码行数:5,代码来源:MouseTracker.cpp

示例3: update

int GameScreen::update (sf::RenderWindow &app)
{
	int nextScreen = myID;
	float elapsedTime = app.GetFrameTime();

	sf::Event event;
	while (app.GetEvent(event)) // Boucle des évènements en attente
	{
		if (event.Type == sf::Event::Closed)
		{
			return EXIT;
		}
		else if(m_iHandler->testEvent(event, "Quit"))
		{
			return EXIT;
		}
		else if (event.Type == sf::Event::MouseMoved)
		{
			sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseMove.X, event.MouseMove.Y, &ConfigOptions::getView());
			m_cursor.moveOnSquare(BoardAlignedSprite::toSquares(mouseCoords), false);
		}
		else if(m_iHandler->testEvent(event, "Up"))
		{
			sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(0, -1);
			if(isValid(s))
				m_cursor.moveOnSquare(s, false);
		}
		else if(m_iHandler->testEvent(event, "Left"))
		{
			sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(-1, 0);
			if(isValid(s))
				m_cursor.moveOnSquare(s, false);
		}
		else if(m_iHandler->testEvent(event, "Down"))
		{
			sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(0, 1);
			if(isValid(s))
				m_cursor.moveOnSquare(s, false);
		}
		else if(m_iHandler->testEvent(event, "Right"))
		{
			sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition()) + sf::Vector2i(1, 0);
			if(isValid(s))
				m_cursor.moveOnSquare(s, false);
		}
		else if(playerHasHand())
		{
			if(m_iHandler->testEvent(event, "Save"))
			{
				m_game.saveToFile(BACKUP_FILE);
			}
			else if(m_iHandler->testEvent(event, "Load"))
			{
				m_game.loadFromFile(BACKUP_FILE);
				refreshAll();
			}
			else if (m_iHandler->testEvent(event, "LClick"))
			{
				sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseButton.X, event.MouseButton.Y, &ConfigOptions::getView());
				sf::Vector2i s = BoardAlignedSprite::toSquares(mouseCoords);
				if(isValid(s))
					clickOn(s);
				else if(!m_game.hasStarted())
				{
					PieceType type = m_placementUI.click(mouseCoords);
					if(type == NB_PIECES) //end of turn
						tryAndEndTurn();
					else
						m_selectedType = type;
				}
			}
			if (m_iHandler->testEvent(event, "Choose"))
			{
				sf::Vector2i s = BoardAlignedSprite::toSquares(m_cursor.GetPosition());
				if(isValid(s))
					clickOn(s);
			}
			else if (m_iHandler->testEvent(event, "RClick"))
			{
				sf::Vector2f mouseCoords = app.ConvertCoords(event.MouseButton.X, event.MouseButton.Y, &ConfigOptions::getView());
				sf::Vector2i s = BoardAlignedSprite::toSquares(mouseCoords);
				if(!m_game.hasStarted())
					remove(s);
			}
			else if (m_iHandler->testEvent(event, "EndTurn"))
			{
				tryAndEndTurn();
			}
			else if (event.Type == sf::Event::MouseWheelMoved)
			{
				if(event.MouseWheel.Delta > 0)
				{
					m_selectedType = m_placementUI.goUp();
				}
				else
				{
					m_selectedType = m_placementUI.goDown();
				}
			}
			else if (m_iHandler->testEvent(event, "Rabbit"))
//.........这里部分代码省略.........
开发者ID:Prateekarimaa,项目名称:Arimaa,代码行数:101,代码来源:GameScreen.cpp


注:本文中的sf::RenderWindow::ConvertCoords方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。