本文整理汇总了C++中sf::CircleShape::getPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ CircleShape::getPosition方法的具体用法?C++ CircleShape::getPosition怎么用?C++ CircleShape::getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::CircleShape
的用法示例。
在下文中一共展示了CircleShape::getPosition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void Game::update() {
posicion_jugable_x = mPlayer.getPosition().x;
posicion_jugable_y = mPlayer.getPosition().y;
this->movement.y = 0.f;
this->movement.x = 0.f;
if (this->mIsMovingUp & this->mIsMovingUpRel & (posicion_jugable_y > 0) & movimiento_valido(0, -1)) {
this->movement.y -= 50.f;
this->mIsMovingUpRel = 0;
}
if (this->mIsMovingDown & this->mIsMovingDownRel & (posicion_jugable_y < 450) & movimiento_valido(0, 1)) {
this->movement.y += 50.f;
this->mIsMovingDownRel = 0;
}
if (this->mIsMovingLeft & this->mIsMovingLeftRel & (posicion_jugable_x > 0) & movimiento_valido(-1, 0)) {
this->movement.x -= 50.f;
this->mIsMovingLeftRel = 0;
}
if (this->mIsMovingRight & this->mIsMovingRightRel & (posicion_jugable_x < 650) & movimiento_valido(1, 0)) {
this->movement.x += 50.f;
this->mIsMovingRightRel = 0;
}
if(mPlayer.getPosition() == mPlayerObj.getPosition()) {
this->mIsMapGenerate = true;
Game::generacion_mapa();
}
mPlayer.move(this->movement);
}
示例2: bounce
void bounce(){
sf::Vector2f Pos = s.getPosition();
if (Pos.x >= 960 || Pos.x <=40){
velocity.x= -velocity.x;
}
if (Pos.y >=960 || Pos.y <=40){
velocity.y = -velocity.y;
}
}
示例3: x
float x() const noexcept { return shape.getPosition().x; }
示例4: x
// (0,0) é no topo da esquerda
float x() { return shape.getPosition().x; }
示例5: if
int main()
{
sf::Clock clock;
double s = 0;
double viewZoom = 1.0f;
srand(time(0));
for (u32 i = 0; i < PN; i++)
{
particule[i]._px = rand() % WINX;
particule[i]._py = rand() % WINY;
if (INITIAL_SPEED_ACTIVATE)
{
particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
}
else
{
particule[i]._mx = 0;
particule[i]._my = 0;
}
particule[i]._mass = PAR_MASS;
particule[i]._color = PCOLOR;
}
planet.setPosition(sf::Vector2f(WINX/2, WINY/2));
planet.setOrigin(sf::Vector2f(10.0f, 10.0f));
planet.setFillColor(sf::Color::Blue);
win.create(sf::VideoMode(WINX, WINY), "ORBITE");
win.setFramerateLimit(MAXFPS);
clock.restart();
while (win.isOpen())
{
s = clock.restart().asSeconds();
s *= SPEED;
sf::View view = win.getDefaultView();
view.zoom(viewZoom);
while (win.pollEvent(eve))
{
if (eve.type == sf::Event::Closed)
win.close();
if (eve.type == sf::Event::KeyPressed)
{
if (eve.key.code == sf::Keyboard::Add)
viewZoom -= 0.25f;
else if (eve.key.code == sf::Keyboard::Subtract)
viewZoom += 0.25f;
else if (eve.key.code == sf::Keyboard::Space)
{
trace.clear();
for (u32 i = 0; i < PN; i++)
{
particule[i]._px = rand() % WINX;
particule[i]._py = rand() % WINY;
if (INITIAL_SPEED_ACTIVATE)
{
particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
}
else
{
particule[i]._mx = 0;
particule[i]._my = 0;
}
particule[i]._mass = PAR_MASS;
particule[i]._color = PCOLOR;
}
}
}
}
planet.setPosition((sf::Vector2f)sf::Mouse::getPosition(win));
for (u32 i = 0; i < PN; i++)
{
particule[i].updateToPosition(planet.getPosition(), PL_MASS, s);
part[i].position = sf::Vector2f(particule[i]._px, particule[i]._py);
part[i].color = particule[i]._color;
if (ACTIVATE_ORBIT_TRACE)
{
sf::Vertex cpy = part[i];
trace.append(cpy);
}
}
win.setView(view);
win.clear(sf::Color::Black);
win.draw(planet);
win.draw(part);
win.draw(trace);
win.display();
}
return (0);
}
示例6: 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);
}
示例7:
// Get the current position of this unit
// For now the position of the circle
inline sf::Vector2f get_position() const
{
return circ.getPosition();
}