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


C++ CircleShape::getGlobalBounds方法代码示例

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


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

示例1: update

	void update(sf::Time timeChange)
	{
		sf::Vector2f p1Movement(0, 0);
		sf::Vector2f p2Movement(0, 0);


		if (p1MovingUp)
			p1Movement.y -= paddleSpeed;
		if (p1MovingDown)
			p1Movement.y += paddleSpeed;
		if (p2MovingUp)
			p2Movement.y -= paddleSpeed;
		if (p2MovingDown)
			p2Movement.y += paddleSpeed;

		p1Paddle.move(p1Movement * timeChange.asSeconds());
		p2Paddle.move(p2Movement * timeChange.asSeconds());


		// Check collision
		if (ball.getPosition().y < 0 || ball.getPosition().y > 480){
			ballMovement.y *= -1;
		}
		if (ball.getGlobalBounds().intersects(p1Paddle.getGlobalBounds()) || ball.getGlobalBounds().intersects(p2Paddle.getGlobalBounds())){
			ballMovement.x *= -1;
		}



		// Scoring
		if (ball.getPosition().x > 600){
			// P1 scores
			ball.setPosition(300, 240);
			p1Score++;
			p1ScoreText.setString(std::to_string(p1Score));
		}
		else if (ball.getPosition().x < 0){
			// P2 scores
			ball.setPosition(300, 240);
			p2Score++;
			p2ScoreText.setString(std::to_string(p2Score));
		}

		ball.move(ballMovement * timeChange.asSeconds());


	}
开发者ID:minhoolee,项目名称:id-Tech-Files,代码行数:47,代码来源:Main.cpp

示例2: collisionSP

bool Knight::collisionSP(sf::CircleShape & player) {
	sf::FloatRect circle1Box = swordCircles[0].getGlobalBounds();
	sf::FloatRect circle2Box = swordCircles[1].getGlobalBounds();
	sf::FloatRect circle3Box = swordCircles[2].getGlobalBounds();
	//if not swinging, we don't want collision to register so return false
	//if sword already intersected, return false to prevent multiple intersections on one swing (light, quick check)
	if (!isSwinging || swordIntersected) {
		return false;
	}
	//full collision check between sword circles and circle of player
	bool ret = false;
	sf::Vector2f playerCenter = sf::Vector2f(player.getGlobalBounds().left + player.getGlobalBounds().width / 2.0f, player.getGlobalBounds().top + player.getGlobalBounds().height / 2.0f);
	// circle 1
	if (circle1Box.intersects(player.getGlobalBounds())) {
		sf::Vector2f circle1Center = sf::Vector2f(circle1Box.left + circle1Box.width / 2.0f, circle1Box.top + circle1Box.height / 2.0f);
		float dx = (playerCenter.x - circle1Center.x) * (playerCenter.x - circle1Center.x);
		float dy = (playerCenter.y - circle1Center.y) * (playerCenter.y - circle1Center.y);
		ret = dx + dy < std::pow(player.getRadius() + swordCircles[0].getRadius(), 2);
		if (ret) {
			swordIntersected = true;
			return true;
		}
	}
	// circle 2
	if (circle2Box.intersects(player.getGlobalBounds())) {
		sf::Vector2f circle2Center = sf::Vector2f(circle2Box.left + circle2Box.width / 2.0f, circle2Box.top + circle2Box.height / 2.0f);
		float dx = (playerCenter.x - circle2Center.x) * (playerCenter.x - circle2Center.x);
		float dy = (playerCenter.y - circle2Center.y) * (playerCenter.y - circle2Center.y);
		ret = dx + dy < std::pow(player.getRadius() + swordCircles[1].getRadius(), 2);
		if (ret) {
			swordIntersected = true;
			return true;
		}
	}
	// circle 3
	if (circle3Box.intersects(player.getGlobalBounds())) {
		sf::Vector2f circle3Center = sf::Vector2f(circle3Box.left + circle3Box.width / 2.0f, circle3Box.top + circle3Box.height / 2.0f);
		float dx = (playerCenter.x - circle3Center.x) * (playerCenter.x - circle3Center.x);
		float dy = (playerCenter.y - circle3Center.y) * (playerCenter.y - circle3Center.y);
		ret = dx + dy < std::pow(player.getRadius() + swordCircles[2].getRadius(), 2);
		if (ret) {
			swordIntersected = true;
			return true;
		}
	}
	return false;
}
开发者ID:michaell308,项目名称:The_Gallant_Gauntlet,代码行数:47,代码来源:Knight.cpp

示例3:

bool tr::CColisiometro::Interseccion(sf::RectangleShape rectangle, sf::CircleShape circle, sf::RectangleShape* choque = nullptr)
{	
	sf::FloatRect rect2 = rectangle.getGlobalBounds();
	sf::FloatRect rect1 = circle.getGlobalBounds();
	sf::FloatRect intersection;

	if (rect2.intersects(rect1, intersection))
	{
		if (choque != nullptr)
		{
			//le regreso la zona del choque			
			choque->setPosition(sf::Vector2f(intersection.left, intersection.top));
			choque->setSize(sf::Vector2f(intersection.width,intersection.height));			
		}
		return true;
	}else
	{
		return false;
	}
}
开发者ID:0Wind-UpBird,项目名称:Run-Ball-Run,代码行数:20,代码来源:Colisiometro.cpp


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