void menu() { int x, y; bool exit = false, high = false; if(!font.loadFromFile("ethnocentric rg.ttf")) { //error... }; window.clear(); sf::RectangleShape menuSquare(sf::Vector2f(550, 450)); menuSquare.setFillColor(sf::Color(75, 75, 75)); menuSquare.setOutlineThickness(4); menuSquare.setOutlineColor(sf::Color(50, 50, 50)); menuSquare.setPosition(25, 25); sf::RectangleShape play(sf::Vector2f(80, 40)); play.setFillColor(sf::Color(255, 0, 0)); play.setOutlineThickness(4); play.setOutlineColor(sf::Color(255, 50, 0)); play.setPosition(100, 350); playButton.setString("Play"); playButton.setFont(font); playButton.setCharacterSize(20); playButton.setColor(sf::Color(30, 30, 30)); playButton.setPosition(100, 357); sf::RectangleShape High(sf::Vector2f(90, 40)); High.setFillColor(sf::Color(255, 0, 0)); High.setOutlineThickness(4); High.setOutlineColor(sf::Color(255, 50, 0)); High.setPosition(300, 350); HighButton.setString("High\nScores"); HighButton.setFont(font); HighButton.setCharacterSize(15); HighButton.setColor(sf::Color(30, 30, 30)); HighButton.setPosition(300, 350); snake.setString("SNAKE 2.0"); snake.setFont(font); snake.setCharacterSize(50); snake.setColor(sf::Color(30, 30, 255)); snake.setPosition(80, 75); CreatedBy.setString("Created by\nBrandon Aderholdt\nJanuary 10th, 2014"); CreatedBy.setFont(font); CreatedBy.setCharacterSize(15); CreatedBy.setColor(sf::Color(30, 30, 70)); CreatedBy.setPosition(140, 200); window.clear(); while(true){ sf::Event event; while(window.pollEvent(event)) { if(event.type == sf::Event::Closed) window.close(); if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){ sf::Vector2i localPosition = sf::Mouse::getPosition(window); x = localPosition.x; y = localPosition.y; if((x > 100) && (x < 180) && (y < 390) && (y > 350)) { exit = true; } if((x > 300) && (x < 390) && (y < 390) && (y > 350)) { high = true; } } } window.draw(menuSquare); window.draw(High); window.draw(HighButton); window.draw(play); window.draw(playButton); window.draw(snake); window.draw(CreatedBy); window.display(); if(high == true){ highScores(); window.clear(); high = false; HighButton.setString("High\nScores"); HighButton.setFont(font); HighButton.setCharacterSize(15); HighButton.setColor(sf::Color(30, 30, 30)); HighButton.setPosition(300, 350); snake.setString("SNAKE 2.0"); snake.setFont(font); snake.setCharacterSize(50); snake.setColor(sf::Color(30, 30, 255)); snake.setPosition(80, 75); playButton.setString("Play"); playButton.setFont(font); playButton.setCharacterSize(20); playButton.setColor(sf::Color(30, 30, 30)); playButton.setPosition(100, 357); CreatedBy.setString("Created by\nBrandon Aderholdt\nJanuary 10th, 2014"); CreatedBy.setFont(font); CreatedBy.setCharacterSize(15); CreatedBy.setColor(sf::Color(30, 30, 70)); CreatedBy.setPosition(140, 200); } if(exit == true){ for(int i = 4; i <= 0; i--){ play.setOutlineThickness(i); sf::sleep(sf::seconds(1)); window.draw(play); window.display(); } break; } } }
void TeleportToArtifactRoom::draw(sf::RenderWindow& mainWindow){ mainWindow.draw(sprite); }
void Tile::draw(sf::RenderWindow& window) { window.draw(_sprite); }
void GUIMenu::draw(sf::RenderWindow &window) { for (std::vector<sf::Text>::iterator it = text.begin(); it != text.end(); it++) window.draw(*it); }
void particle_system::draw(sf::RenderWindow &window, sf::View view) { window.setView(view); window.draw(va); window.setView(window.getDefaultView()); }
//tell the render window to draw the shape void Bug::Draw(sf::RenderWindow &w) { w.draw(m_shape); }
int ChoosePlayerScreen::Run(sf::RenderWindow & App, Game &game) { sf::Event event; bool running = true; windowWidth = App.getSize().x; windowHeight = App.getSize().y; sf::Font font; if (!font.loadFromFile("fonts/arial.ttf")) std::cerr << "Problem with loading fonts" << std::endl; const float BACK_MENU_BUTTON_POS_X = 0.08; const float BACK_MENU_BUTTON_POS_Y = 0.10; sf::String backToMenuButtonPath("image/MenuButton.png"); sf::String backToMenuHoverButtonPath("image/MenuButtonShadow.png"); ButtonView backToMenuButton(backToMenuButtonPath, backToMenuHoverButtonPath, false); float backToMenuButtonWidth = backToMenuButton.getGlobalBounds().width; float backToMenuButtonHeight = backToMenuButton.getGlobalBounds().height; float backToMenuButtonPosX = windowWidth * BACK_MENU_BUTTON_POS_X - backToMenuButtonWidth * 0.5; float backToMenuButtonPosY = windowHeight * BACK_MENU_BUTTON_POS_Y - backToMenuButtonHeight * 0.5; backToMenuButton.setPosition(sf::Vector2f(backToMenuButtonPosX, backToMenuButtonPosY)); const int MAX_PLAYERS = 6; vector<string> players; std::string choosePlayerText = "Wpisz nazwe gracza"; sf::Text choosePlayerLabel(choosePlayerText, font, 50); choosePlayerLabel.setColor(sf::Color(255, 255, 255, 255)); float choosePlayerPosX = windowWidth * 0.50 - choosePlayerLabel.getGlobalBounds().width * 0.5; float choosePlayerPosY = windowHeight * 0.10 - choosePlayerLabel.getGlobalBounds().height * 0.5; choosePlayerLabel.setPosition(choosePlayerPosX, choosePlayerPosY); std::string playerName; sf::Color textColor = sf::Color::Black; sf::Vector2f frameSize(310, 45); sf::Color frameColor = sf::Color::White; float playerNamePosX = windowWidth * 0.35; float playerNamePosY = windowHeight * 0.32; playerNameTextField = TextField(playerName, font, 35, textColor); playerNameTextField.setFrame(frameSize, frameColor); playerNameTextField.setPositon(sf::Vector2f(playerNamePosX, playerNamePosY)); sf::String addPlayerButtonPath("image/Accept.png"); sf::String addPlayerHoverButtonPath("image/AcceptShadow.png"); ButtonView addPlayerButton(addPlayerButtonPath, addPlayerHoverButtonPath, false); float addPlayerButtonPosX = windowWidth * 0.70 - addPlayerButton.getGlobalBounds().width * 0.5; float addPlayerButtonPosY = windowHeight * 0.35 - addPlayerButton.getGlobalBounds().height * 0.5; addPlayerButton.setPosition(addPlayerButtonPosX, addPlayerButtonPosY); std::string playerText = "Wprowadz nazwy graczy"; sf::Text playerLabel(playerText, font, 30); playerLabel.setColor(sf::Color(255, 255, 255, 255)); float playerLabelPosX = windowWidth * 0.50 - playerLabel.getGlobalBounds().width * 0.5; float playerLabelPosY = windowHeight * 0.50 - playerLabel.getGlobalBounds().height * 0.5; playerLabel.setPosition(playerLabelPosX, playerLabelPosY); sf::String nextButtonPath("image/ForwardButton.png"); ButtonView nextButton(nextButtonPath, nextButtonPath, false); float nextButtonPosX = windowWidth * 0.80 - nextButton.getGlobalBounds().width * 0.5; float nextButtonPosY = windowHeight * 0.80 - nextButton.getGlobalBounds().height * 0.5; nextButton.setPosition(nextButtonPosX, nextButtonPosY); while (running) { while (App.pollEvent(event)) { sf::Mouse mouse; sf::Vector2i mousePos = mouse.getPosition(App); switch (event.type) { case sf::Event::Closed: App.close(); break; case sf::Event::MouseMoved: if (backToMenuButton.isButtonHoverd(mousePos) && mouse.isButtonPressed(sf::Mouse::Left)) { return (0); } if (nextButton.isButtonHoverd(mousePos) && mouse.isButtonPressed(sf::Mouse::Left)) { game.setPlayersNames(players); return (2); } if (addPlayerButton.isButtonHoverd(mousePos) && mouse.isButtonPressed(sf::Mouse::Left) && playerName.size() > 0) { players.push_back(playerName); playerName = ""; playerNameTextField.setString(playerName); playerText = ""; for (string name : players) { if (players.size() < MAX_PLAYERS || name != players.back()) playerText += name + " vs "; else playerText += name; } playerLabel.setString(playerText); playerLabelPosX = windowWidth * 0.50 - playerLabel.getGlobalBounds().width * 0.5; playerLabel.setPosition(playerLabelPosX, playerLabelPosY); } break; case sf::Event::TextEntered: playerName = playerNameTextField.action(event); break; default: break; } } App.clear(sf::Color(56, 134, 185, 255)); App.draw(playerLabel); App.draw(choosePlayerLabel); App.draw(backToMenuButton); playerNameTextField.draw(App); if (!addPlayerButton.isHidden()) App.draw(addPlayerButton); if (players.size() >= 2) App.draw(nextButton); App.display(); } return (-1); }
void BackgroundObject::Render(sf::RenderWindow &window) { window.draw(m_currentAnimation->getSprite()); }
void GameObject::draw (sf::RenderWindow &GameWindow ) { GameWindow.draw(GameObjectSprite); }
void main() { menu(); while(true){ sf::Clock clock, clockInvincible; score1 = 0; int xBlock, yBlock, x, y, seconds = 0, red, green, blue; int direction = 0, directionOfBack = 0, size; bool checkGameOver = false, outOfBounds = false, restarter = false, breaker = false; size = Robjects.size(); Robjects.erase(Robjects.begin()+0, Robjects.begin()+size); window.clear(); //--------------------------------------------------------------------------- //sf::RenderWindow window(sf::VideoMode(600, 500), "Testing"); //--------------------------------------------------------------------------- event.type = sf::Event::Count; sf::RectangleShape square(sf::Vector2f(sizex, sizey)); square.setFillColor(sf::Color(200, 60, 0)); square.setOutlineThickness(2); square.setOutlineColor(sf::Color(140, 30, 0)); //--------------------------------------------------------------------------- sf::RectangleShape egg(sf::Vector2f(sizex + 2, sizey + 2)); egg.setFillColor(sf::Color(red, green, blue)); egg.setOutlineThickness(2); egg.setOutlineColor(sf::Color(200, 200, 200)); //--------------------------------------------------------------------------- setAll(x, y, xBlock, yBlock); //--------------------------------------------------------------------------- egg.setPosition(xBlock, yBlock); //--------------------------------------------------------------------------- setEgg(red, green, blue); while(window.isOpen()) { if(invincible1 == true){ invincible2(x, y); for(int i = 0; i < Robjects.size(); i++){ Robjects[i].setFillColor(sf::Color(200, 50, 50)); Robjects[i].setOutlineThickness(2); Robjects[i].setOutlineColor(sf::Color(40, 40, 40)); } } else outOfBounds = checkOutOfBounds(x , y); sf::Time elapsed1 = clock.getElapsedTime(); seconds = elapsed1.asMilliseconds(); //--------------------------------------------------------------------------- restarter = updateGame(x, y, xBlock, yBlock, direction, directionOfBack, checkGameOver, seconds, red, green, blue); egg.setFillColor(sf::Color(red, green, blue)); if(restarter == true) clock.restart(); directionOfBack = CreateTail(x, y, direction, checkGameOver, false); //--------------------------------------------------------------------------- if((x % 25 == 0)&&(y % 25 == 0)){ //------------------------------------------------------------ while(window.pollEvent(event)) { if(event.type == sf::Event::Closed){ size = Robjects.size(); Robjects.erase(Robjects.begin()+0, Robjects.begin()+size); window.close(); } //--------------------------------------------------------------------- if((event.key.code == sf::Keyboard::P)&&(event.type == sf::Event::KeyPressed)){ window.draw(square); for(int i = 0; i < Robjects.size(); i++) window.draw(Robjects[i]); if(eggs == true){} else window.draw(egg); window.draw(score); window.display(); while(true){ while(window.pollEvent(event)) { if((event.key.code == sf::Keyboard::P)&&(event.type == sf::Event::KeyPressed)) breaker = true; } if(breaker == true) break; } } breaker = false; event.key.code == sf::Keyboard::Q; if(event.type == sf::Event::KeyPressed){ direction = move(direction, x, y); square.setPosition(x,y); } } } //--------------------------------------------------------------------------- if((checkGameOver == true)||(outOfBounds == true)) { window.clear(); window.draw(square); for(int i = 0; i < Robjects.size(); i++) window.draw(Robjects[i]); window.draw(egg); window.draw(score); window.draw(gameOver); exit(); window.clear(); menu(); break; } //--------------------------------------------------------------------------- square.setPosition(x,y); egg.setPosition(xBlock, yBlock); window.clear(); window.draw(square); for(int i = 0; i < Robjects.size(); i++) window.draw(Robjects[i]); if(eggs == false){ window.draw(egg); } else{ for(int i = 0; i < 120; i++) window.draw(egger[i]); } if(invincible == true) { invincible3.setString("I"); invincible3.setFont(font); invincible3.setCharacterSize(10); invincible3.setColor(sf::Color(255, 255, 255)); invincible3.setPosition(xBlock + 4, yBlock + 4); window.draw(invincible3); } window.draw(score); window.display(); if(eggs == true) sf::sleep(sf::seconds(.0009)); else sf::sleep(sf::seconds(.003)); } } //return 0; }
void Chameleon::draw(sf::RenderWindow& window) { window.draw(sprite); if (licking) tongue.draw(window); }
bool addHighScores() { std::ofstream outFile; std::ifstream inFile; std::string filename, name, finalName; std::vector<std::string> names; std::vector<int> scores; int score, count = 0, scored; bool enterIt = false, breaker = false; scored = score1; if(!font.loadFromFile("ethnocentric rg.ttf")) { //error... }; filename = "Highscores.txt"; inFile.open(filename); enterName.setString("Enter Name: "); enterName.setFont(font); enterName.setCharacterSize(20); enterName.setColor(sf::Color(100, 100, 100)); enterName.setPosition(20, 357); nameEnter.setString(name); nameEnter.setFont(font); nameEnter.setCharacterSize(20); nameEnter.setColor(sf::Color(100, 100, 100)); nameEnter.setPosition(225, 357); inFile>>name>>score; while(inFile){ names.push_back(name); scores.push_back(score); inFile>>name>>score; } //------------------------------------------------------------ if(scores.size() == 5){ for(int i = 0; i < scores.size(); i++) { if(scores[i] < scored) enterIt = true; } } //------------------------------------------------------------ else { for(int i = 0; i < scores.size(); i++) { if(scores[i] < scored){ enterIt = true; break; } } if(enterIt != true) enterIt = true; } //-------------------------------------------------------------- int i = 0; name = ""; window.clear(); sf::Event event; if(enterIt == true) { while(true){ if(enterIt = true) window.clear(); enterIt = false; nameEnter.setString(name); window.draw(enterName); window.draw(nameEnter); window.display(); while(window.pollEvent(event)) { switch(event.type){ case sf::Event::TextEntered: if(sf::Keyboard::isKeyPressed(sf::Keyboard::Return)){ breaker = true; break; } else if((event.text.unicode != 8)&&(i < 9)){ name += (char)event.text.unicode; i++; finalName = name; } else if (event.text.unicode == '\b'){ name = name.substr(0, name.length() - 1); window.clear(); enterIt = true; if(!i == 0) i--; } } } if(breaker == true) break; } if(names.size() == 0){ names.push_back(finalName); scores.push_back(scored); } else if(names.size() < 5){ for(int i = 0; i < names.size(); i++){ if(scores[i] < scored){ names.insert(names.begin() + i, finalName); scores.insert(scores.begin() + i, scored); enterIt = true; break; } } if(!enterIt == true){ names.push_back(finalName); scores.push_back(scored); } } else { for(int i = 0; i < names.size(); i++){ if(scores[i] < scored){ names.insert(names.begin() + i, finalName); scores.insert(scores.begin() + i, scored); names.pop_back(); scores.pop_back(); break; } } } inFile.close(); std::ofstream outFile(filename); for(int i = 0; i < names.size(); i++) outFile<<names[i]<<" "<<scores[i]<<std::endl; outFile.close(); return true; } return false; outFile.close(); }
void highScores() { bool exit1 = false; std::string filename, name1, score1; std::vector<sf::Text> HighNames; std::vector<sf::Text> HighScores; int x = 75, y = 100, x2 = 300, y2 = 100, size; filename = "Highscores.txt"; std::ifstream inFile(filename); if(!font.loadFromFile("ethnocentric rg.ttf")) { //error... }; int count = 0; inFile>>name1>>score1; while(count != 5){ HighName.setString(convertInt(count + 1) + ". " + name1); HighName.setFont(font); HighName.setCharacterSize(20); HighName.setColor(sf::Color(50, 50, 50)); HighName.setPosition(x, y + (50 * count)); HighScore.setString(score1); HighScore.setFont(font); HighScore.setCharacterSize(20); HighScore.setColor(sf::Color(50, 50, 50)); HighScore.setPosition(x2, y2 + (50 * count)); HighScoreTitle.setString("High Scores"); HighScoreTitle.setFont(font); HighScoreTitle.setCharacterSize(50); HighScoreTitle.setColor(sf::Color(130, 30, 30)); HighScoreTitle.setPosition(50, 20); menuButton.setString("Menu"); menuButton.setFont(font); menuButton.setCharacterSize(20); menuButton.setColor(sf::Color(100, 100, 100)); menuButton.setPosition(100, 357); sf::RectangleShape menu(sf::Vector2f(80, 40)); menu.setFillColor(sf::Color(255, 0, 0)); menu.setOutlineThickness(4); menu.setOutlineColor(sf::Color(255, 100, 0)); menu.setPosition(100, 350); HighNames.push_back(HighName); HighScores.push_back(HighScore); count++; name1 = ""; score1 = ""; inFile>>name1>>score1; } size = HighNames.size(); window.clear(); window.draw(HighScoreTitle); window.draw(HighNames[0]); window.draw(HighScores[0]); window.draw(HighNames[1]); window.draw(HighScores[1]); window.draw(HighNames[2]); window.draw(HighScores[2]); window.draw(HighNames[3]); window.draw(HighScores[3]); window.draw(HighNames[4]); window.draw(HighScores[4]); window.draw(menuButton); window.display(); while(true){ while(window.pollEvent(event)) { if(event.type == sf::Event::Closed){ size = Robjects.size(); Robjects.erase(Robjects.begin()+0, Robjects.begin()+size); window.close(); } if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){ sf::Vector2i localPosition = sf::Mouse::getPosition(window); x = localPosition.x; y = localPosition.y; if((x > 100) && (x < 180) && (y < 390) && (y > 350)) exit1 = true; } } if(exit1 == true) break; } inFile.close(); window.clear(); }
bool exit() { int x, y, size; bool exit1 = false; if(addHighScores() == true) return true; if(!font.loadFromFile("ethnocentric rg.ttf")) { //error... }; gameOver.setString("Game Over"); gameOver.setFont(font); gameOver.setCharacterSize(50); gameOver.setColor(sf::Color(200, 200, 0)); gameOver.setPosition(85, 200); sf::RectangleShape exit2(sf::Vector2f(80, 40)); exit2.setFillColor(sf::Color(255, 0, 0)); exit2.setOutlineThickness(4); exit2.setOutlineColor(sf::Color(255, 100, 0)); exit2.setPosition(250, 350); sf::RectangleShape menu(sf::Vector2f(80, 40)); menu.setFillColor(sf::Color(255, 0, 0)); menu.setOutlineThickness(4); menu.setOutlineColor(sf::Color(255, 100, 0)); menu.setPosition(100, 350); exitButton.setString("Exit"); exitButton.setFont(font); exitButton.setCharacterSize(20); exitButton.setColor(sf::Color(30, 30, 30)); exitButton.setPosition(260, 357); menuButton.setString("Menu"); menuButton.setFont(font); menuButton.setCharacterSize(20); menuButton.setColor(sf::Color(30, 30, 30)); menuButton.setPosition(100, 357); window.draw(gameOver); window.draw(exit2); window.draw(menu); window.draw(gameOver); window.draw(exitButton); window.draw(menuButton); window.display(); while(true){ while(window.pollEvent(event)) { if(event.type == sf::Event::Closed) window.close(); if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){ sf::Vector2i localPosition = sf::Mouse::getPosition(window); x = localPosition.x; y = localPosition.y; if((x > 100) && (x < 180) && (y < 390) && (y > 350)){ exit1 = true; } else if((x > 250) && (x < 330) && (y < 390) && (y > 350)){ size = Robjects.size(); Robjects.erase(Robjects.begin()+0, Robjects.begin()+size); window.close(); } } } if(exit1 == true) break; size = Robjects.size(); Robjects.erase(Robjects.begin()+0, Robjects.begin()+size); } window.clear(); return true; }
int WaitingMenu::run(sf::RenderWindow &window, CommonData* commonData) { // Create background sf::Sprite background(commonData->defaultBackgroundTexture); // Create menu title Label* lobbyTitle = new Label("Lobby", 100, commonData); lobbyTitle->setPosition((SCREEN_WIDTH - lobbyTitle->getWidth()) / 2, 50); // Teams labels Label* blueTeamLabel = new Label("Blue team", 70, 150, 200, commonData); blueTeamLabel->setColor(sf::Color::Blue); Label* redTeamLabel = new Label("Red team", 70, commonData); redTeamLabel->setPosition(SCREEN_WIDTH - redTeamLabel->getWidth() - 150, 200); redTeamLabel->setColor(sf::Color::Red); // Players labels Label** playerLabel = new Label*[4]; for (int i = 0; i < 4; i++) { playerLabel[i] = new Label("", 60, 180, 300 + (i/2)*100, commonData); if (i % 2 == 1) { playerLabel[i]->setPosition(SCREEN_WIDTH - playerLabel[i]->getWidth() - 180, 300 + (i/2)*100); } } // Countdown label Label* countdownLabel = new Label("The game will start in 15 seconds...", 40, commonData); countdownLabel->setPosition(SCREEN_WIDTH - countdownLabel->getWidth() - 30, 600); // Countdown sf::Clock clock; sf::Time fiveteenSeconds = sf::seconds(15.0f); int amountOfPlayers = 0; // Main loop while (window.isOpen()) { // Position of mouse sf::Vector2i position = sf::Mouse::getPosition(window); // Process events sf::Event event; while (window.pollEvent(event)) { // Close window: exit if (event.type == sf::Event::Closed) { window.close(); } // Escape pressed: exit if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { window.close(); } } // Show players name on labels for (int i = 0; i < commonData->map->playersSize(); i++) { Player* player = commonData->map->getPlayerAtIndex(i); playerLabel[player->getID()]->setString(player->getName()); } // Prepare countdown information if ((amountOfPlayers != commonData->map->playersSize()) && (commonData->map->playersSize() == 2 || commonData->map->playersSize() == 4)) { clock.restart(); amountOfPlayers = commonData->map->playersSize(); } // Clear screen window.clear(sf::Color::Black); // Draw window.draw(background); lobbyTitle->draw(window); blueTeamLabel->draw(window); redTeamLabel->draw(window); for (int i = 0; i < 4; i++) { if (i % 2 == 1) { playerLabel[i]->setPosition(SCREEN_WIDTH - playerLabel[i]->getWidth() - 180, 300 + (i/2)*100); } playerLabel[i]->draw(window); } // Show information about starting game only when there are 2 or 4 players if (commonData->map->playersSize() == 2 || commonData->map->playersSize() == 4) { int timeToStart = (int)ceil(fiveteenSeconds.asSeconds() - clock.getElapsedTime().asSeconds()); if (timeToStart <= 3) { timeToStart = 3; } countdownLabel->setString("The game will start in " + Converter::int2string(timeToStart) + " seconds..."); countdownLabel->setPosition(SCREEN_WIDTH - countdownLabel->getWidth() - 30, 600); countdownLabel->draw(window); } // Update the window window.display(); // Go to the game if countdown will finish if ((amountOfPlayers == 2 || amountOfPlayers == 4) && clock.getElapsedTime().asSeconds() > fiveteenSeconds.asSeconds() - 3.0f && commonData->gameStarted == true) { return GAME; } } // Change screen return EXIT; }
void nasic::options::show(sf::RenderWindow& window) { using nasic::options; ///////////////////////////////////////////////////// //***************IMPORTANT NOTE********************* //we're getting the video mode and creating a scale //variable for the drawables using 800 as the base //800*600 will be the smallest screen supported //*****KEEPING IN MIND**** //we're blowing up small images... //this is not ideal for non-retro-looking sprites sf::VideoMode mode = sf::VideoMode::getDesktopMode(); float scale = mode.width/800.f; window.setKeyRepeatEnabled(false); window.setFramerateLimit(60);//set the refresh limit to the current frame rate 60fps //bail if the options are not in uninitialized state if(!m_optionstate == optionstate::s_uninitialized) return; //play the transition sound... m_transition.play(); //create info stuff sf::Color bg = sf::Color(255,150,0,200); sf::Color none = sf::Color(0,0,0,0); sf::Color darkred = sf::Color(100,0,0,255); sf::Vector2f volpos = sf::Vector2f(window.getSize().x/2.f,window.getSize().y/4.f); sf::Vector2f effpos = sf::Vector2f(window.getSize().x/2.f,window.getSize().y/2.f); sf::Vector2f diffpos = sf::Vector2f(window.getSize().x/2.f,window.getSize().y/1.25f); gui::optionbox vol("Volume", volpos, 20, window); gui::optionbox eff("Effects Volume", effpos, 20, window); gui::optionbox dif("Difficulty", diffpos, 3, window); sf::Uint32 focus = 0; sf::Font myfont; if(!myfont.loadFromFile("fonts/contb.ttf")) { std::cerr<<"Could not load contb.ttf"<<std::endl; } sf::Text title("Options", myfont, 48); title.setColor(darkred); title.setPosition(window.getSize().x * 0.01f, window.getSize().y * 0.01f); sf::Text volLabel(" ", myfont, 48); volLabel.setOrigin(volLabel.getGlobalBounds().width/2.f,0.f); volLabel.setPosition(window.getSize().x/2.f, window.getSize().y/4.f); sf::Text effLabel(" ", myfont, 48); effLabel.setOrigin(effLabel.getGlobalBounds().width/2.f,0.f); effLabel.setPosition(window.getSize().x/2.f, window.getSize().y/2.f); sf::Text difLabel(" ", myfont, 48); difLabel.setOrigin(difLabel.getGlobalBounds().width/2.f,0.f); difLabel.setPosition(window.getSize().x/2.f, window.getSize().y/1.25f); sf::ConvexShape bgBox = thor::Shapes::roundedRect(sf::Vector2f(window.getSize().x, window.getSize().y), 0.f, sf::Color(bg), 0.f, sf::Color(none)); bgBox.setPosition(0.f,0.f); nasic::starfield stars(window,nasic::starfield::starStyle::smallStars, scale); nasic::hexgrid hex(window, nasic::hexgrid::hexStyle::translucent, scale); m_optionstate = optionstate::s_settingoptions; //time stuff... sf::Clock tickClock; sf::Time timeSinceLastUpdate = sf::Time::Zero; sf::Time TimePerFrame = sf::seconds(1.f/60.f); vol.setVal(m_initialVol); eff.setVal(m_initialEff); dif.setVal(m_initialDif); //initialize focus to volume controls vol.setFocus(true); eff.setFocus(false); dif.setFocus(false); sf::SoundBuffer menubuff; if(!menubuff.loadFromFile("sound/select.wav")) { std::cerr<<"Could not load select.wav."<<std::endl; } sf::Sound menusound; menusound.setBuffer(menubuff); menusound.setVolume(m_initialEff*5.f); sf::Music menumusic; if(!menumusic.openFromFile("sound/theme.ogg")) { std::cout<<"Could not open stream for theme.ogg"<<std::endl; } menumusic.setVolume(m_initialVol*5.f); menumusic.setLoop(true); menumusic.play(); bool running = true; sf::Event e; while(running) { while(window.pollEvent(e)) { if(e.type == sf::Event::Closed) { m_options.saveOptions(m_options,m_filename.c_str()); m_optionstate = optionstate::s_done; return; } if(e.type == sf::Event::KeyPressed) { switch(e.key.code) { case sf::Keyboard::Escape: { m_options.saveOptions(m_options,m_filename.c_str()); m_optionstate = optionstate::s_done; return; } break; case sf::Keyboard::Up: { if(focus > 0) { focus--; menusound.play(); } } break; case sf::Keyboard::Down: { if(focus < 2) { focus++; menusound.play(); } } break; case sf::Keyboard::Left: { menusound.play(); } break; case sf::Keyboard::Right: { menusound.play(); } break; case sf::Keyboard::Tab: { menusound.play(); if(focus >= 2) focus = 0; else focus++; } default: break; } } vol.update(e, window); eff.update(e, window); dif.update(e, window); } //handle game ticks and return a fixed dt //for updates timeSinceLastUpdate += tickClock.restart(); while (timeSinceLastUpdate > TimePerFrame) { timeSinceLastUpdate -= TimePerFrame; stars.update(window, TimePerFrame); } m_vol = vol.getVal() * 5.f; menumusic.setVolume(m_vol); m_options.m_volume = m_vol; switch(focus) { case 0://volume is on focus { vol.setFocus(true); eff.setFocus(false); dif.setFocus(false); } break; case 1://effects is on focus { vol.setFocus(false); eff.setFocus(true); dif.setFocus(false); } break; case 2://difficulty is on focus { vol.setFocus(false); eff.setFocus(false); dif.setFocus(true); } break; default: break; } if(eff.getDownClicks() == 1) menusound.play(); if(eff.getUpClicks() == 1) menusound.play(); m_eff = eff.getVal() * 5.f; menusound.setVolume(m_eff); m_options.m_effects = m_eff; m_options.m_difficulty = dif.getVal(); //update labels switch(vol.getVal()) { case 0: volLabel.setString("Off"); break; default: volLabel.setString(toString(vol.getVal())); break; } switch(eff.getVal()) { case 0: effLabel.setString(toString(eff.getVal())); break; default: effLabel.setString(toString(eff.getVal())); break; } switch(dif.getVal()) { case 0: { difLabel.setColor(sf::Color(255,100,100,255)); difLabel.setString("Infantile"); } break; case 1: { difLabel.setColor(sf::Color(200,0,200,255)); difLabel.setString("Easy as Pie"); } break; case 2: { difLabel.setColor(sf::Color(0,200,0,255)); difLabel.setString("Normal"); } break; case 3: { difLabel.setColor(sf::Color(200,0,0,255)); difLabel.setString("Very Hard"); } break; default: break; } volLabel.setOrigin(volLabel.getGlobalBounds().width/2.f,0.f); effLabel.setOrigin(effLabel.getGlobalBounds().width/2.f,0.f); difLabel.setOrigin(difLabel.getGlobalBounds().width/2.f,0.f); window.clear(); window.draw(stars); window.draw(bgBox); window.draw(hex); window.draw(vol); window.draw(eff); window.draw(dif); window.draw(title); window.draw(volLabel); window.draw(effLabel); window.draw(difLabel); window.display(); } std::cout<<m_options.m_volume<<"\n"<<m_options.m_effects<<"\n"<<m_options.m_difficulty<<std::endl; m_options.saveOptions(m_options,m_filename.c_str()); return; }
void draw(sf::RenderWindow& mTarget) { mTarget.draw(shape); }
void FPS::draw(sf::RenderWindow &window) { window.draw(fpsText); }
int screen_1::Run(sf::RenderWindow &App) { sf::Event Event; bool Running = true; while (Running) { //Verifying events while (App.pollEvent(Event)) { // Window closed if (Event.type == sf::Event::Closed) { return (-1); } //Key pressed if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { sf::Vector2f pos = frogger.getPosition(); if (pos.x <= 15 || (pos.x <= 15 && pos.y <= 675)) { frogger.move(0, 0); }// end if else { if (rectSourceSprite.left != 216) { rectSourceSprite.left = 216; rectSourceSprite.width = 55; frogger.setTextureRect(rectSourceSprite); }// end if frogger.move(-50, 0); }// end else }// end if if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { sf::Vector2f pos = frogger.getPosition(); if (pos.x >= 690) { frogger.move(0, 0); }// end if else { if (rectSourceSprite.left != 89) { rectSourceSprite.left = 89; rectSourceSprite.width = 60; frogger.setTextureRect(rectSourceSprite); }// end if frogger.move(50, 0); }// end else }// end if if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { sf::Vector2f pos = frogger.getPosition(); if (pos.y <= -35) { frogger.move(0, 0); }// end if else { if (rectSourceSprite.left != 0) { rectSourceSprite.left = 0; rectSourceSprite.width = 89; frogger.setTextureRect(rectSourceSprite); }// end if frogger.move(0, -50); } }// end if if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { sf::Vector2f pos = frogger.getPosition(); if (pos.y >= 540) { frogger.move(0, 0); }// end if else { if (rectSourceSprite.left != 149) { rectSourceSprite.left = 149; rectSourceSprite.width = 67; frogger.setTextureRect(rectSourceSprite); }// end if frogger.move(0, 50); }// end else }// end if } // Creating the objects Object t1(130, 420, 0.5); Object t2(550, 290, 0.3); Object c1(-50, 420, 0.5); Object c2(280, 289, 0.3); Object c3(0, 289, 0.3); Object sl1(0, 125, 0.2); Object sl2(200, 61, 0.3); Object sl3(300, 8, 0.4); Object l1(799, 8.3, 0.4); Object l2(500, 125, 0.2); t1.moveRight(truck); t2.moveLeft(truck2); c1.moveRight(car); c2.moveLeft(car2); c3.moveLeft(car3); sl1.moveRight(shortLog); sl2.moveLeft(shortLog2); sl3.moveRight(shortLog3); l1.moveRight(longLog); l2.moveRight(longLog2); //Clearing screen App.clear(sf::Color(0, 0, 0, 0)); //Drawing App.draw(background); App.draw(truck); App.draw(truck2); App.draw(car); App.draw(car2); App.draw(car3); App.draw(longLog); App.draw(longLog2); App.draw(shortLog); App.draw(shortLog2); App.draw(shortLog3); App.draw(lillypad); App.draw(lillypad2); App.draw(lillypad3); App.draw(lillypad4); App.draw(lillypad5); App.draw(frogger); App.display(); } //Never reaching this point normally, but just in case, exit the application return -1; }
void GameOver::draw(sf::RenderWindow& app) { app.draw(_sprite); }
void InterfaceGrenade::wyswietl(sf::RenderWindow &okno) { okno.draw(sprajt); }
void rendering::render_room(const Room* room,sf::RenderWindow& screen, const std::pair<unsigned int, unsigned int>& pos, const std::pair<unsigned int, unsigned int>& size, const GameInfo& stats) { screen.draw(*room); render_time(screen,stats); }
void NpcCls::Render(sf::RenderWindow &aWindow) { aWindow.draw(m_currentAnimation.getSprite()); }
void rendering::render_characters(const std::vector<std::shared_ptr<ICharacter>>& c, sf::RenderWindow& w) { for(const auto& e : c) w.draw(*e); }
void Shield::draw(sf::RenderWindow &window) { if(isVisible==true) window.draw(shieldSpr); }
void rendering::render_map(const Maze& maze, sf::RenderWindow& screen, const std::pair<unsigned int, unsigned int>& pos, const std::pair<unsigned int, unsigned int>& size) { /* First let's figure out the layout of the map ! TODO : This must be done only once for each map, so we have to calculate this when we load a level, not when we render the map */ Room* seed = maze.getSeedRoom(); std::vector<Room*> vec; std::vector<std::pair<int, int>> positions; std::vector<std::pair<unsigned int, unsigned int>> coords; positions.push_back(std::make_pair(0,0)); coords.push_back(std::make_pair(pos.first + size.first/2, pos.second + size.second / 2)); unsigned int cpt = 0; vec.push_back(seed); while(cpt < vec.size()) { Room* piece = vec[cpt]; if(piece == nullptr) { infos::log(RENDERING_PATH,"A room is null in render_map, we will not render the rest of the map"); return; } if(piece->getNeighboor(NORTH) != nullptr) { if (std::find(positions.begin(),positions.end(),std::make_pair(positions[cpt].first,positions[cpt].second - 1)) == positions.end()) { positions.push_back(std::make_pair(positions[cpt].first,positions[cpt].second - 1)); vec.push_back(piece->getNeighboor(NORTH)); } } if (piece->getNeighboor(SOUTH) != nullptr) { if(std::find(positions.begin(),positions.end(),std::make_pair(positions[cpt].first,positions[cpt].second + 1)) == positions.end()) { positions.push_back(std::make_pair(positions[cpt].first,positions[cpt].second + 1)); vec.push_back(piece->getNeighboor(SOUTH)); } } if (piece->getNeighboor(WEST) != nullptr) { if(std::find(positions.begin(),positions.end(),std::make_pair(positions[cpt].first - 1,positions[cpt].second)) == positions.end()) { positions.push_back(std::make_pair(positions[cpt].first - 1,positions[cpt].second)); vec.push_back(piece->getNeighboor(WEST)); } } if (piece->getNeighboor(EAST) != nullptr) { if(std::find(positions.begin(),positions.end(),std::make_pair(positions[cpt].first + 1,positions[cpt].second)) == positions.end()) { positions.push_back(std::make_pair(positions[cpt].first + 1,positions[cpt].second)); vec.push_back(piece->getNeighboor(EAST)); } } ++cpt; } /* Now that we have the layout, let's figure out the size of each element in the map */ const int minf = std::min_element(positions.begin(),positions.end(),rendering::firstComp)->first; //Minimum for the width const int mins = std::min_element(positions.begin(),positions.end(),rendering::secondComp)->second; //Minimum for the height const int maxf = std::max_element(positions.begin(),positions.end(),rendering::firstComp)->first; const int maxs = std::max_element(positions.begin(),positions.end(),rendering::secondComp)->second; const int number_room_w = maxf - minf + 1; const int number_room_h = maxs - mins + 1; const int width_for_rooms = (static_cast<float>(size.first) / ::quad) * ::quad_for_rooms; // Takes quad_for_rooms/quad % of the full size const int height_for_rooms = (static_cast<float>(size.second) / ::quad) * ::quad_for_rooms; const int width_for_blanks = (static_cast<float>(size.first) / ::quad) * ::quad_for_blanks; const int height_for_blanks = (static_cast<float>(size.second) / ::quad) * ::quad_for_blanks; const float room_height = height_for_rooms / number_room_h; const float room_width = width_for_rooms / number_room_w; const float blank_height = height_for_blanks / (number_room_h + 1); const float blank_width = width_for_blanks / (number_room_w + 1); const int line_size_h = blank_height * ::corridors_size; const int line_size_w = blank_width * ::corridors_size; const int line_size = std::max(line_size_h,line_size_w); cpt = 0; /* Then, let's do the actual rendering */ /* For Debugging purpose, let's log those infos, to see what's messing with the rendering */ for(auto p : positions) { Room* piece = vec[cpt]; auto in = maze.getCurrentRoom(); sf::RectangleShape rec; if(piece == in) rec.setFillColor(KiroGame::transparent); const unsigned int rank_w = abs(minf - p.first); const unsigned int rank_h = abs(mins - p.second); const float x = pos.first + rank_w * room_width + (rank_w + 1) * blank_width; const float y = pos.second + rank_h * room_height + (rank_h + 1) * blank_height; rec.setPosition(x,y); rec.setSize(sf::Vector2f(room_width,room_height)); screen.draw(rec); sf::RectangleShape line; // For corridors between rooms if(piece == nullptr) { infos::log(RENDERING_PATH,"A room is null in render_map, we will not render the rest of the map"); return; } float x_line, y_line; if(piece->getNeighboor(NORTH) != nullptr) { //If north, the size is the width //the (x,y) are located on the square above. x_line = x + (room_width/2) - (line_size / 2); y_line = y - blank_height; line.setPosition(x_line,y_line); line.setSize(sf::Vector2f(line_size,blank_height)); screen.draw(line); } if(piece->getNeighboor(SOUTH) != nullptr) { x_line = x + (room_width/2) - (line_size / 2); y_line = y + room_height; line.setPosition(x_line,y_line); line.setSize(sf::Vector2f(line_size,blank_height)); screen.draw(line); } if(piece->getNeighboor(EAST) != nullptr) { x_line = x + room_width; y_line = y + room_height/2 - line_size/2; line.setPosition(x_line,y_line); line.setSize(sf::Vector2f(blank_width,line_size)); screen.draw(line); } if(piece->getNeighboor(WEST) != nullptr) { x_line = x - blank_width; y_line = y + room_height/2 - line_size/2; line.setPosition(x_line,y_line); line.setSize(sf::Vector2f(blank_width,line_size)); screen.draw(line); } ++cpt; } //screen.display(); }
double Arena::runSimulation(Maze& maze, Robot& r, sf::RenderWindow& window) { sf::Font f; if (!f.loadFromFile("fonts/Oswald-Regular.ttf")) return 0; const int ROWS = maze.getRows(); const int COLS = maze.getCols(); const int CELL_SIZE = 30, OFFSET = 150; sf::RectangleShape rectangles[10][10]; vector<sf::RectangleShape> lines; //text for display of info sf::Text bst; sf::Text med; sf::Text gen; //set fonts bst.setFont(f); med.setFont(f); gen.setFont(f); bst.setColor(sf::Color::Black); med.setColor(sf::Color::Black); gen.setColor(sf::Color::Black); //set sizes bst.setCharacterSize(24); med.setCharacterSize(24); gen.setCharacterSize(24); //set positions gen.setPosition(10, 10); bst.setPosition(10, 40); med.setPosition(10, 70); //set strings stringstream stream; stream.str(""); string out; stream << generation; stream >> out; out = "Generation: " + out; gen.setString(out); stream.str(string()); stream.clear(); out.clear(); stream << setprecision(2) << median; stream >> out; out = "Median Score: " + out; med.setString(out); stream.str(string()); stream.clear(); out.clear(); stream << setprecision(2) << best; stream >> out; out = "Best Score: " + out; bst.setString(out); //Cell used to find borders for the board spaces Cell* c; //populate rectangles as board spaces for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { //add board spaces, set color and position rectangles[i][j] = sf::RectangleShape(sf::Vector2f(CELL_SIZE, CELL_SIZE)); rectangles[i][j].setFillColor(sf::Color::White); rectangles[i][j].setPosition((j * CELL_SIZE) + OFFSET, (i * CELL_SIZE) + OFFSET); //set cell to find borders and highlight end cell c = maze.getCell(i, j); if (c == maze.getEndCell()) rectangles[i][j].setFillColor(sf::Color::Blue); if (c->hasWall(direction::NORTH) || c->hasEdge(direction::NORTH)) { lines.push_back(sf::RectangleShape(sf::Vector2f(CELL_SIZE, 2))); lines[lines.size() - 1].setPosition(rectangles[i][j].getPosition()); lines[lines.size() - 1].setFillColor(sf::Color::Black); } if (c->hasWall(direction::WEST) || c->hasEdge(direction::WEST)) { lines.push_back(sf::RectangleShape(sf::Vector2f(2, CELL_SIZE))); lines[lines.size() - 1].setPosition(rectangles[i][j].getPosition()); lines[lines.size() - 1].setFillColor(sf::Color::Black); } if (c->hasWall(direction::SOUTH) || c->hasEdge(direction::SOUTH)) { lines.push_back(sf::RectangleShape(sf::Vector2f(CELL_SIZE, 2))); lines[lines.size() - 1].setPosition(rectangles[i][j].getPosition() + sf::Vector2f(0, CELL_SIZE)); lines[lines.size() - 1].setFillColor(sf::Color::Black); } if (c->hasWall(direction::EAST) || c->hasEdge(direction::EAST)) { lines.push_back(sf::RectangleShape(sf::Vector2f(2, CELL_SIZE))); lines[lines.size() - 1].setPosition(rectangles[i][j].getPosition() + sf::Vector2f(CELL_SIZE, 0)); lines[lines.size() - 1].setFillColor(sf::Color::Black); } } } //reset maze maze.clearVisited(); maze.clearValues(); //set needed values after reset Cell* curCell = maze.getStartCell(); robotOrientation = direction::SOUTH; unsigned int move; double score; //clock for delays sf::Clock clock; sf::Time delay = sf::milliseconds(50); //DRAW WINDOW INITIALLY WITH START CELL HIGHLIGHTED AS CURRENT window.clear(sf::Color::White); //highlight start cell rectangles[curCell->getRow()][curCell->getCol()].setFillColor(sf::Color::Green); //add cells for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { window.draw(rectangles[i][j]); } } //add borders for (unsigned int i = 0; i < lines.size(); i++) { window.draw(lines[i]); } //add information window.draw(gen); window.draw(bst); window.draw(med); window.display(); //while the robot is not in the same cell facing the same direction while (!repeat(robotOrientation, curCell->getValue()) && !(curCell == maze.getEndCell())) { //set current cell to visited and update it's value curCell->setVisited(); curCell->setValue(curCell->getValue() + robotOrientation); //send the robot the environment and get it's next move move = r.getMove(getEnv(robotOrientation, curCell)); //perform next move //find rotation if (move == 3 || move == 7) { robotOrientation = Direction::left(robotOrientation); } else if (move == 2 || move == 6) { robotOrientation = Direction::opposite(robotOrientation); } else if (move == 1 || move == 5) { robotOrientation = Direction::right(robotOrientation); } else { //no rotation } //reset clock and hold for display clock.restart(); while (clock.getElapsedTime() < delay) {} //HIGHLIGHT CURRENT CELL AS VISITED rectangles[curCell->getRow()][curCell->getCol()].setFillColor(sf::Color::Red); //move forwards if (!curCell->hasWall(robotOrientation) && !curCell->hasEdge(robotOrientation)) { curCell = maze.getCell(curCell->getRow() + Direction::row(robotOrientation), curCell->getCol() + Direction::col(robotOrientation)); } //REDRAW WINDOW WITH UPDATED CELLS window.clear(sf::Color::White); //highlight current visiting cell rectangles[curCell->getRow()][curCell->getCol()].setFillColor(sf::Color::Green); //add cells for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { window.draw(rectangles[i][j]); } } //add borders for (unsigned int i = 0; i < lines.size(); i++) { window.draw(lines[i]); } sf::Event event; while (window.pollEvent(event)) { // "close requested" event: we close the window if (event.type == sf::Event::Closed) return -1; } //add information window.draw(gen); window.draw(bst); window.draw(med); window.display(); } //calculate score //score is a 1 if the end has been reached, else it is 1 - (distance from end * 0.01) if (curCell == maze.getEndCell()) { score = 1.0; } else { score = (double)getNumberOfVisitedCells(maze) / (double)((double)maze.getRows() * (double)maze.getCols()); } //reset clock and hold for display clock.restart(); while (clock.getElapsedTime() < sf::milliseconds(1000)) {} //return score return score; }
virtual void draw (sf::RenderWindow& w) const { w.draw(vertex_lista); }
void EmotivShooterScreen::Draw(sf::RenderWindow &Window, sf::Clock clock) { Background.setTexture(&bgTex); Window.draw(Background); if(boss.GetActive() == false) { for(int e =0; e < enemy.size(); e++) { Window.draw(enemy[e]); } } for(int b =0; b < bullet.size(); b++) { Window.draw(bullet[b]); } if(timer.asSeconds() >= boss.GetSpawnTime()) { Window.draw(boss); } if(boss.GetAttack() == true) { for(int f = 0; f < enemyFire.size(); f++) { Window.draw(enemyFire[f]); } } Window.draw(player); /////////////////////////////////////////////////////////////////// // text // std::ostringstream gs; gs << "Score: " << score << endl; /*<< "Time: " << timer.asSeconds() << endl << "Frustration: " << frustrationScore << endl << "Excitement: " << excitementScore << endl << "Boredom: " << boredomScore << endl << "meditation: " << meditationScore << endl; */ text.setString(gs.str()); text.setPosition(0,20); Window.draw(text); if(boss.GetActive() == true) { std::ostringstream bs; bs << "Master Controller: " << boss.GetHealth() << endl; text.setString(bs.str()); text.setPosition(sf::VideoMode::getDesktopMode().width / 2, 20); globalVariables.SetBossSpawned(true); } if(paused == true) { MsgBox.setSize(sf::Vector2f(610,150)); MsgBox.setPosition((sf::VideoMode::getDesktopMode().width / 3), (sf::VideoMode::getDesktopMode().height / 3)); YesBtn.setSize(sf::Vector2f(50, 50)); YesBtn.setPosition((sf::VideoMode::getDesktopMode().width / 3) + 150, (sf::VideoMode::getDesktopMode().height / 3) + 100); YesBtn.setFillColor(sf::Color::Blue); NoBtn.setSize(sf::Vector2f(50, 50)); NoBtn.setPosition((sf::VideoMode::getDesktopMode().width / 3) + 400, (sf::VideoMode::getDesktopMode().height / 3) + 100); NoBtn.setFillColor(sf::Color::Blue); Window.draw(MsgBox); std::ostringstream pm; pm << "PAUSED " << endl <<"Would you like to return to the Main Menu?" << endl; text.setString(pm.str()); text.setCharacterSize(24); text.setColor(sf::Color::Green); text.setPosition((sf::VideoMode::getDesktopMode().width / 3), (sf::VideoMode::getDesktopMode().height / 3)); Window.draw(text); Window.draw(YesBtn); std::ostringstream yb; yb << "Yes" << endl; text.setString(yb.str()); text.setCharacterSize(24); text.setColor(sf::Color::Green); text.setPosition((sf::VideoMode::getDesktopMode().width / 3) + 150, (sf::VideoMode::getDesktopMode().height / 3) + 100); Window.draw(text); //sf::FloatRect ybBB = YesBtn.getGlobalBounds(); Window.draw(NoBtn); std::ostringstream nb; nb << "No" << endl; text.setString(nb.str()); text.setCharacterSize(24); text.setPosition((sf::VideoMode::getDesktopMode().width / 3) + 400, (sf::VideoMode::getDesktopMode().height / 3) + 100); text.setColor(sf::Color::Green); Window.draw(text); //sf::FloatRect nbBB = NoBtn.getGlobalBounds(); } if(victory == true) { EndBtn.setSize(sf::Vector2f(560,200)); EndBtn.setPosition((sf::VideoMode::getDesktopMode().width / 3), (sf::VideoMode::getDesktopMode().height / 3)); Window.draw(EndBtn); std::ostringstream vs; vs << "CONGRATULATIONS!! " << endl << " Your Final Score is: " << score << endl <<"Click here to return to the Main Menu?" << endl; text.setString(vs.str()); text.setCharacterSize(24); text.setColor(sf::Color::Green); text.setPosition((sf::VideoMode::getDesktopMode().width / 3) + 5, (sf::VideoMode::getDesktopMode().height / 3) + 10); Window.draw(text); //sf::FloatRect vsBB = EndBtn.getGlobalBounds(); } Window.draw(text); }
void Simple2DScene::render(sf::RenderWindow& window) { window.draw(this->_obj); }