本文整理汇总了C++中sf::CircleShape类的典型用法代码示例。如果您正苦于以下问题:C++ CircleShape类的具体用法?C++ CircleShape怎么用?C++ CircleShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CircleShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: losango
/*
* 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);
}
示例3: 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;
}
示例4: set_circle
void set_circle(sf::CircleShape& circle, const float value, const float norm_radius,
const sf::Vector2f& position, const sf::Color& color)
{
const float radius{sqrt_value_tot_radius(value, norm_radius)};
circle.setRadius(radius);
circle.setOrigin(radius, radius);
circle.setPosition(position);
circle.setFillColor(color);
}
示例5: Ball
Ball(float mX, float mY)
{
shape.setPosition(mX, mY);
shape.setRadius(defRadius);
shape.setFillColor(defColor);
shape.setOrigin(defRadius, defRadius);
}
示例6: initialize
void Particles::initialize() {
int displayxi = int(displayx);
int displayyi = int(displayy);
int radiusi = int(radius);
int wallwidthi = int(wallwidth);
srand(time(NULL));
for( int i = 0; i<Nparticles; i++ ) {
float tempR = rand() % ((displayyi-24)/2);
float tempAngle = rand() % 360;
float tempX = -tempR*sin(tempAngle*conv);
float tempY = tempR*cos(tempAngle*conv);
sf::Vector2f temp(tempX, tempY);
sf::Vector2f placeParticles = temp + centerofmap;
particles.setPosition( placeParticles );
sf::Vector2f currentParticle = particles.getPosition();
sf::Vector2f tempPos(0,0);
sf::Vector2f disVec(0,0);
float distance = 0;
// Need to check if particles overlap during initialization
// if it does overlap, just move it by some amount
// We do not need to check if there is just one particle
if( i==0 ) {
storeParticles.push_back( particles );
}
else {
for( it = storeParticles.begin(); it != storeParticles.end(); it++ ) {
tempPos = (*it).getPosition();
disVec = currentParticle - tempPos;
distance = sqrt(pow(disVec.x,2) + pow(disVec.y,2) );
if( distance < 2.2*radius ) deleted++;
while( distance < 2.2*radius ){
(particles).setPosition( rand()%(displayxi-2*wallwidthi-3*radiusi)+(wallwidthi+1.5*radiusi), rand()%(displayyi-3*radiusi-2*wallwidthi)+(wallwidthi+1.5*radiusi) );
currentParticle = particles.getPosition();
tempPos = (*it).getPosition();
disVec = currentParticle - tempPos;
distance = sqrt(pow(disVec.x,2) + pow(disVec.y,2) );
if( i>=2 ) {
for( bit=storeParticles.begin(); bit != it; bit++ ){
tempPos = (*bit).getPosition();
disVec = currentParticle - tempPos;
distance = sqrt( pow(disVec.x,2)+pow(disVec.y,2));
if( distance < 2.2*radius ){
(particles).setPosition( rand()%(displayxi-2*wallwidthi-3*radiusi)+(wallwidthi+1.5*radiusi), rand()%(displayyi-3*radiusi-2*wallwidthi)+(wallwidthi+1.5*radiusi) );
}
}
}
}
}
storeParticles.push_back(particles);
}
}
}
示例7: gameWindow
Pong() : gameWindow(sf::VideoMode(600, 480), "Pong")
{
ball.setFillColor(sf::Color::Cyan);
ball.setPosition(100.0, 100.0);
ball.setRadius(10.f);
p1Paddle.setFillColor(sf::Color::Green);
p1Paddle.setPosition(10.0, 100.0);
p1Paddle.setSize(sf::Vector2f(10.0, 100.0));
p2Paddle.setFillColor(sf::Color::Red);
p2Paddle.setPosition(580.0, 100.0);
p2Paddle.setSize(sf::Vector2f(10.0, 100.0));
p1MovingUp = false;
p1MovingDown = false;
p2MovingUp = false;
p2MovingDown = false;
ballMovement = sf::Vector2f(ballSpeed, ballSpeed);
font.loadFromFile("arial.ttf");
p1ScoreText.setPosition(150, 10);
p1ScoreText.setFont(font);
p1ScoreText.setString(std::to_string(p1Score));
p1ScoreText.setColor(sf::Color::Red);
p1ScoreText.setCharacterSize(24);
p2ScoreText.setPosition(450, 10);
p2ScoreText.setFont(font);
p2ScoreText.setString(std::to_string(p2Score));
p2ScoreText.setColor(sf::Color::Red);
p2ScoreText.setCharacterSize(24);
}
示例8: refresh
void ColorPalette::refresh(void) {
selected.setFillColor(color);
label.setColor(color);
label.setString(ColorPalette::interpret(color, str));
rgb_c.setOutlineColor(Utility::Color::getInverseColor(color));
bw_c.setOutlineColor(Utility::Color::getInverseColor(color));
}
示例9: setPosition
void Unit::setPosition(float x, float y) {
if(_isLoaded) {
_circle.setPosition(x,y);
_sprite.setPosition(x,y);
}
else {
_circle.setPosition(x,y);
}
}
示例10:
Stone (float x, float y, float a, float b)
{
velocity.x = x;
velocity.y = y;
s.setRadius(radius);
s.setOrigin(radius,radius);
s.setFillColor(sf::Color::Black);
s.setPosition(a,b);
}
示例11: init
static void init(sf::RenderWindow &window)
{
window.setMouseCursorVisible(false);
window.setVerticalSyncEnabled(true);
crosshair.setFillColor(sf::Color(0, 0, 0, 0));
crosshair.setOutlineColor(sf::Color(0, 0, 0));
crosshair.setOutlineThickness(2.0f);
srand(static_cast<unsigned>(time(0)));
}
示例12: Ball
// Costruttore: prende come parametri la posizione iniziale
// della pallina, sotto forma di due `float`.
Ball(float mX, float mY)
{
// SFML usa un sistema di coordinate avente l'origine
// posizionata nell'angolo in alto a sinistra della
// finestra.
// {Info: coordinate system}
shape.setPosition(mX, mY);
shape.setRadius(defRadius);
shape.setFillColor(defColor);
shape.setOrigin(defRadius, defRadius);
}
示例13: set_select_state
// Draw a ring around the object to show it's selected
inline void set_select_state(bool select)
{
select_state = select;
if (select)
{
circ.setOutlineColor(sf::Color::Green);
circ.setOutlineThickness(OBJECT_SIZE/5);
}
else
{
circ.setOutlineColor(sf::Color::Black);
circ.setOutlineThickness(OBJECT_SIZE/10);
}
}
示例14: Polygons
Polygons():
_polygons(),
__polygonsVect()
{
_polygons.setRadius(50);
_polygons.setFillColor(sf::Color::Red);
for(int i = 3; i < 9;i++)
{
_polygons.setPointCount(i);
_polygons.setPosition(100.0 + (i*99) , 200.0);
__polygonsVect.push_back(_polygons);
}
}
示例15: bounceStone
void bounceStone(std::vector<Stone>& stones){
sf::Vector2f loc = s.getPosition();
sf::Vector2f stonePos;
bool collide = 0;
std::vector<sf::Vector2f> Pos;
for (int i=0; i<stones.size(); i++){
stonePos = stones[i].s.getPosition();
Pos.push_back(stonePos);
}
//comparing x and y positions of each stone
//determines the distance between the x and y coordinates of each stone
for(int i=0; i<Pos.size(); i++){
float d = sqrt(pow((loc.x-Pos[i].x),2)+pow((loc.y-Pos[i].y),2));
if (d<=80 && loc!=Pos[i]){
float newVelX1 = stones[i].velocity.x;
float newVelY1 = stones[i].velocity.y;
float newVelX2 = velocity.x;
float newVelY2 = velocity.y;
stones[i].velocity.x = newVelX2;
stones[i].velocity.y = newVelY2;
velocity.x = newVelX1;
velocity.y = newVelY1;
}
}
}