本文整理汇总了C++中sf::RectangleShape类的典型用法代码示例。如果您正苦于以下问题:C++ RectangleShape类的具体用法?C++ RectangleShape怎么用?C++ RectangleShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RectangleShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isInRect
bool CreditsMenu::isInRect(sf::Vector2i position, sf::RectangleShape menuItemRect)
{
return(menuItemRect.getPosition().y < position.y &&
menuItemRect.getPosition().y + menuItemRect.getSize().y > position.y &&
menuItemRect.getPosition().x < position.x &&
menuItemRect.getPosition().x + menuItemRect.getSize().x > position.x);
}
示例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: crossfade
bool Tutorial::crossfade(float elapsedTime, sf::RectangleShape& rect1, sf::RectangleShape& rect2)
{
float temp = alpha1 - elapsedTime * ANIMATION_SPEED;
float temp2 = alpha2 + elapsedTime * ANIMATION_SPEED;
// std::cout << "color " << static_cast<int>(temp) << std::endl;
// std::cout << "color2 " << static_cast<int>(temp2) << std::endl;
// ensure high calc times don't screw up the outcome (drag the window for a sec outputs a too high value)
// maybe just limit it would be better..
if (temp < alpha1)
{
alpha1 = temp;
alpha2 = temp2;
}
if (alpha1 < 1)
{
alpha1 = 0;
alpha2 = 255;
rect1.setFillColor(sf::Color(255, 255, 255, static_cast<sf::Uint8>(alpha1)));
return true;
}
// disabled because it should not be crossfaded only overlayed
//rect1.setFillColor(sf::Color(255, 255, 255, static_cast<sf::Uint8>(alpha1)));
rect2.setFillColor(sf::Color(255, 255, 255, static_cast<sf::Uint8>(alpha2)));
return false;
}
示例4: arrange
void DropDown::arrange(sf::Text &text,sf::RectangleShape &shape)
{
float ratiox = shape.getGlobalBounds().width/text.getGlobalBounds().width;
float ratioy = (shape.getGlobalBounds().height/text.getGlobalBounds().height);
ratioy*=0.5f;
text.scale(ratiox,ratioy);
}
示例5: init
void init() {
this->restart();
// RectangleShapes
sf::Vector2f unit(unit_w, unit_h);
stone_view = sf::RectangleShape(unit);
stone_view.setFillColor(sf::Color(255, 81, 68));
body_view = sf::RectangleShape(unit);
body_view.setFillColor(sf::Color(0, 204, 255));
food_view = sf::RectangleShape(unit);
food_view.setFillColor(sf::Color(19, 169, 136));
// font & msg
if (!font.loadFromFile("Inconsolata-Bold.ttf")) {
puts("fonts loading error!");
this->close();
}
msg1.setFont(font);
msg1.setColor(sf::Color::White);
msg1.setCharacterSize(50);
msg1.setPosition(80, 100);
msg2.setFont(font);
msg2.setColor(sf::Color::White);
msg2.setCharacterSize(25);
msg2.setString("Press <Enter> to Replay");
msg2.setPosition(60, 250);
}
示例6: setUpBall
void PongGame::setUpBall(int const mainWindowWidth, int const mainWindowHeight, sf::RectangleShape &ball) {
ball.setPosition(mainWindowWidth / 2, mainWindowHeight / 2);
ball.setSize(sf::Vector2f(20, 20));
ball.setFillColor(sf::Color::Red);
ball.setOutlineColor(sf::Color::Yellow);
ball.setOutlineThickness(2);
}
示例7: CheckRectangleCollision
//Method to check collision between 2 rectangles.
bool CollisionManager::CheckRectangleCollision(sf::RectangleShape entity1, sf::RectangleShape entity2)
{
if (entity1.getGlobalBounds().intersects(entity2.getGlobalBounds()))
return true;
else
return false;
}
示例8: IsPossibleCollisionWithTopOrBottomSide
bool CollisionChecker::IsPossibleCollisionWithTopOrBottomSide(sf::RectangleShape &r1, sf::RectangleShape &r2)
{
if(r1.getPosition().x+r1.getGlobalBounds().width > r2.getPosition().x
&& r1.getPosition().x < r2.getPosition().x+r2.getGlobalBounds().width){
return true;
}
return false;
}
示例9: main
int main() {
sgb::Chip8 chip8;
chip8.loadGame("PONG2");
back.create(64, 32, sf::Color::Black);
backshape.setPosition(0, 0);
backtext.loadFromImage(back);
backshape.setTexture(&backtext);
while(window.isOpen()){
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
// emulate one cycle
chip8.emulateCycle();
// if drawflag is set, update screen;
if (chip8.drawFlag)
updateGraphics(chip8);
//query keys
chip8.setKeys();
sf::sleep(sf::seconds(1.0f/500.0f));
}
return 0;
}
示例10: Paddle
// As with the ball, we construct the paddle with
// arguments for the initial position and initialize
// the SFML rectangle shape.
Paddle(float mX, float mY)
{
shape.setPosition(mX, mY);
shape.setSize({defWidth, defHeight});
shape.setFillColor(defColor);
shape.setOrigin(defWidth / 2.f, defHeight / 2.f);
}
示例11:
Player(sf::Vector2f position, sf::Vector2f size)
{
once = true;
rect.setPosition(position);
rect.setSize(size);
rect.setFillColor(sf::Color::Green);
}
示例12: key_pressed_events
//keyboard inputs (pressed)
void key_pressed_events(){
if(event.key.code == sf::Keyboard::Left){
square.move(x_move, 0);
x_move -= (x_move > 0) ? x_move - 2 : 2;
if(x_move <= -5){x_move = -5;}
it = stars.begin();
while(it != stars.end()){
it -> move(x_move / -4, 0);
it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
rand() % (255 + 1 - 240) + 240,
rand() % (255 + 1 - 240) + 240));
if(it -> getPosition().x > window_x){
it -> setPosition(0, it -> getPosition().y);}
++it;}
}
else if(event.key.code == sf::Keyboard::A){
it = stars.begin();
while(it != stars.end()){
it -> move(6 / 4, 0);
it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
rand() % (255 + 1 - 240) + 240,
rand() % (255 + 1 - 240) + 240));
if(it -> getPosition().x > window_x){
it -> setPosition(0, it -> getPosition().y);}
++it;}
}
else if(event.key.code == sf::Keyboard::Right){
square.move(x_move, 0);
x_move += 2;
if(x_move >= 5){x_move = 5;}
it = stars.begin();
while(it != stars.end()){
it -> move(x_move / -4, 0);
it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
rand() % (255 + 1 - 240) + 240,
rand() % (255 + 1 - 240) + 240));
if(it -> getPosition().x < 0){
it -> setPosition(window_x, it -> getPosition().y);}
++it;}
}
else if(event.key.code == sf::Keyboard::D){
it = stars.begin();
while(it != stars.end()){
it -> move(6 / -4, 0);
it -> setFillColor(sf::Color(rand() % (255 + 1 - 240) + 240,
rand() % (255 + 1 - 240) + 240,
rand() % (255 + 1 - 240) + 240));
if(it -> getPosition().x < 0){
it -> setPosition(window_x, it -> getPosition().y);}
++it;}
}
}
示例13: TestBox
TestBox(bool isCollidable) :
sg::Entity(isCollidable)
{
r0.setSize(sf::Vector2f(100.0f, 50.0f));
r0.setOrigin(50.0f, 25.0f);
this->addDrawable(r0, false);
bs.addShape(r0);
r1.setRadius(40.0f);
r1.setOrigin(40.0f, 40.0f);
r1.move(100.0f, 0.0f);
r1.scale(2.0f, 1.0f);
this->addDrawable(r1, false);
bs.addShape(r1);
r2.setSize(sf::Vector2f(250.0f, 10.0f));
r2.setOrigin(125.0f, 5.0f);
r2.rotate(-90.0f);
this->addDrawable(r2, false);
bs.addShape(r2);
r3.setRadius(40.0f);
r3.setOrigin(40.0f, 40.0f);
r3.move(-100.0f, 0.0f);
this->addDrawable(r3, false);
bs.addShape(r3);
//bs.rotate(-45.0f);
this->addTransformable(bs);
//this->rotate(45.0f);
}
示例14: Board
Board(int n, sf::Vector2f pos){
boardSprite.setSize(sf::Vector2f(n, 2));
boardSprite.setFillColor(sf::Color::Blue);
boardSprite.setPosition(pos);
}
示例15: el
el(sf::Vector2f p)
{
r.setSize(sf::Vector2f(50,50));
r.setFillColor(sf::Color(2,136,209));
pos = p;
r.setPosition(pos);
}