void resetBall() { FloatRect p = player.getGlobalBounds(); FloatRect b = ball.getGlobalBounds(); ball.setPosition(p.left + p.width/2 + 5, p.top); ballSpeed.x = 0.1f; ballSpeed.y = -0.3f; }
void UIComponentImage::onRender(GraphicsDevice* renderer, UIView* view) { RectangleShape backgroundRect; backgroundRect.setRect(view->getBounds()); if(mTexture) backgroundRect.setTexture(mTexture); renderer->draw(backgroundRect); }
void UIComponentTreeView::onRender(Renderer* renderer, UIView* view) { // Draw a black background on the ROOT tree view if(mSubTreeLevel == 0) { RectangleShape back; back.setRect(view->getBounds()); back.setColor(Color(36,36,36)); renderer->draw(back); } /*else if(mSubTreeLevel == 1) { RectangleShape back; back.setRect(view->getBounds()); back.setColor(Color::Grass); renderer->draw(back); } else if(mSubTreeLevel == 2) { RectangleShape back; back.setRect(view->getBounds()); back.setColor(Color::Bittersweet); renderer->draw(back); } else if(mSubTreeLevel == 3) { RectangleShape back; back.setRect(view->getBounds()); back.setColor(Color::Lavender); renderer->draw(back); }*/ }
Wire(float mX, float mY) { line.setSize(Vector2f(5, 5)); line.setPosition(mX, mY); line.setFillColor(Color::Red); }
void RenderSystem::draw(GameObject* gameObject) { RenderComponent* render = gameObject->getComponent<RenderComponent>(); if (render != nullptr) { RectangleShape shape = *render->getDrawable(); TransformComponent* transform = gameObject->getComponent<TransformComponent>(); if (transform != nullptr) { shape.setPosition(transform->getPosition()); } else { BoardComponent* boardComp = gameObject->getComponent<BoardComponent>(); if (boardComp != nullptr && mBoard != nullptr) { Vector2i boardPos = boardComp->getPosition(); shape.setPosition(mBoard->getTilePosition(boardPos.x, boardPos.y)); } } mWindow->draw(shape); } }
// The constructor is almost identical to the `Paddle` one. Brick(float mX, float mY) { shape.setPosition(mX, mY); shape.setSize({blockWidth, blockHeight}); shape.setFillColor(Color::Yellow); shape.setOrigin(blockWidth / 2.f, blockHeight / 2.f); }
/* Determine si le bouton de la boite de dialogue selectionné par le clic de la souris est celui d'annulation. */ bool MainTool::isCancelClicked(int x, int y) { Text ok; ok.setFont(font); ok.setString("Sauver"); ok.setCharacterSize(12); FloatRect fro = ok.getLocalBounds(); Text cancel; cancel.setFont(font); cancel.setString("Annuler"); cancel.setCharacterSize(12); FloatRect frc = cancel.getLocalBounds(); cancel.setPosition((400 - 40 - fro.width - frc.width) / 2 + 30 + fro.width, 70); RectangleShape buttonCancel; buttonCancel.setSize(Vector2f(frc.width + 10, frc.height + 10)); buttonCancel.setPosition(cancel.getPosition().x - 5, cancel.getPosition().y); if (buttonCancel.getGlobalBounds().contains(x, y)) return true; else return false; }
void updatePlayer() { if (Keyboard::isKeyPressed(Keyboard::Left)) { player.move(-moveDistance * updateTime/50.0, 0); } else if (Keyboard::isKeyPressed(Keyboard::Right)) { player.move(moveDistance * updateTime/50.0, 0); } }
Paddle(float mX, float mY) { shape.setPosition(mX, mY); shape.setSize({paddleWidth, paddleHeight}); shape.setFillColor(Color::Red); shape.setOrigin(paddleWidth / 2.f, paddleHeight / 2.f); }
void GameEngine::_initWall(RectangleShape &wall, const unsigned int size, Color const &color, const Vector2f &pos) { wall.setSize(Vector2f(25, size)); wall.setOrigin(0, size); wall.setFillColor(color); wall.setPosition(pos); }
initialization_blocks(float x, float y, int count) { rectangle.setSize(RECTANGLES_SIZE); rectangle.setFillColor(Color::Blue); rectangle.setOrigin(RECTANGLES_SIZE.x / 2, RECTANGLES_SIZE.y / 2); pos.x = x; pos.y = y; }
void UIComponentScrollBar::onRender(Renderer* renderer, UIView* view) { RectangleShape scrollBarBackground; scrollBarBackground.setSize(17.f, view->getSize().y); scrollBarBackground.setPosition(view->getPosition().x + view->getSize().y - 17.f, view->getPosition().y); scrollBarBackground.setColor(Color::Blue); renderer->draw(scrollBarBackground); renderer->draw(scrollBarPaddle); }
//Точка входит в квадрат? bool Check(RectangleShape rect, CircleShape shape){ Vector2f coordrect = rect.getPosition(); Vector2f coordshape = shape.getPosition(); if (coordrect.x <= coordshape.x && coordrect.y <= coordshape.y && coordrect.x + rect.getSize().x >= coordshape.x && coordrect.y + rect.getSize().y >= coordshape.y) { return true; } else { return false; } }
KShape *RectangleShapeFactory::createDefaultShape(KResourceManager *) const { RectangleShape *rect = new RectangleShape(); rect->setBorder(new KLineBorder(1.0)); rect->setShapeId(KoPathShapeId); QLinearGradient *gradient = new QLinearGradient(QPointF(0,0), QPointF(1,1)); gradient->setCoordinateMode(QGradient::ObjectBoundingMode); gradient->setColorAt(0.0, Qt::white); gradient->setColorAt(1.0, Qt::green); rect->setBackground(new KGradientBackground(gradient)); return rect; }
void update(float time, int number_block) { if (step == MOVE_DOWN) step_one(rectangle, time, pos.y, step); else if (step == MOVE_RIGHT_AND_UP) step_two(rectangle, time, pos.x, pos.y, step, number_block, rotation); else if (step == MOVE_RIGHT_AND_TURN) step_three(rectangle, time, number_block, pos.x, pos.y, step); else if (step == MOVE_DOWN_AND_CHANGE_SCALE) step_four(rectangle, time, number_block, pos.x, pos.y, step, size_y); else if (step == MOVE_LEFT) step_five(rectangle, time, number_block, pos.x, pos.y, step, size_y); rectangle.setScale(size_x, size_y); rectangle.setRotation(rotation); rectangle.setPosition(pos.x, pos.y); };
void update() { shape.move(velocity); if(Keyboard::isKeyPressed(Keyboard::Key::Left) && left() > 0) { velocity.x = -paddleVelocity; } else if(Keyboard::isKeyPressed(Keyboard::Key::Right) && right() < windowWidth) { velocity.x = paddleVelocity; } else velocity.x = 0; }
void Snake::afficher(sf::RenderWindow * _window){ int colorByQuad = 200/corps.size(); for(int i=0;i<corps.size();i++){ partCorps.setFillColor(Color(10,255-(i*colorByQuad),10)); partCorps.setPosition(Vector2f(corps[i].x*partSize,corps[i].y*partSize)); _window->draw(partCorps); } _window->draw(partFood); if(loose){ RectangleShape tmp; tmp.setFillColor(Color(50,0,0,127)); tmp.setPosition(0,0); tmp.setSize(Vector2f(largeur,hauteur)); _window->draw(tmp); _window->draw(text); _window->draw(text2); } }
void step_five(RectangleShape &rectangle, float time, int number_block, float &x, float &y, int &step, float &size_y) { if (x > RECTANGLES_SIZE.x / 2) x -= time * 0.1; else { step = MOVE_DOWN; rectangle.setFillColor(Color::Blue); } }
void step_one(RectangleShape &rectangle, float time, float &y, int &step) { if (y > WINDOW_SIZE.y - RECTANGLES_SIZE.y / 2) { rectangle.setFillColor(Color::Magenta); step = MOVE_RIGHT_AND_UP; } else y += time * 0.1; }
Player(int player, float x, float y){ // == Создание игрока == rectangle.setPosition(Vector2f(x, y)); //Позиция игрока this->player = player; //ID игрока rectangle.setSize(Vector2f(20, 20)); //Размер rectangle.setFillColor(Color::Green); //Цвет // == Создание пушки == Vector2f centerTank = { 0, 0 }; centerTank.x = rectangle.getPosition().x + (rectangle.getSize().x / 2); //Центр танка по x centerTank.y = rectangle.getPosition().y + (rectangle.getSize().y / 2); //Центр танка по y turret.setPrimitiveType(LinesStrip); turret.append(centerTank); //Начало пушки из танка centerTank.y -= 25; turret.append(centerTank); //Смещение по y на 10 };
void UIComponentTreeViewItem::onRender(Renderer* renderer, UIView* view) { // Render this item full size /*RectangleShape back; back.setRect(view->getBounds()); back.setColor(Color::Red); renderer->draw(back);*/ // Render a little expandable flag if it applies if(mParent->getChildCount() > 0) { RectangleShape back; back.setRect(mParent->getChild(0)->getBounds()); back.setSize(5.f, back.getSize().y); back.setColor(Color::Red); renderer->draw(back); } }
void StateTransitionBlocks::onUpdate(const Time& time) { if(!m_next) { remainingTime -= time.asSeconds(); if(remainingTime <= 0.f && !positions.empty()) { vec2 p = positions.back(); positions.pop_back(); RectangleShape shape; shape.setColor(Color::Black); shape.setSize(blockSize,blockSize); shape.setPosition(p.x, p.y); shapes.push_back(shape); remainingTime = 0.005f; } if(positions.empty()) m_next = true; } else { remainingTime -= time.asSeconds(); if(remainingTime <= 0.f) { if(shapes.size() > 0) shapes.pop_back(); remainingTime = 0.005f; } if(shapes.empty()) { Log("Transition ended"); finish(); } } }
Quadtree::Quadtree(int level, RectangleShape bounds) : level_(level), bounds_(bounds) { // Initialize children pointers to null for(int i = 0; i < 4; ++i) children_[i] = 0; if(Debug::enabled) std::cout << "Quadtree @ (" << bounds_.x() << ", " << bounds_.y() << ") -> (" << bounds_.x() + bounds_.width() << ", " << bounds.y() + bounds_.height() << ")" << std::endl; }
void GameArea::render() { const int colWidth = zone.width / 3, rowHeight = zone.height / 3; RectangleShape nextNestedRect; if(gameStatus.nextNested == 9) // whole board { nextNestedRect.setSize(Vector2f(zone.width, zone.height)); nextNestedRect.setPosition(zone.left, zone.top); } else // nested ttt { nextNestedRect.setSize(Vector2f(colWidth, rowHeight)); nextNestedRect.setPosition((gameStatus.nextNested % 3) * colWidth + zone.left, (gameStatus.nextNested/3) * rowHeight + zone.top); } nextNestedRect.setFillColor(Color(0xBA, 0xAC, 0x44)); // Yellow win->draw(nextNestedRect); for(int row=0; row < 3; row++) { for(int col=0; col < 3; col++) { Rect<int> subZone(col * colWidth + zone.left, row * rowHeight + zone.top, colWidth, rowHeight); drawTTT(subZone, Color(0x25, 0x4e, 0xc4), 4, 0); } } drawTTT(zone, Color::Black, 8, 0); for(int over=0; over < 10; over++) { for(int nested=0; nested < 9; nested++) { switch(gameStatus.board[over][nested]) { case CIRCLE: drawCircle(Cell(over, nested)); break; case CROSS: drawCross(Cell(over, nested)); break; default: break; } } } switch(gameStatus.winner) { case CIRCLE: drawCircle(zone, 0xff/2); break; case CROSS: drawCross(zone, 0xff/2); break; default: break; } }
void Toolbar::drawBar(RenderWindow & window) { int width = TILE_SIZE*(drawTools.size()+ mainTools.size()) + 40 + 5 * (drawTools.size() - 1); //build framework RectangleShape framework; framework.setPosition((window.getSize().x - width) / 2, 0); framework.setSize(Vector2f(width, TILE_SIZE+10)); framework.setFillColor(Color(140,140,140,255)); window.draw(framework); //Add tools for (int i = 0; i < drawTools.size()+mainTools.size(); i++) { if (i < drawTools.size()) { drawTools[i]->setPosition(framework.getPosition().x + 10 + (TILE_SIZE + 5)*i, 5); window.draw(*drawTools[i]); } else { mainTools[i- drawTools.size()]->setPosition(framework.getPosition().x + 30 + (TILE_SIZE + 5)*i, 5); window.draw(*mainTools[i - drawTools.size()]); } } }
void drawSprite(Sprite &spr, RenderTarget &target) { RectangleShape shape; Texture &sftexture = const_cast<Texture&>(*spr.getTexture()); FloatRect r = spr.getLocalBounds(); shape.setSize(Vector2f(r.width, r.height)); shape.setOrigin(spr.getOrigin()); shape.setRotation(spr.getRotation()); shape.setPosition(spr.getPosition()); shape.setScale(spr.getScale()); shape.setTexture(spr.getTexture()); shape.setFillColor(spr.getColor()); sftexture.setRepeated(false); target.draw(shape); sftexture.setRepeated(true); }
void step_two(RectangleShape &rectangle, float time, float &x, float &y, int &step, int number_block, float &rotation) { if (x < WINDOW_SIZE.x - RECTANGLES_SIZE.x / 2) { x += time * 0.08; if (y > WINDOW_SIZE.y / 2) y -= time * 0.08; else rotation += time * 0.105; } else { rotation = 540; step = MOVE_RIGHT_AND_TURN; rectangle.setFillColor(Color::Yellow); } }
void Renderer::drawFilledRectangle(const Rectangle& t, Color color, optional<Color> outline) { addRenderElem([this, t, color, outline] { static RectangleShape r; r.setSize(Vector2f(t.getW(), t.getH())); r.setPosition(t.getPX(), t.getPY()); r.setFillColor(color); if (outline) { r.setOutlineThickness(-2); r.setOutlineColor(*outline); } else r.setOutlineThickness(0); display.draw(r); }); }
void update() { shape.move(velocity); // To move the paddle, we check if the user is pressing // the left or right arrow key: if so, we change the velocity. // To keep the paddle "inside the window", we change the velocity // only if its position is inside the window. if(Keyboard::isKeyPressed(Keyboard::Key::Left) && left() > 0) velocity.x = -paddleVelocity; else if(Keyboard::isKeyPressed(Keyboard::Key::Right) && right() < windowWidth) velocity.x = paddleVelocity; // If the user isn't pressing anything, stop moving. else velocity.x = 0; }
void Game::interfejs(float hp, float bullets, Text &h, Text &b, Vector2f poz, float magazynek, int runda, Text &round, int ile_zombii, Text &licznik_zombie, Text &gun_name, string gun, RectangleShape &sprint, bool isSprint, Time czas) { h.setString("hp: "+to_string((int)hp)); b.setString("bullets: "+to_string((int)magazynek)+" / " +to_string((int)bullets)); h.setPosition(poz.x + 1280 / 2-80, poz.y - 360+20); b.setPosition(poz.x + 1280 / 2 - 265, poz.y + 360 - 40); gun_name.setString(gun); gun_name.setPosition(poz.x + 1280 / 2 - 265, poz.y + 360 - 80); round.setString("round: " + to_string(runda)); round.setPosition(poz.x - 1280 / 2 + 10, poz.y + 360 - 40); licznik_zombie.setString("zombies left to kill: " + to_string(ile_zombii)); licznik_zombie.setPosition(poz.x - 1280 / 2 +10 , poz.y - 360 + 20); sprint.setPosition(poz.x + 1280 / 2 - 90, poz.y - 360 + 70); if(isSprint && sprint.getSize().x >0) sprint.setSize(Vector2f(sprint.getGlobalBounds().width -(15.0f*czas.asSeconds()), sprint.getGlobalBounds().height )); else { if(sprint.getSize().x <= 15*5)sprint.setSize(Vector2f(sprint.getGlobalBounds().width + (7.5f*0.5f*czas.asSeconds()), sprint.getGlobalBounds().height)); } }