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); }
void initialize(sf::RenderWindow &mainWindow, sf::Font &mainFont) { titleText.setFont(mainFont); titleText.setString("Triangle Super"); titleText.setCharacterSize(72); titleText.setPosition(mainWindow.getSize().x/2 - titleText.getGlobalBounds().width/2.f, mainWindow.getSize().y/2 - titleText.getGlobalBounds().height/2.f); playText.setFont(mainFont); playText.setString("Play!"); playText.setCharacterSize(30); playText.setPosition(mainWindow.getSize().x/3 - playText.getGlobalBounds().width/2.f, mainWindow.getSize().y/3 *2 - playText.getGlobalBounds().height/2.f); quitText.setFont(mainFont); quitText.setString("Quit."); quitText.setCharacterSize(30); quitText.setPosition(mainWindow.getSize().x/3 *2 - quitText.getGlobalBounds().width/2.f, mainWindow.getSize().y/3*2-quitText.getGlobalBounds().height/2.f); scoreText.setFont(mainFont); scoreText.setCharacterSize(30); scoreText.setPosition(mainWindow.getSize().x/2 - scoreText.getGlobalBounds().width/2.f, mainWindow.getSize().y/3-scoreText.getGlobalBounds().height/2.f); }
void LogMessageWindow::addMessage(sf::Text msg){ if (msg_queue.empty()){ std::cout << "Msg queue is empty\n"; //reposition the text to the boundaries of the message log window msg.setPosition(sf::Vector2f(this->message_window_background.getPosition().x + 10, this->message_window_background.getPosition().y + message_window_background.getSize().y - 14 )); } //When the number of messages in the queue reach the height of the message window, clear it. else if ( ((int)message_window_background.getSize().y / 14) == msg_queue.size()){//Division by constant, constant is the position of each message msg_queue.clear(); msg.setPosition(sf::Vector2f(this->message_window_background.getPosition().x + 10, this->message_window_background.getPosition().y + message_window_background.getSize().y - 14)); } else{ std::cout << "Msg queue is NOT empty\n"; msg.setPosition(sf::Vector2f(message_window_background.getPosition().x + 10, msg_queue.back().getPosition().y - 14.0f)); } msg_queue.push_back(msg); }
void Scoring::Draw(unsigned int p_num, int score) { std::stringstream pointsStream; pointsStream << score; points_graphics.setString(pointsStream.str()); switch(p_num) { case 0: points_graphics.setPosition(5,5); break; case 1: points_graphics.setPosition(WindowManager::GetSize().x - points_graphics.getGlobalBounds().width - 5,5); break; case 2: points_graphics.setPosition(5,WindowManager::GetSize().y - points_graphics.getGlobalBounds().height - 5); break; case 3: points_graphics.setPosition(WindowManager::GetSize().x - points_graphics.getGlobalBounds().width - 5,WindowManager::GetSize().y - points_graphics.getGlobalBounds().height - 5); break; } WindowManager::Draw(points_graphics); }
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); }
void WindowCreateThing::init(sf::RenderWindow &window) { rectTitle.setSize(sf::Vector2f(window.getSize().x*0.45, window.getSize().y*0.07)); rectTitle.setPosition(sf::Vector2f(window.getSize().x/2-(rectTitle.getSize().x/2), window.getSize().x/4-(rectTitle.getSize().y/2))); rectTitle.setFillColor(sf::Color(158, 158, 158)); rectTitle.setOutlineColor(sf::Color::Black); rectTitle.setOutlineThickness(1.f); rectMain.setSize(sf::Vector2f(window.getSize().x*0.45,window.getSize().y*0.45)); rectMain.setPosition(sf::Vector2f(rectTitle.getPosition().x, rectTitle.getPosition().y+rectTitle.getSize().y)); rectMain.setFillColor(sf::Color::White); rectMain.setOutlineColor(sf::Color::Black); rectMain.setOutlineThickness(1.f); load(); starting_position = sf::Mouse::getPosition(window); textTitle.setFont(font); textTitle.setString("CreateThings.txt"); textTitle.setCharacterSize(24); textTitle.setColor(sf::Color::White); textTitle.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x*0.3, rectTitle.getPosition().y+rectTitle.getSize().y*0.1)); //textTitle.setPosition(sf::Vector2f(400,10)); textClose.setFont(font); textClose.setString("X"); textClose.setStyle(sf::Text::Bold); textClose.setCharacterSize(35); textClose.setColor(sf::Color::White); textClose.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x-30, rectTitle.getPosition().y+rectTitle.getSize().y*0.05)); ///// FOLDER ICONE textureFolder.setSmooth(true); spriteFodler.setTexture(textureFolder); sf::Vector2f targetSize(25.0f, 25.0f); spriteFodler.setScale( targetSize.x / spriteFodler.getLocalBounds().width, targetSize.y / spriteFodler.getLocalBounds().height); spriteFodler.setPosition(sf::Vector2f(textTitle.getPosition().x-targetSize.x, textTitle.getPosition().y)); ///// CLOSE ICONE /*textureClose.setSmooth(true); spriteClose.setTexture(textureClose); sf::Vector2f targetSize2(window.getSize().y*0.07, window.getSize().y*0.07); spriteClose.setScale( targetSize2.x / spriteClose.getLocalBounds().width, targetSize2.y / spriteClose.getLocalBounds().height); spriteClose.setPosition(rectTitle.getPosition().x+rectTitle.getSize().x-targetSize2.x, rectTitle.getPosition().y);*/ }
void draw_shadow_text(sf::RenderWindow& window, sf::Text& text, sf::Color color, int x, int y) { text.setColor(sf::Color::Black); text.setPosition(x + 5, y + 5); window.draw(text); text.setColor(color); text.setPosition(x, y); window.draw(text); }
virtual void init() { dt=0; if (!standard_font.loadFromFile("fonts/Unique.ttf")) { // error... } darken = sf::RectangleShape(sf::Vector2f(800,400)); tit.setFont(standard_font); tit.setString("Made by"); explain.setFont(standard_font); explain.setString("Just a bored slacker"); explain.setCharacterSize(36); explain.setPosition(260,320); tit.setCharacterSize(24); // dla centrowania obiektow sf::FloatRect tempt = tit.getGlobalBounds(); tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2)); tit.setPosition(400,120); if (!tex.loadFromFile("gfx/jabslogo.png")) { std::cout<<"Fuckup"<<std::endl; } spr.setTexture(tex); spr.setPosition(334,144); timer.restart(); };
bool startMenu(sf::Text title, sf::Text anyKey, sf::Text credits, sf::RenderWindow& window) { // create and load texture for earth.png sf::Texture earth; if(!earth.loadFromFile("img/earth2.png")) cout << "Error, could not load earth.png" << endl; sf::Sprite earthSprite; earthSprite.setTexture(earth); earthSprite.setPosition(WINDOW_WIDTH / 4 , WINDOW_HEIGHT / 4); // set title color, position, size and style title.setColor(sf::Color::Black); title.setPosition(WINDOW_WIDTH / 5, 0); title.setCharacterSize(50); title.setStyle(sf::Text::Bold); // set anyKey position and color anyKey.setPosition(WINDOW_WIDTH / 4.5, 410); anyKey.setColor(sf::Color::Black); credits.setPosition(WINDOW_WIDTH / 2.6, 450); credits.setCharacterSize(10); credits.setColor(sf::Color::Black); while(window.isOpen()) { sf::Event event; while (window.pollEvent(event)) // process events { // QUIT if (event.type == sf::Event::Closed) { window.close(); // close the window return false; } // if the user presses any key if(event.type == sf::Event::KeyPressed || event.type == sf::Event::MouseButtonPressed) return true; } window.clear(sf::Color(255, 255, 235, 0)); window.draw(earthSprite); window.draw(title); window.draw(anyKey); window.draw(credits); window.display(); } return false; }
void initTexts() { if (!font.loadFromFile("arial.ttf"))cout << "error"; endText.setFont(font); endText.setString("Game Over"); endText.setCharacterSize(50); endText.setColor(sf::Color( 156, 39, 176)); endText.setPosition(SIZE/2-100,SIZE/2-100); scoreText.setFont(font); scoreText.setCharacterSize(50); scoreText.setColor(sf::Color(255,255,255)); scoreText.setPosition(SIZE/2-200,SIZE/2); }
virtual void init() { dt=0; if (!standard_font.loadFromFile("fonts/Unique.ttf")) { // error... } darken = sf::RectangleShape(sf::Vector2f(800,400)); tit.setFont(standard_font); score.setFont(standard_font); std::stringstream ss; ss << your_score; std::string str = ss.str(); tit.setString("Congrats! You beat the game\nIt took you:"); score.setString(str + " seconds"); tit.setCharacterSize(24); score.setCharacterSize(24); // dla centrowania obiektow sf::FloatRect tempt = tit.getGlobalBounds(); sf::FloatRect tempr = score.getGlobalBounds(); tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2)); score.setOrigin(sf::Vector2f(tempr.width/2,tempr.height/2)); tit.setPosition(400,150); score.setPosition(400,200); score.setColor(sf::Color(0,127,127)); timer.restart(); };
void pauseMenu() { pause.setFont(myFont); pause.setCharacterSize(WIDTH / 16); pause.setStyle(sf::Text::Bold); pause.setColor(sf::Color::Black); pause.setString("PAUSE"); pause.setOrigin(pause.getLocalBounds().width / 2, pause.getLocalBounds().height / 2); pause.setPosition(WIDTH / 2, 3 * HEIGHT / 16); sf::Vector2f menuRectSize(3 * WIDTH / 16, HEIGHT / 8); for (int i = 0; i < pauseMenuRect.size(); i++) { pauseMenuRect[i].setSize(menuRectSize); pauseMenuRect[i].setFillColor(grey); pauseMenuRect[i].setOrigin(menuRectSize.x / 2, menuRectSize.y / 2); pauseMenuRect[i].setPosition(WIDTH / 2, 6 * HEIGHT / 16 + i * (5 * HEIGHT / 32)); pauseMenuText[i].setFont(myFont); pauseMenuText[i].setCharacterSize(2 * pause.getCharacterSize() / 5); pauseMenuText[i].setStyle(sf::Text::Bold); pauseMenuText[i].setColor(sf::Color::Black); pauseMenuText[i].setString(pauseMenuCommands[i]); pauseMenuText[i].setOrigin(pauseMenuText[i].getLocalBounds().width / 2, pauseMenuText[i].getLocalBounds().height / 2); pauseMenuText[i].setPosition(pauseMenuRect[i].getPosition().x, pauseMenuRect[i].getPosition().y); } BILLIARDS.draw(pause); for (int i = 0; i < pauseMenuRect.size(); i++) { BILLIARDS.draw(pauseMenuRect[i]); BILLIARDS.draw(pauseMenuText[i]); } }
inline void draw_on(sf::RenderWindow& window) { window.draw(circ); window.draw(sprite); info_str.setPosition(get_position()); window.draw(info_str); }
void showMission(Game1 & game, MissionText & mission_text, sf::Text & text, Hero & hero, MenuImg & fon, menuBools & bools) { if (!bools.first_play) { switch (hero.player->quest) { case Player::quest_status::start: text.setString(mission_text.start); break; case Player::quest_status::find_car: text.setString(mission_text.find_car); break; case Player::quest_status::find_gaz: text.setString(mission_text.find_gaz); break; case Player::quest_status::find_busket: text.setString(mission_text.find_buscket); break; case Player::quest_status::find_colon: text.setString(mission_text.find_colon); break; case Player::quest_status::go_to_car: text.setString(mission_text.go_to_car); break; } text.setOrigin(text.getLocalBounds().width / 2, 0); text.setPosition(fon.sprite->getPosition().x + 220, fon.sprite->getPosition().y - 250); text.setColor(Color::Red); game.window->draw(text); } else { fon.hand_sprite->setPosition(fon.sprite->getPosition().x + 200, fon.sprite->getPosition().y); game.window->draw(*fon.hand_sprite); } game.aim_sprite->setPosition(game.pos); game.window->draw(*game.aim_sprite); game.window->display(); }
void Item::Draw(sf::RenderWindow& renderWindow, sf::Text &text) { TextureManager *t = Resources::getTextureManager("tileMap"); sf::Sprite s; sf::Vector2f item_pos = GetPosition(); t->generateSprite(id, item_pos, s, sf::Vector2f(GetWidth(),GetHeight())); renderWindow.draw(s); sf::Vector2f test_pos = GetPosition(); text.setPosition(test_pos.x, test_pos.y); text.setScale(sf::Vector2f(1.5,1.5)); renderWindow.draw(text); //renderWindow.draw(_sprite); /*if(amount >0){ char c[10]; sprintf(c, "%i", amount); std::string string(c); sf::String str(string); text.setString(str); text.setPosition(GetPosition().x, GetPosition().y); renderWindow.draw(text); }*/ }
//private function to initialize the text easier //precondition: the Font must have opened correctly void RoundEndScreen::initializeText(sf::Font &font, sf::Text &text, float x_position, float y_position, int size) { text.setFont(font); text.setCharacterSize(size); text.setPosition(x_position, y_position); text.setColor(sf::Color::White); }
//Enemy sprite render. void update(float deltaTime, char** levelMap, struct config* config) { if(mDirection == 0) {mMovement.x = 0; mMovement.y = -mSpeed;} if(mDirection == 1) {mMovement.x = mSpeed; mMovement.y = 0;} if(mDirection == 2) {mMovement.x = 0; mMovement.y = mSpeed;} if(mDirection == 3) {mMovement.x = mSpeed; mMovement.y = 0;} mRect.left += mMovement.x * deltaTime; collision(levelMap, config); mRect.top += mMovement.y * deltaTime; collision(levelMap, config); //Enemy animation. mCurrentFrame += mAnimationSpeed * deltaTime; if(mCurrentFrame > mFrameCount) mCurrentFrame -= mFrameCount; if(mMovement.x > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 925, mRect.width, mRect.height)); if(mMovement.x < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 667, mRect.width, mRect.height)); if(mMovement.y > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 535, mRect.width, mRect.height)); if(mMovement.y < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 787, mRect.width, mRect.height)); mSprite.setPosition(mRect.left - offsetX, mRect.top - offsetY); mTextName.setPosition(mRect.left - offsetX, mRect.top - mTextName.getCharacterSize() - offsetY); }
void rysuj_tekst( sf::RenderWindow & okno, sf::Color kolor, sf::String _tresc, float x, float y ) { tekst.setString( _tresc ); tekst.setColor( kolor ); tekst.setPosition( x, y ); okno.draw( tekst ); tekst.setColor( sf::Color::White ); }
void Game::prepareText(sf::Text &text, int height) { text.setFont(font); text.setCharacterSize(Game::characterSize); text.setStyle(sf::Text::Bold); text.setColor(sf::Color::White); text.setPosition(420, height); }
void rysuj_tekst( sf::RenderWindow & okno, sf::String _tresc, float x, float y ) { double kamera_xHud = kamera.getCenter().x - kamera.getSize().x/2; double kamera_yHud = kamera.getCenter().y - kamera.getSize().y/2; tekst.setString( _tresc ); tekst.setPosition( kamera_xHud + x, kamera_yHud + y ); okno.draw( tekst ); }
void getText(sf::Text & txt, sf::Font & font,char* str, int x, int y, int size) { txt.setFont(font); txt.setString(str); txt.setColor(sf::Color::Black); txt.setPosition(x,y); txt.setCharacterSize(size); }
/** Text drawing for buttons. */ void SpriteManager::draw (sf::Text button_text, int x, int y, int width, int height, sf::RenderWindow &window) { button_text.setFont (font); sf::FloatRect text_rect = button_text.getLocalBounds (); button_text.setPosition ((x + (width / 2)) - (button_text.getLocalBounds ().width / 2), (y + (height / 2)) - (button_text.getLocalBounds ().height));//Centers text to button. window.draw (button_text); }
void rendering::render_time(sf::RenderWindow& screen,const GameInfo& stats) { static sf::Text text; static sf::Font f; f.loadFromFile("../data/Font/Loma.ttf"); text.setFont(f); text.setColor(sf::Color::Red); text.setCharacterSize(24); text.setPosition(700,100); text.setString(stats.GetFormattedElapsed()); screen.draw(text); text.setString(std::to_string(stats.getFps())); text.setPosition(700,125); screen.draw(text); }
void MenuState::createOption(sf::Text& textOption, int order, std::string s){ textOption.setFont(terminal); //This font is blurry need another one! textOption.setCharacterSize(20); textOption.setString(s); textOption.setOrigin(static_cast<int> (textOption.getLocalBounds().width / 2), static_cast<int>(textOption.getLocalBounds().height / 2)); textOption.setPosition(static_cast<int>((window.getDefaultView().getSize().x) / 2), 130 + order*50); textOption.setColor(sf::Color(128,128,128)); }
void MoveDraw() { moves.setFont(myFont); moves.setCharacterSize(12); moves.setStyle(sf::Text::Bold); moves.setColor(sf::Color::Red); moves.setOrigin(moves.getLocalBounds().width / 2, moves.getLocalBounds().height / 2); moves.setPosition(WIDTH * 3 / 4, borderDepth / 2); bestScore.setFont(myFont); bestScore.setCharacterSize(12); bestScore.setStyle(sf::Text::Bold); bestScore.setColor(sf::Color::Red); bestScore.setOrigin(bestScore.getLocalBounds().width / 2, bestScore.getLocalBounds().height / 2); bestScore.setPosition(WIDTH * 1 / 4, borderDepth / 2); stringstream mess2; if (BS != 0) mess2 << "Best Score: " << BS; else mess2 << "Best Score: --"; string message2 = mess2.str(); bestScore.setString(message2); if ((twoPlayerGame) || (pause2P)) { if (mover > 2) mover = 1; stringstream mess; mess << "Player " << mover << "'s turn"; string message = mess.str(); moves.setString(message); BILLIARDS.draw(moves); } else { stringstream mess; mess << "Moves: " << mover; string message = mess.str(); moves.setString(message); BILLIARDS.draw(bestScore); if ((onePlayerGame)||(pause1P)) BILLIARDS.draw(moves); } }
void handle () { rotate(); float percentageHealth = float((Health/MaxHealth) * 100); HealthBarGreen.setSize(sf::Vector2f(percentageHealth * (HealthBarSize / percentageHealth), 5)); NameOutline.setPosition(Sprite.getPosition().x + 1.5, Sprite.getPosition().y + nameSpacing + 4); PlayerName.setPosition(Sprite.getPosition().x, Sprite.getPosition().y + nameSpacing); HealthBarRed.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing); HealthBarGreen.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing); }
virtual void draw(RenderWindow *window) { sf::RectangleShape box(window->getView().getSize()); box.setFillColor(color); text.setPosition((window->getView().getSize() - Vector2f(text.getGlobalBounds().width, text.getGlobalBounds().height)) * 0.5f); window->draw(text); window->draw(box); }
void youWin (sf::Text & txt, sf::Font & font) { txt.setFont(font); // font is a sf::Font // set the string to display txt.setString("You win !!!"); txt.setColor(sf::Color::Black); txt.setPosition(100,100); txt.setCharacterSize(72); }
void GraphicEngine::transformSprite(sf::Text& sprite, const Transformation& t, const Color& color) { if (t.hasPosition()) sprite.setPosition((float)t.getX(), (float)t.getY()); if (t.hasRotation()) sprite.rotate(t.getRotation()); if (color.isUsed()) sprite.setColor(sf::Color(color.getColor())); if (t.hasScale()) sprite.setScale(t.getScaleX(), t.getScaleY()); }
void DebugScreenState::initalizeText(sf::Text& text , sf::Vector2f position , sf::String string) { sf::Font& font = getContext().fonts->get(Fonts::Default); text.setFont(font); text.setCharacterSize(10); text.setColor(sf::Color::White); text.setPosition(position); text.setString(string); }