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 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); }
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 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);*/ }
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(); };
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(); };
//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); }
void Scoring::Initialize() { font.loadFromFile("./Resources/Fonts/jokerman.ttf"); points_graphics.setFont(font); points_graphics.setCharacterSize(24); points_graphics.setString("0"); }
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]); } }
//Player constructor. Player(sf::Texture& texture, sf::Texture& hpImage, int x, int y, sf::Font& font) { mSprite.setTexture(texture); mRect = sf::FloatRect(x, y, 120, 110); //Character x, y, width, height. mName = "Player 1"; mTextName.setString(mName); mTextName.setFont(font); mTextName.setCharacterSize(30); mTextName.setStyle(sf::Text::Bold); mTextName.setColor(sf::Color::Red); mHpSprite.setTexture(hpImage); mHpSprite.setTextureRect(sf::IntRect(0, 0, 100, 10)); mSprite.setTextureRect(sf::IntRect(0, 15, 120, 110)); mSpeed = 0.1; mMovement.x = 0; mMovement.y = 0; mCurrentFrame = 0; mAnimationSpeed = 0.005; mIsAlive = true; mHP = 100; mMaxHp = 100; mMP = 100; }
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 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 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 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); }
// This function displays text to the screen. It takes the text // // to be displayed, the location to display it, the size of the // // text, and the color of the text void FontManager::SetText(sf::Text& txt, string text, int x, int y, int size, sf::Color color, bool setOrigin) { txt.setFont(font); txt.setString(text); txt.setPosition(x, y); txt.setCharacterSize(size); txt.setColor(color); //if (setOrigin) //txt.setOrigin(txt.getGlobalBounds().width / 2.0f, txt.getLocalBounds().height / 2.0f); }
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); }
// Set some information about the object inline void set_info(int str, sf::Font *font, int size) { info_str.setString(std::to_string(str)); info_str.setFont(*font); info_str.setCharacterSize(size); info_str.setColor(sf::Color::Black); health_bar_bg.setSize(sf::Vector2f(get_max_hp()/scale, 10)); health_bar_bg.setOutlineColor(sf::Color(125,125,125)); health_bar_bg.setOutlineThickness(1); health_bar_current.setSize(sf::Vector2f(str/scale, 10)); health_bar_current.setFillColor(get_life_color(str)); }
StatusBox(uint _x, uint _y, float _width, float _height, const GuiStyle& _style) : BaseBox(_x, _y, _width, _height, _style) { blackbox = new sf::RectangleShape(); blackbox->setFillColor(sf::Color::Black); blackbox->setSize({_width, _height}); blackbox->setPosition(sf::Vector2f(_x, _y)); textbox = new sf::Text; textbox->setPosition(_x, _y); textbox->setFont(*style.font); textbox->setCharacterSize(style.fontsize); }
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(); };
// Constructeur & destructeur Observer(const sf::Vector2f& center) { //sf::Font font; assert(_font.loadFromFile("vera.ttf") == true); _text.setColor(sf::Color::White); _text.setFont(_font); _text.setCharacterSize(50); _text.setStyle(sf::Text::Italic); _border.setPosition(center); _border.setOutlineColor(sf::Color::White); _border.setOutlineThickness(2.0); _border.setFillColor(sf::Color::Transparent); }
GameEnd(sf::String message, float durationParam = 1.0f) : timer(0.0f), duration(durationParam), color(0xff, 0, 0, 0) { text.setFont(font); text.setCharacterSize(64); text.setScale(0.002f, 0.002f); text.setString(message); }
/* PRIVATE function are not supposed to be called from outside VisualNovel namespace even though it's accessible from global. it can lead to errors if called */ void Init(){ //get the image for the text's background log_background = get_image( "resource/LogBackground.png" ); //set the volume to the default global volume SoundFx.setVolume( MUSIC_VOLUME ); static bool loaded = false; if( !loaded ) //to prevent double calling { font_display.loadFromFile( "resource/PTN57F.ttf" ); log_text_display.setFont( font_display ); log_text_display.setCharacterSize( 24 ); log_text_display.setColor( sf::Color( 255, 255, 255 ) ); log_text_display.setPosition( log_x + log_padding_x, log_y + log_padding_y ); log_name_display.setFont( font_display ); log_name_display.setCharacterSize( 40 ); log_name_display.setColor( sf::Color( 255, 255, 255 ) ); log_name_display.setPosition( log_x + log_padding_x, log_y - log_to_name_y - 40 ); } }
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]); } }
int log_setup_1(){ //Load Font if( PTSANS_loaded == false ){ if (!PTSANS.loadFromFile("PTN57F.ttf")) return -1; PTSANS_loaded = true; } texture_3.loadFromFile( "Temp_log.png" ); //Setup Strings log_string.setFont( PTSANS ); log_string.setCharacterSize(24); log_string.setColor( sf::Color(255, 255, 255) ); log_string.setPosition(90.f, 600.f); log_name.setFont( PTSANS ); log_name.setCharacterSize(40); log_name.setColor( sf::Color(255, 255, 255) ); log_name.setPosition(90.f, 535.f); log_back.setTexture( texture_3, false ); log_back.setPosition( 0.f, 580.f ); }
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); }
hud() { tex_paskaHp[ 0 ].loadFromFile( "gfx/pasek_hpTlo.png" ); tex_paskaHp[ 1 ].loadFromFile( "gfx/pasek_hp.png" ); tex_paskaBonusu[ 0 ].loadFromFile( "gfx/pasek_bonusTlo.png" ); tex_paskaBonusu[ 1 ].loadFromFile( "gfx/pasek_bonus.png" ); spr_paskaHp.setTexture( tex_paskaHp[ 0 ] ); spr_paskaBonusu.setTexture( tex_paskaBonusu[ 0 ] ); tex_tla.loadFromFile( "gfx/tlo0.png" ); czcionka.loadFromFile( "font/Barme Reczny.ttf" ); tekst.setFont( czcionka ); tekst.setCharacterSize( 18 ); timer[ 0 ] = 0; timer[ 1 ] = 0; typ_bonusu = 0; alphaPaskaBonusu = 0.0001; // spr_paskaBonusu.setColor( sf::Color( 255, 255, 255, alphaPaskaBonusu ) ); }
void TextBox::Setup(int visible, int charSize, int width, sf::Vector2f screenPos) { _numVisible = visible; sf::Vector2f offset(2.0f, 2.0f); _font.loadFromFile("arial.ttf"); _content.setFont(_font); _content.setString(""); _content.setCharacterSize(charSize); _content.setColor(sf::Color::White); _content.setPosition(screenPos + offset); auto backdropHeight = visible * (charSize * 1.2f); _backdrop.setSize(sf::Vector2f(width, backdropHeight)); _backdrop.setFillColor(sf::Color(90, 90, 90, 90)); _backdrop.setPosition(screenPos); }