From: malak585 Date: Thu, 30 Nov 2023 13:59:15 +0000 (+0100) Subject: worked on gameover menu - Alma, Kukas, Malin X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=2f63183395554e65038f4acb4b975174694bc84e;p=TDDC76_proj.git worked on gameover menu - Alma, Kukas, Malin --- diff --git a/assets/data.json b/assets/data.json index 05c4965..679dcef 100644 --- a/assets/data.json +++ b/assets/data.json @@ -29,7 +29,7 @@ "game_constants": { "bottles_per_second" : 2, - "game_time" : 20, + "game_time" : 2, "yf_per_second": 0.125, "bikes_per_second": 0.17, "scoreboard" : 5 diff --git a/assets/muspekareRed.png b/assets/muspekareRed.png new file mode 100644 index 0000000..f74d78e Binary files /dev/null and b/assets/muspekareRed.png differ diff --git a/src/Menus.cc b/src/Menus.cc index 1c0738b..8e76914 100644 --- a/src/Menus.cc +++ b/src/Menus.cc @@ -505,7 +505,7 @@ void Scoreboard_menu::handle_input(sf::Event& event) // GameOver menu -------------------------------------------- -GameOver_menu::GameOver_menu(int const points, json& params) : texture{}, texture2{}, sprite{}, rectangle{}, mouse_l{}, mouse_r{}, pointstext{}, +GameOver_menu::GameOver_menu(int const points, json& params) : texture{}, texture2{}, sprite{}, rectangle{}, mouse_l{}, mouse_r{}, linetext{}, entertext{}, pointstext{}, playerInput{}, data{}, playerText{}, savetext{}, quittext{}, font{}, exit_game{false}, menu{false}, menu_index{1}, points{points} { texture.loadFromFile("assets/game_over.png"); @@ -522,9 +522,9 @@ GameOver_menu::GameOver_menu(int const points, json& params) : texture{}, textur // transparent box rectangle = sf::CircleShape{200}; - rectangle.setFillColor(sf::Color(255, 255, 0, 128)); + rectangle.setFillColor(sf::Color(255, 255, 0, 180)); rectangle.setOutlineThickness(7); - rectangle.setOutlineColor(sf::Color( 0, 0, 0, 200)); + rectangle.setOutlineColor(sf::Color( 0, 0, 0, 128)); sf::FloatRect gbrs {rectangle.getGlobalBounds()}; rectangle.setOrigin(gbrs.width / 2, gbrs.height / 2); rectangle.setPosition (S_WIDTH / 2, ((S_HEIGHT / 2))); @@ -534,11 +534,19 @@ GameOver_menu::GameOver_menu(int const points, json& params) : texture{}, textur pointstext = sf::Text{ "Your points: " + std::to_string(points), font, 30 }; sf::FloatRect gbp {pointstext.getGlobalBounds()}; pointstext.setOrigin(gbp.width / 2, gbp.height / 2); - pointstext.setPosition (S_WIDTH / 2 - 70, ((S_HEIGHT / 2) - 150)); + pointstext.setPosition (S_WIDTH / 2 , ((S_HEIGHT / 2) - 100)); pointstext.setFillColor(sf::Color::Black); - //player text input + // Enter text + entertext = sf::Text{ "Enter your name:", font, 24 }; + sf::FloatRect gbe {entertext.getGlobalBounds()}; + entertext.setOrigin(gbe.width / 2, gbe.height / 2); + entertext.setPosition (S_WIDTH / 2 , ((S_HEIGHT / 2) - 30)); + entertext.setFillColor(sf::Color::Black); + + + // Player text input playerText.setFont( font ); playerText.setCharacterSize( 24 ); sf::FloatRect gbpt {playerText.getGlobalBounds()}; @@ -547,8 +555,16 @@ GameOver_menu::GameOver_menu(int const points, json& params) : texture{}, textur playerText.setFillColor(sf::Color::Black); + // Line text + linetext = sf::Text{ "_________________________", font, 24 }; + sf::FloatRect gblt {linetext.getGlobalBounds()}; + linetext.setOrigin(gblt.width / 2, gblt.height / 2); + linetext.setPosition (S_WIDTH / 2 , ((S_HEIGHT / 2) + 10)); + linetext.setFillColor(sf::Color::Black); + + // mouse - texture2.loadFromFile("assets/muspekareGul.png"); + texture2.loadFromFile("assets/muspekareRed.png"); mouse_l.setTexture(texture2); mouse_l.setScale(0.1, 0.1); @@ -583,18 +599,18 @@ void GameOver_menu::update(Context& context) // changes color on text depending on selection if( menu_index == 1) { - savetext.setFillColor(sf::Color::Yellow); + savetext.setFillColor(sf::Color(153, 0, 0)); quittext.setFillColor(sf::Color::Black); } else if( menu_index == 2) { savetext.setFillColor(sf::Color::Black); - quittext.setFillColor(sf::Color::Yellow); + quittext.setFillColor(sf::Color(153, 0, 0)); } // 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) + 60 - 30*(menu_index - 1)), ((S_HEIGHT / 2) + 85 + 50*(menu_index - 1))); + mouse_l.setPosition(((S_WIDTH / 2) - 58 + 30*(menu_index - 1)), ((S_HEIGHT / 2) + 132 + 50*(menu_index - 1))); } @@ -606,7 +622,9 @@ void GameOver_menu::render(sf::RenderWindow& window) const window.draw(mouse_l); window.draw(mouse_r); + window.draw(entertext); window.draw(playerText); + window.draw(linetext); window.draw(pointstext); window.draw(savetext); window.draw(quittext); @@ -686,9 +704,9 @@ void GameOver_menu::handle_input(sf::Event& event) } //spara namn till fil -void GameOver_menu::load_to_csv() const +void GameOver_menu::load_to_csv() { - std::string current_line{"Gorilla," + std::to_string(points)}; + std::string current_line{"Gorilla, " + std::to_string(points)}; std::ifstream highscore_file_r{"assets/highscore.csv"}; std::vector lines_read; diff --git a/src/States.h b/src/States.h index d4e622d..0811992 100644 --- a/src/States.h +++ b/src/States.h @@ -154,7 +154,7 @@ public: void update(Context& context) override; void render(sf::RenderWindow& window) const override; void handle_input(sf::Event& event) override; - void load_to_csv() const; + void load_to_csv(); private: sf::Texture texture; @@ -165,6 +165,8 @@ private: sf::Sprite mouse_r; sf::String playerInput; sf::Text playerText; + sf::Text linetext; + sf::Text entertext; sf::Text pointstext; sf::Text savetext; sf::Text quittext;