From: malak585 Date: Mon, 27 Nov 2023 13:44:46 +0000 (+0100) Subject: worked on scoreboard. - Alma och malin X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=104ff0b34a1f8af3d399f24b5ab9e0c35fd44ff0;p=TDDC76_proj.git worked on scoreboard. - Alma och malin --- diff --git a/assets/scoreboard.png b/assets/scoreboard.png new file mode 100644 index 0000000..bdaa06a Binary files /dev/null and b/assets/scoreboard.png differ diff --git a/src/Menus.cc b/src/Menus.cc index 53accbe..6fc0b5b 100644 --- a/src/Menus.cc +++ b/src/Menus.cc @@ -334,21 +334,19 @@ void Pause_menu::handle_input(sf::Event& event) // Scoreboard menu -------------------------------------------- -Scoreboard_menu::Scoreboard_menu() : /*texture{},*/ texture2{}, /*sprite{},*/ menu{false}, exit_game{false}, - startmenutext{}, quittext{}, mouse_r{}, mouse_l{}, font{}, menu_index{1} +Scoreboard_menu::Scoreboard_menu() : texture{}, texture2{}, sprite{}, menu{false}, exit_game{false}, + scoreboardtext{}, firstplacetext{}, startmenutext{}, quittext{}, mouse_r{}, mouse_l{}, font{}, menu_index{1} { - // Add background later - /* - texture.loadFromFile("assets/Pause_bild.png"); + texture.loadFromFile("assets/scoreboard.png"); sprite.setTexture(texture);; sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF); sf::FloatRect gb {sprite.getGlobalBounds()}; sprite.setPosition(0, 0); - */ + // mouse - texture2.loadFromFile("assets/muspekareGul.png"); + texture2.loadFromFile("assets/muspekare2.png"); mouse_l.setTexture(texture2); mouse_l.setScale(0.1, 0.1); @@ -364,17 +362,33 @@ Scoreboard_menu::Scoreboard_menu() : /*texture{},*/ texture2{}, /*sprite{},*/ me throw std::invalid_argument ("Unable to load font"); + // Scoreboard text + scoreboardtext = sf::Text{ "Scoreboard:", font, 39 }; + sf::FloatRect gbs {scoreboardtext.getGlobalBounds()}; + scoreboardtext.setOrigin(gbs.width / 2, gbs.height / 2); + scoreboardtext.setPosition (S_WIDTH / 2 - 15, ((S_HEIGHT / 2) - 120)); + scoreboardtext.setFillColor(sf::Color::Red); + + // ----------------------------------------------------------------------- + // First place text + firstplacetext = sf::Text{ "1. NAME 100p\n 2. NAME 39p" , font, 18 }; + sf::FloatRect gbfp {firstplacetext.getGlobalBounds()}; + firstplacetext.setOrigin(gbfp.width / 2, gbfp.height / 2); + firstplacetext.setPosition (S_WIDTH / 2 - 15, ((S_HEIGHT / 2) - 70)); + firstplacetext.setFillColor(sf::Color::Red); + // ----------------------------------------------------------------------- + // Start menu text startmenutext = sf::Text{ "Start menu", font, 24 }; sf::FloatRect gbr {startmenutext.getGlobalBounds()}; startmenutext.setOrigin(gbr.width / 2, gbr.height / 2); - startmenutext.setPosition (S_WIDTH / 2, ((S_HEIGHT / 2) - 30)); + startmenutext.setPosition (S_WIDTH / 2 - 15, ((S_HEIGHT / 2) + 80)); // Quit text quittext = sf::Text{ "Quit", font, 24 }; - sf::FloatRect gbs {quittext.getGlobalBounds()}; - quittext.setOrigin(gbs.width / 2, gbs.height / 2); - quittext.setPosition (S_WIDTH / 2, ((S_HEIGHT / 2) + 20)); + sf::FloatRect gbq {quittext.getGlobalBounds()}; + quittext.setOrigin(gbq.width / 2, gbq.height / 2); + quittext.setPosition (S_WIDTH / 2 - 15, ((S_HEIGHT / 2) + 130)); } @@ -388,27 +402,29 @@ void Scoreboard_menu::update(Context& context) // changes color on text depending on selection if( menu_index == 1) { - startmenutext.setFillColor(sf::Color::Yellow); - quittext.setFillColor(sf::Color::Black); + startmenutext.setFillColor(sf::Color::Black); + quittext.setFillColor(sf::Color::Red); } else if( menu_index == 2) { - startmenutext.setFillColor(sf::Color::Black); - quittext.setFillColor(sf::Color::Yellow); + startmenutext.setFillColor(sf::Color::Red); + quittext.setFillColor(sf::Color::Black); } // mouse placement - mouse_r.setPosition(((S_WIDTH / 2) + 60), ((S_HEIGHT / 2) - 45 + 50*(menu_index - 1))); - mouse_l.setPosition(((S_WIDTH / 2) - 58), ((S_HEIGHT / 2) + 2 + 50*(menu_index - 1))); + mouse_r.setPosition(((S_WIDTH / 2) + 45), ((S_HEIGHT / 2) + 65 + 50*(menu_index - 1))); + mouse_l.setPosition(((S_WIDTH / 2) - 73), ((S_HEIGHT / 2) + 112 + 50*(menu_index - 1))); } void Scoreboard_menu::render(sf::RenderWindow& window) const { - /*window.draw(sprite);*/ + window.draw(sprite); window.draw(mouse_l); window.draw(mouse_r); + window.draw(scoreboardtext); + window.draw(firstplacetext); window.draw(startmenutext); window.draw(quittext); diff --git a/src/States.h b/src/States.h index 2b07839..c8ab49f 100644 --- a/src/States.h +++ b/src/States.h @@ -98,11 +98,13 @@ public: void render(sf::RenderWindow& window) const override; void handle_input(sf::Event& event) override; private: - /*sf::Texture texture;*/ + sf::Texture texture; sf::Texture texture2; - /*sf::Sprite sprite;*/ + sf::Sprite sprite; sf::Sprite mouse_l; sf::Sprite mouse_r; + sf::Text scoreboardtext; + sf::Text firstplacetext; sf::Text startmenutext; sf::Text quittext; sf::Font font;