本文整理汇总了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());
}
示例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;
}
示例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;
}
}