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 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 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]); } }
void origin_from_text(sf::Text text) { const sf::FloatRect rectangle{text.getLocalBounds()}; text.setOrigin(0.5f*rectangle.width, 0.95f*rectangle.height); }
void set_origin() { const sf::FloatRect rectangle{m_text.getLocalBounds()}; m_text.setOrigin(0.5f*rectangle.width, 0.95f*rectangle.height); }
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); } }
//will update the string of the text if needed and color and will keep the text centered if specified void FontManager::UpdateText(sf::Text& text, const char* txt, sf::Color color, bool setOrigin) { if (txt != NULL) text.setString(txt); if (setOrigin) text.setOrigin(text.getGlobalBounds().width / 2.0f, text.getLocalBounds().height / 2.0f); text.setColor(color); }
void MenuScreen::generateGameModeButton(sf::Text& button, const string& modeName, short position, const sf::Font *font, const sf::Vector2u& screenSize ) { button = sf::Text( modeName, *font ); button.setColor( sf::Color::Blue ); button.setStyle( sf::Text::Regular ); sf::FloatRect textRect = button.getGlobalBounds(); button.setOrigin( textRect.left + textRect.width / 2.0f, textRect.top + textRect.height / 2.0f ); button.setPosition( screenSize.x / 2, screenSize.y * 0.2 + position * Constants::LENGTH_BUTTON_SEPERATION ); }
void drawNumbers(sf::RenderWindow & window,sf::Text & text, float bgHeight) { std::string textNum; sf::Vector2f position = getCenter(window); for (int i = 0; i < NUMBER_OF_DIGITS; i++) { position = polarToCartesianSys(bgHeight * 0.5f - text.getGlobalBounds().height * 2, 30.f * ( i + 1 ) - 90); text.setString(std::to_string( i + 1 )); text.setOrigin(text.getGlobalBounds().width * 0.5f, text.getGlobalBounds().height * 0.5f); text.setPosition(position.x + window.getSize().x * 0.5f, position.y + window.getSize().y * 0.5f); 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(); };
virtual void init() { dt=0; if (!standard_font.loadFromFile("fonts/Unique.ttf")) { // error... } darken = sf::RectangleShape(sf::Vector2f(800,400)); tit.setFont(standard_font); subtit.setFont(standard_font); tit.setString(title); subtit.setString(subtitle); tit.setCharacterSize(24); subtit.setCharacterSize(18); // dla centrowania obiektow sf::FloatRect tempt = tit.getGlobalBounds(); sf::FloatRect temps = subtit.getGlobalBounds(); tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2)); subtit.setOrigin(sf::Vector2f(temps.width/2,temps.height/2)); tit.setPosition(400,150); subtit.setPosition(400,180); timer.restart(); };
void endGame() { endTitle.setFont(myFont); endTitle.setCharacterSize(WIDTH / 16); endTitle.setStyle(sf::Text::Bold); endTitle.setColor(sf::Color::Black); string str; if (end1P) { stringstream message; message << "Final score: " << mover; str = message.str(); } else if (end2P) { stringstream message; message << "Player " << mover << " wins!"; str = message.str(); } endTitle.setString(str); endTitle.setOrigin(endTitle.getLocalBounds().width / 2, endTitle.getLocalBounds().height / 2); endTitle.setPosition(WIDTH / 2, 2 * HEIGHT / 5); sf::Vector2f menuRectSize(3 * WIDTH / 16, HEIGHT / 8); for (int i = 0; i < endMenuRect.size(); i++) { endMenuRect[i].setSize(menuRectSize); endMenuRect[i].setFillColor(grey); endMenuRect[i].setOrigin(menuRectSize.x / 2, menuRectSize.y / 2); endMenuRect[i].setPosition(WIDTH / 2, 4 * HEIGHT / 5); endMenuText[i].setFont(myFont); endMenuText[i].setCharacterSize(2 * pause.getCharacterSize() / 5); endMenuText[i].setStyle(sf::Text::Bold); endMenuText[i].setColor(sf::Color::Black); endMenuText[i].setString(endMenuCommands[i]); endMenuText[i].setOrigin(endMenuText[i].getLocalBounds().width / 2, endMenuText[i].getLocalBounds().height / 2); endMenuText[i].setPosition(endMenuRect[i].getPosition().x, endMenuRect[i].getPosition().y); } BILLIARDS.draw(endTitle); for (int i = 0; i < endMenuRect.size(); i++) { BILLIARDS.draw(endMenuRect[i]); BILLIARDS.draw(endMenuText[i]); } }
void showMenu(Game1 & game, MenuText & menu_text, sf::Text & text, MenuImg & fon, menuBools & bools) { game.window->draw(*fon.sprite); if (!bools.about) { text.setString(menu_text.new_game); menu_text.new_game_rect = { fon.sprite->getPosition().x - menu_text.new_game_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.new_game_pos.y, text.getLocalBounds().width, text.getLocalBounds().height }; _choose_color(text, game.pos, menu_text.new_game_rect); text.setOrigin(text.getLocalBounds().width / 2, 0); text.setPosition(fon.sprite->getPosition().x - menu_text.new_game_pos.x, fon.sprite->getPosition().y - menu_text.new_game_pos.y); game.window->draw(text); text.setString(menu_text.continue_game); menu_text.continue_game_rect = { fon.sprite->getPosition().x - menu_text.continue_game_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.continue_game_pos.y, text.getLocalBounds().width, text.getLocalBounds().height }; if (bools.first_play) { text.setColor(Color(128, 128, 128)); } else { _choose_color(text, game.pos, menu_text.continue_game_rect); } text.setOrigin(text.getLocalBounds().width / 2, 0); text.setPosition(fon.sprite->getPosition().x - menu_text.continue_game_pos.x, fon.sprite->getPosition().y - menu_text.continue_game_pos.y); game.window->draw(text); text.setString(menu_text.about); menu_text.about_rect = { fon.sprite->getPosition().x - menu_text.about_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.about_pos.y, text.getLocalBounds().width, text.getLocalBounds().height }; _choose_color(text, game.pos, menu_text.about_rect); text.setOrigin(text.getLocalBounds().width / 2, 0); text.setPosition(fon.sprite->getPosition().x - menu_text.about_pos.x, fon.sprite->getPosition().y - menu_text.about_pos.y); game.window->draw(text); text.setString(menu_text.exit); menu_text.exit_rect = { fon.sprite->getPosition().x - menu_text.exit_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.exit_pos.y, text.getLocalBounds().width, text.getLocalBounds().height }; _choose_color(text, game.pos, menu_text.exit_rect); text.setOrigin(text.getLocalBounds().width / 2, 0); text.setPosition(fon.sprite->getPosition().x - menu_text.exit_pos.x, fon.sprite->getPosition().y - menu_text.exit_pos.y); game.window->draw(text); } else { text.setColor(Color::Red); text.setString(menu_text.about_text); text.setOrigin(text.getLocalBounds().width / 2, 0); text.setPosition(fon.sprite->getPosition().x - menu_text.about_text_pos.x, fon.sprite->getPosition().y - menu_text.about_text_pos.y); game.window->draw(text); text.setString(menu_text.back); menu_text.back_rect = { fon.sprite->getPosition().x - menu_text.back_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.back_pos.y, text.getLocalBounds().width, text.getLocalBounds().height }; _choose_color(text, game.pos, menu_text.back_rect); text.setOrigin(text.getLocalBounds().width / 2, 0); text.setPosition(fon.sprite->getPosition().x - menu_text.back_pos.x, fon.sprite->getPosition().y - menu_text.back_pos.y); game.window->draw(text); } }
void CenterTextVert(sf::Text& message, const sf::RenderTarget& target) { sf::FloatRect message_bounds = message.getLocalBounds(); message.setOrigin(0, message_bounds.top + (message_bounds.height/2.f)); message.setPosition(message.getPosition().x, target.getSize().y/2.f); }
void centerAlignText(sf::Text& t) { sf::FloatRect r = t.getLocalBounds(); t.setOrigin(r.width / 2, 0); }
inline void centerOrigin(sf::Text& text) { sf::FloatRect bounds = text.getLocalBounds(); text.setOrigin(std::floor(bounds.left + bounds.width / 2.f), std::floor(bounds.top + bounds.height / 2.f)); }
void CenterText(sf::Text& message, const sf::RenderTarget& target) { sf::FloatRect message_bounds = message.getLocalBounds(); message.setOrigin(message_bounds.left + (message_bounds.width/2.0f), message_bounds.top + (message_bounds.height/2.0f)); message.setPosition(sf::Vector2f(target.getSize() / (unsigned)2)); }
void CenterTextHor(sf::Text& message, const sf::RenderTarget& target) { sf::FloatRect message_bounds = message.getLocalBounds(); message.setOrigin(message_bounds.left + (message_bounds.width/2.f), 0); message.setPosition(target.getSize().x/2.f, message.getPosition().y); }
void MameUIsenWindow::centerElement(sf::Text& text) { sf::FloatRect fr = text.getLocalBounds(); text.setOrigin(fr.left + fr.width/2.0f, fr.top + fr.height/2.0f); }
Player () { PlayerNumber = totalPlayers; Sprite = loadSpriteData("Player " + intToString(PlayerNumber + 1)); //Get Global width, seperate to rotation CharacterWidth = Sprite.getGlobalBounds().width; nameSpacing = 30; healthBarSpacing = nameSpacing + 15; Sprite.setOrigin(Sprite.getGlobalBounds().width/2, Sprite.getGlobalBounds().height/2); Sprite.setPosition((App.getSize().x/2) - (Sprite.getGlobalBounds().width/2), (App.getSize().y/2) - (Sprite.getGlobalBounds().height/2)); //PlayerName.setFont(sf::Font::getDefaultFont()); PlayerName.setCharacterSize(15); PlayerName.setString("Player: " + intToString(PlayerNumber + 1)); PlayerName.setOrigin(PlayerName.getGlobalBounds().width/2, PlayerName.getGlobalBounds().height/2); PlayerName.setPosition(Sprite.getPosition().x, Sprite.getPosition().y + nameSpacing); NameOutline.setSize(sf::Vector2f(PlayerName.getGlobalBounds().width, PlayerName.getGlobalBounds().height)); NameOutline.setOutlineThickness(2); NameOutline.setFillColor(sf::Color(0, 0, 0, 120)); NameOutline.setOutlineColor(sf::Color::Black); NameOutline.setOrigin(NameOutline.getGlobalBounds().width/2, NameOutline.getGlobalBounds().height/2); NameOutline.setPosition(Sprite.getPosition().x + 1.5, Sprite.getPosition().y + nameSpacing + 4); MaxHealth = Health = 100; HealthBarSize = 50; HealthBarRed.setSize(sf::Vector2f(HealthBarSize, 5)); HealthBarRed.setOutlineThickness(1); HealthBarRed.setFillColor(sf::Color::Red); HealthBarRed.setOutlineColor(sf::Color::Black); HealthBarRed.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing); HealthBarGreen.setSize(sf::Vector2f(HealthBarSize, 5)); HealthBarGreen.setOutlineThickness(1); HealthBarGreen.setFillColor(sf::Color::Green); HealthBarGreen.setOutlineColor(sf::Color::Black); HealthBarGreen.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing); if (controllerConnected) { ControlScheme = ControlSchemes::Joystick; Key k; k.InputType = Input::JoystickMovedNeg; k.KeyCode = sf::Joystick::Axis::Y; Bindings["Up"] = k; k.InputType = Input::JoystickMovedPos; k.KeyCode = sf::Joystick::Axis::Y; Bindings["Down"] = k; k.InputType = Input::JoystickMovedNeg; k.KeyCode = sf::Joystick::Axis::X; Bindings["Left"] = k; k.InputType = Input::JoystickMovedPos; k.KeyCode = sf::Joystick::Axis::X; Bindings["Right"] = k; } else { ControlScheme = ControlSchemes::KeyboardMouse; Key k; k.InputType = Input::KeyboardInput; k.KeyCode = sf::Keyboard::W; Bindings["Up"] = k; k.InputType = Input::KeyboardInput; k.KeyCode = sf::Keyboard::S; Bindings["Down"] = k; k.InputType = Input::KeyboardInput; k.KeyCode = sf::Keyboard::A; Bindings["Left"] = k; k.InputType = Input::KeyboardInput; k.KeyCode = sf::Keyboard::D; Bindings["Right"] = k; } totalPlayers++; }
void centerOrigin(sf::Text& text) { sf::FloatRect bounds = text.getLocalBounds(); text.setOrigin(bounds.left + bounds.width / 2.f, bounds.top + bounds.height / 2.f); }
void centerTextOrigin( sf::Text& text ) { text.setOrigin( text.getLocalBounds().width / 2, text.getLocalBounds().height / 2 ); }