From: Alma Dejus Date: Wed, 15 Nov 2023 13:17:43 +0000 (+0100) Subject: updated the paus menu - Alma och Malin X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=cddf98826938051582a5570a1da239b334a3cffa;p=TDDC76_proj.git updated the paus menu - Alma och Malin --- diff --git a/src/States.cc b/src/States.cc index 2da252f..708530a 100644 --- a/src/States.cc +++ b/src/States.cc @@ -51,6 +51,7 @@ void Game_state::handle_input(sf::Event& event) player.handle_input(event); } +// Start menu -------------------------------------------- Start_menu::Start_menu() : texture{}, texture2{}, sprite{}, mouse_l{}, mouse_r{}, start_game{false}, exit_game{false}, menu_index{1}, starttext{}, scoreboardtext{}, quittext{}, font{} { @@ -123,7 +124,6 @@ void Start_menu::update(Context& context) quittext.setFillColor(sf::Color::Yellow); } - // mouse placement mouse_r.setPosition(((S_WIDTH / 2) + 60), ((S_HEIGHT / 2) - 115 + 50*(menu_index - 1))); mouse_l.setPosition(((S_WIDTH / 2) - 58), ((S_HEIGHT / 2) - 68 + 50*(menu_index - 1))); @@ -140,7 +140,7 @@ void Start_menu::render(sf::RenderWindow& window) const window.draw(scoreboardtext); window.draw(quittext); - if (exit_game == true) + if (exit_game) { window.close(); } @@ -207,9 +207,11 @@ void Start_menu::handle_input(sf::Event& event) } } -Pause_menu::Pause_menu() : texture{}, sprite{}, resume_game{false}, exit_game{false} + +// Pause menu -------------------------------------------- +Pause_menu::Pause_menu() : texture{}, texture2{}, sprite{}, resume_game{false}, menu{false}, exit_game{false}, + resumetext{}, startmenutext{}, quittext{}, mouse_r{}, mouse_l{}, font{}, menu_index{1} { - /* texture.loadFromFile("assets/Pause_bild.png"); sprite.setTexture(texture);; @@ -217,20 +219,40 @@ Pause_menu::Pause_menu() : texture{}, sprite{}, resume_game{false}, exit_game{fa sf::FloatRect gb {sprite.getGlobalBounds()}; sprite.setPosition(0, 0); - // - scoreboardtext = sf::Text{ "Scoreboard", font, 24 }; - sf::FloatRect gbtb {scoreboardtext.getGlobalBounds()}; - scoreboardtext.setOrigin(gbtb.width / 2, gbtb.height / 2); - scoreboardtext.setPosition (S_WIDTH / 2, ((S_HEIGHT / 2) - 50)); - scoreboardtext.setFillColor(sf::Color::Black); + // mouse + texture2.loadFromFile("assets/muspekareGul.png"); + mouse_l.setTexture(texture2); - //quit + mouse_l.setScale(0.1, 0.1); + mouse_l.setRotation(180); + sf::FloatRect gbm {mouse_l.getGlobalBounds()}; + + mouse_r.setTexture(texture2); + mouse_r.setScale(0.1, 0.1); + + + //load textfont + if ( !font.loadFromFile ("assets/fonts/Philosopher-Regular.ttf") ) + throw std::invalid_argument ("Unable to load font"); + + + // Resume text + resumetext = sf::Text{ "Resume", font, 24 }; + sf::FloatRect gbr {resumetext.getGlobalBounds()}; + resumetext.setOrigin(gbr.width / 2, gbr.height / 2); + resumetext.setPosition (S_WIDTH / 2, ((S_HEIGHT / 2) - 30)); + + // Start menu text + startmenutext = sf::Text{ "Start menu", font, 24 }; + sf::FloatRect gbs {startmenutext.getGlobalBounds()}; + startmenutext.setOrigin(gbs.width / 2, gbs.height / 2); + startmenutext.setPosition (S_WIDTH / 2, ((S_HEIGHT / 2) + 20)); + + //quit text quittext = sf::Text{ "Quit", font, 24 }; - sf::FloatRect gbtq {quittext.getGlobalBounds()}; - quittext.setOrigin(gbtq.width / 2, gbtq.height / 2); - quittext.setPosition (S_WIDTH / 2, S_HEIGHT / 2); - quittext.setFillColor(sf::Color::Black); -*/ + sf::FloatRect gbq {quittext.getGlobalBounds()}; + quittext.setOrigin(gbq.width / 2, gbq.height / 2 ); + quittext.setPosition (S_WIDTH / 2, ((S_HEIGHT / 2) + 70)); } void Pause_menu::update(Context& context) @@ -239,16 +261,51 @@ void Pause_menu::update(Context& context) { context.next_state = std::move(context.saved_game); } - else if (exit_game) + else if (menu) { context.next_state = std::make_unique(); context.saved_game.release(); } + + // changes color on text depending on selection + if( menu_index == 1) + { + resumetext.setFillColor(sf::Color::Yellow); + startmenutext.setFillColor(sf::Color::Black); + quittext.setFillColor(sf::Color::Black); + } + else if( menu_index == 2) + { + resumetext.setFillColor(sf::Color::Black); + startmenutext.setFillColor(sf::Color::Yellow); + quittext.setFillColor(sf::Color::Black); + } + else if( menu_index == 3) + { + resumetext.setFillColor(sf::Color::Black); + startmenutext.setFillColor(sf::Color::Black); + quittext.setFillColor(sf::Color::Yellow); + } + + // 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))); } void Pause_menu::render(sf::RenderWindow& window) const { window.draw(sprite); + window.draw(mouse_l); + window.draw(mouse_r); + + window.draw(resumetext); + window.draw(startmenutext); + window.draw(quittext); + + if (exit_game) + { + window.close(); + } } void Pause_menu::handle_input(sf::Event& event) @@ -259,14 +316,54 @@ void Pause_menu::handle_input(sf::Event& event) switch(event.key.code) { case sf::Keyboard::Enter: - resume_game = true; + if(menu_index == 1) + { + resume_game = true; + menu_index = 1; + } + + else if(menu_index == 2) + { + menu = true; + menu_index = 1; + } + + else if(menu_index == 3) + { + exit_game = true; + menu_index = 1; + } break; - case sf::Keyboard::Escape: - exit_game = true; + + + case sf::Keyboard::Up: + if(menu_index == 1) + { + break; + } + + else; + { + menu_index -= 1; + } break; + + case sf::Keyboard::Down: + if(menu_index == 3) + { + break; + } + + else; + { + menu_index += 1; + } + break; + default: break; } + break; default: break; diff --git a/src/States.h b/src/States.h index 8991484..85e4ac1 100644 --- a/src/States.h +++ b/src/States.h @@ -49,13 +49,14 @@ private: sf::Sprite sprite; sf::Sprite mouse_l; sf::Sprite mouse_r; - sf::Text gametitle; sf::Text starttext; sf::Text scoreboardtext; sf::Text quittext; sf::Font font; + bool start_game; bool exit_game; + int menu_index; }; @@ -69,9 +70,20 @@ public: void handle_input(sf::Event& event) override; private: sf::Texture texture; + sf::Texture texture2; sf::Sprite sprite; + sf::Sprite mouse_l; + sf::Sprite mouse_r; + sf::Text resumetext; + sf::Text startmenutext; + sf::Text quittext; + sf::Font font; + bool resume_game; bool exit_game; + bool menu; + + int menu_index; };