本文整理汇总了C++中sf::CircleShape::getRadius方法的典型用法代码示例。如果您正苦于以下问题:C++ CircleShape::getRadius方法的具体用法?C++ CircleShape::getRadius怎么用?C++ CircleShape::getRadius使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::CircleShape
的用法示例。
在下文中一共展示了CircleShape::getRadius方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exibeHud
/*
* Mostra na tela os indicadores básicos do jogo:
* vidas restantes, HP e pontuação.
*/
void Jogo::exibeHud()
{
float x = 0.10 * janela.getSize().x;
float y = 0.15 * janela.getSize().y;
/* Desenha vidas extras da nave */
static sf::CircleShape losango(20.0, 4);
for (int i = 0; i < nave->getVidas(); i++) {
double deltaX = 2.5 * losango.getRadius();
losango.setPosition(x + (i * deltaX), y);
janela.draw(losango);
}
/* Desenha caixa da lifebar */
y += 3.0 * losango.getRadius();
static sf::RectangleShape caixa({200.0, 10.0});
caixa.setPosition(x, y);
caixa.setFillColor(sf::Color::Blue);
janela.draw(caixa);
/* Desenha lifebar com parcial do HP */
float k = (float) nave->getHP() / nave->getHPMax();
sf::RectangleShape lifebar({k * caixa.getSize().x,
caixa.getSize().y});
lifebar.setPosition(x, y);
lifebar.setFillColor(k > 0.25 ? sf::Color::Green : sf::Color::Red);
janela.draw(lifebar);
/* Imprime pontuação (e, se for o caso, mensagem de pausa) */
y += 2.5 * lifebar.getSize().y;
sf::String str = "Score: " + std::to_string(nave->getScore());
if (pausado) str += " (pausa)";
sf::Text texto(str, fonte, 20);
texto.setPosition(x, y);
janela.draw(texto);
}
示例2: checkCircleCollision
/*
Name: checkCircleCollision
Desc: given to circles, it will check to see if they are colliding.
Args: p_circle1, the first circle
p_circle2, the second circle to check against.
Rtrn: bool, if the two are colliding
*/
bool Game::checkCircleCollision(const sf::CircleShape &p_circle1, const sf::CircleShape &p_circle2)
{
float xDistance = p_circle1.getPosition().x - p_circle2.getPosition().x;
float yDistance = p_circle1.getPosition().y - p_circle2.getPosition().y;
return sqrt((xDistance * xDistance) + (yDistance * yDistance)) < p_circle1.getRadius() + p_circle2.getRadius();
}
示例3: 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;
}
示例4: collisionCircle
bool Engine::collisionCircle(sf::FloatRect box1, sf::CircleShape circle)
{
int d2 = (box1.left-circle.getPosition().x)*(box1.left-circle.getPosition().x) + (box1.top-circle.getPosition().y)*(box1.top-circle.getPosition().y);
if (d2>pow(circle.getRadius(),2))
return false;
else
return true;
}
示例5:
sf::Vector2f World::validMovement(const sf::Vector2f& translation,
const sf::CircleShape& obstacle) const
{
auto beginPlayerPos{center(player)};
auto obstaclePos{center(obstacle)};
auto endPlayerPos{center(player) + translation};
auto r = player.getRadius();
auto R = obstacle.getRadius();
auto rR = r + R;
auto dist_s = dist_sqr(endPlayerPos, obstaclePos);
auto scaling_factor = 1.f;
if (dist_s < rR * rR)
{
scaling_factor = compute_scaling_factor(
translation, obstaclePos - beginPlayerPos, r + R);
}
return translation * scaling_factor;
}
示例6: radius
float radius() const noexcept { return shape.getRadius(); }
示例7: bottom
float bottom () { return y() + shape.getRadius(); }
示例8: top
float top() { return y() - shape.getRadius(); }
示例9: left
float left() { return x() - shape.getRadius(); }
示例10: bottom
float bottom() const noexcept { return y() + shape.getRadius(); }
示例11: top
float top() const noexcept { return y() - shape.getRadius(); }
示例12: right
float right() const noexcept { return x() + shape.getRadius(); }
示例13: left
float left() const noexcept { return x() - shape.getRadius(); }
示例14: if
sf::Vector2f collide(sf::CircleShape ball, sf::RectangleShape block)
{
sf::Vector2f ball_center = ball.getPosition() + sf::Vector2f(ball.getRadius(), ball.getRadius());
sf::Vector2f block_center = block.getPosition() + sf::Vector2f(block.getSize().x/2, block.getSize().y/2);
sf::Vector2f diff = ball_center - block_center;
// Not intersecting
if(abs(diff.x) > block.getSize().x/2 + ball.getRadius() || abs(diff.y) > block.getSize().y/2 + ball.getRadius())
{
return sf::Vector2f(0,0);
}
std::cout << diff.x << ", " << diff.y << std::endl;
// hit edge of block (top/bottom)
if(abs(diff.x) <= PADDLE_WIDTH/2)
{
if(diff.y <= 0)
{
return sf::Vector2f(0,-1);
}
else if(diff.y > 0)
{
return sf::Vector2f(0,1);
}
}
// hit edge of block (left/right)
else if(abs(diff.y) <= PADDLE_HEIGHT/2)
{
if(diff.x <= 0)
{
return sf::Vector2f(-1,0);
}
else if(diff.x > 0)
{
return sf::Vector2f(1,0);
}
}
float distance = getDistance(ball_center, block.getPosition());
if(distance <= ball.getRadius())
{
return (ball_center - block.getPosition()) / distance;
}
sf::Vector2f block_corner = block.getPosition() + sf::Vector2f(block.getSize().x,0);
distance = getDistance(ball_center, block_corner);
if(distance <= ball.getRadius())
{
return (ball_center - block_corner) / distance;
}
block_corner = block.getPosition() + sf::Vector2f(0, block.getSize().y);
distance = getDistance(ball_center, block_corner);
if(distance <= ball.getRadius())
{
return (ball_center - block_corner) / distance;
}
block_corner = block.getPosition() + block.getSize();
distance = getDistance(ball_center, block_corner);
if(distance <= ball.getRadius())
{
return (ball_center - block_corner) / distance;
}
// Not intersecting, even in the corners
return sf::Vector2f(0,0);
}
示例15: setRadius
// Circle Shape
void Unit::setRadius(float radius) {
_circle.setRadius(radius);
_circle.setOrigin(_circle.getRadius(), _circle.getRadius());
}