added GameOver and Scoreboard menu
authormalak585 <malak585@su15-110.ad.liu.se>
Mon, 20 Nov 2023 08:45:44 +0000 (09:45 +0100)
committermalak585 <malak585@su15-110.ad.liu.se>
Mon, 20 Nov 2023 08:45:44 +0000 (09:45 +0100)
src/Menus.cc [new file with mode: 0644]
src/States.cc
src/States.h

diff --git a/src/Menus.cc b/src/Menus.cc
new file mode 100644 (file)
index 0000000..53accbe
--- /dev/null
@@ -0,0 +1,621 @@
+#include <memory>
+#include <iostream>
+
+#include "States.h"
+#include "Context.h"
+#include "constants.h"
+// Start menu --------------------------------------------
+Start_menu::Start_menu() : texture{},  texture2{}, sprite{}, mouse_l{}, mouse_r{}, start_game{false}, exit_game{false}, 
+                           scoreboard{false}, menu_index{1}, starttext{}, scoreboardtext{}, quittext{}, font{}
+{                         
+    //sprite
+    texture.loadFromFile("assets/meny_bild.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");
+    mouse_l.setTexture(texture2);
+
+    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");
+
+    //start 
+    starttext = sf::Text{ "Start Game", font, 24 };
+    sf::FloatRect gbts {starttext.getGlobalBounds()};
+    starttext.setOrigin(gbts.width / 2, gbts.height / 2);
+    starttext.setPosition ((S_WIDTH) / 2, ((S_HEIGHT / 2) - 100));
+
+    //score
+    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));
+
+    //quit
+    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);
+}
+
+void Start_menu::update(Context& context)
+{
+    if (start_game)
+    {
+        context.next_state = std::make_unique<Game_state>();
+    }
+    
+    if (scoreboard)
+    {
+        context.next_state = std::make_unique<Scoreboard_menu>();
+        scoreboard = false;
+        return;
+    }
+
+    // changes color on text depending on selection
+    if( menu_index == 1)
+    {
+        starttext.setFillColor(sf::Color::Yellow);
+        scoreboardtext.setFillColor(sf::Color::Black);
+        quittext.setFillColor(sf::Color::Black);  
+    }
+    else if( menu_index == 2)
+    {
+        starttext.setFillColor(sf::Color::Black);
+        scoreboardtext.setFillColor(sf::Color::Yellow);
+        quittext.setFillColor(sf::Color::Black);  
+    }
+        else if( menu_index == 3)
+    {
+        starttext.setFillColor(sf::Color::Black);
+        scoreboardtext.setFillColor(sf::Color::Black);
+        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))); 
+    
+}
+
+void Start_menu::render(sf::RenderWindow& window) const
+{
+    window.draw(sprite);
+    window.draw(mouse_l);
+    window.draw(mouse_r);
+
+    window.draw(starttext);
+    window.draw(scoreboardtext);
+    window.draw(quittext);
+
+    if (exit_game)
+    {
+        window.close();
+    }
+}
+
+void Start_menu::handle_input(sf::Event& event)
+{
+    switch (event.type)
+    {
+    case sf::Event::KeyPressed:
+        switch(event.key.code)
+        {
+        case sf::Keyboard::Enter:
+            if(menu_index == 1)
+            {
+                start_game = true; 
+                menu_index = 1;
+            }
+
+            else if(menu_index == 2)
+            {  
+                scoreboard = true;
+                menu_index = 1;
+            }
+
+            else if(menu_index == 3)
+            {
+                exit_game = true;
+                menu_index = 1;
+            }   
+            break;
+        
+
+        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;
+    }
+}
+
+
+// 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);;
+
+    sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
+    sf::FloatRect gb {sprite.getGlobalBounds()};
+    sprite.setPosition(0, 0);
+
+    // mouse
+    texture2.loadFromFile("assets/muspekareGul.png");
+    mouse_l.setTexture(texture2);
+
+    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 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)
+{
+    if (resume_game)
+    {
+        context.next_state = std::move(context.saved_game);
+    }
+    else if (menu)
+    {
+        context.next_state = std::make_unique<Start_menu>();
+        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)
+{
+    switch (event.type)
+    {
+    case sf::Event::KeyPressed:
+        switch(event.key.code)
+        {
+        case sf::Keyboard::Enter:
+            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::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;
+    }
+}
+
+
+// Scoreboard menu --------------------------------------------
+Scoreboard_menu::Scoreboard_menu() : /*texture{},*/ texture2{}, /*sprite{},*/ menu{false}, exit_game{false}, 
+                                 startmenutext{}, quittext{}, mouse_r{}, mouse_l{}, font{}, menu_index{1}
+{
+    // Add background later
+    /*
+    texture.loadFromFile("assets/Pause_bild.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");
+    mouse_l.setTexture(texture2);
+
+    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");
+
+
+    // 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));
+
+    // 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));
+}
+
+
+void Scoreboard_menu::update(Context& context)
+{
+    if (menu)
+    {
+        context.next_state = std::make_unique<Start_menu>();
+    }
+    // changes color on text depending on selection
+    if( menu_index == 1)
+    {
+        startmenutext.setFillColor(sf::Color::Yellow);
+        quittext.setFillColor(sf::Color::Black);
+    }
+    else if( menu_index == 2)
+    {
+        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 Scoreboard_menu::render(sf::RenderWindow& window) const
+{
+    /*window.draw(sprite);*/
+    window.draw(mouse_l);
+    window.draw(mouse_r);
+
+    window.draw(startmenutext);
+    window.draw(quittext);
+
+    if (exit_game)
+    {
+        window.close();
+    }
+}
+
+
+void Scoreboard_menu::handle_input(sf::Event& event)
+{
+    switch (event.type)
+    {
+    case sf::Event::KeyPressed:
+        switch(event.key.code)
+        {
+        case sf::Keyboard::Enter:
+
+            if(menu_index == 1)
+            {
+                menu = true;
+                menu_index = 1;
+            }
+
+            else if(menu_index == 2)
+            {
+                exit_game = true;
+                menu_index = 1;
+            }
+            break;
+        
+
+        case sf::Keyboard::Up:
+            if(menu_index == 1)
+            {
+                break;    
+            }
+
+            else;
+            {
+               menu_index -= 1;
+            }
+            break;
+
+        case sf::Keyboard::Down:
+            if(menu_index == 2)
+            {
+                break;
+            }
+
+            else;
+            {
+                menu_index += 1;
+            }
+            break;
+
+        default:
+            break;
+        }
+
+        break;
+    default:
+        break;
+    }
+}
+
+
+// GameOver menu --------------------------------------------
+GameOver_menu::GameOver_menu() : /*texture{},*/ texture2{}, /*sprite{},*/ menu{false}, exit_game{false}, 
+                                 startmenutext{}, quittext{}, mouse_r{}, mouse_l{}, font{}, menu_index{1}
+{
+    // Add background later
+    /*
+    texture.loadFromFile("assets/Pause_bild.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");
+    mouse_l.setTexture(texture2);
+
+    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");
+
+
+    // 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));
+
+    // 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));
+}
+
+
+void GameOver_menu::update(Context& context)
+{
+    if (menu)
+    {
+        context.next_state = std::make_unique<Start_menu>();
+    }
+    // changes color on text depending on selection
+    if( menu_index == 1)
+    {
+        startmenutext.setFillColor(sf::Color::Yellow);
+        quittext.setFillColor(sf::Color::Black);
+    }
+    else if( menu_index == 2)
+    {
+        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 GameOver_menu::render(sf::RenderWindow& window) const
+{
+    /*window.draw(sprite);*/
+    window.draw(mouse_l);
+    window.draw(mouse_r);
+
+    window.draw(startmenutext);
+    window.draw(quittext);
+
+    if (exit_game)
+    {
+        window.close();
+    }
+}
+
+
+void GameOver_menu::handle_input(sf::Event& event)
+{
+    switch (event.type)
+    {
+    case sf::Event::KeyPressed:
+        switch(event.key.code)
+        {
+        case sf::Keyboard::Enter:
+
+            if(menu_index == 1)
+            {
+                menu = true;
+                menu_index = 1;
+            }
+
+            else if(menu_index == 2)
+            {
+                exit_game = true;
+                menu_index = 1;
+            }
+            break;
+        
+
+        case sf::Keyboard::Up:
+            if(menu_index == 1)
+            {
+                break;    
+            }
+
+            else;
+            {
+               menu_index -= 1;
+            }
+            break;
+
+        case sf::Keyboard::Down:
+            if(menu_index == 2)
+            {
+                break;
+            }
+
+            else;
+            {
+                menu_index += 1;
+            }
+            break;
+
+        default:
+            break;
+        }
+
+        break;
+    default:
+        break;
+    }
+}
index 708530a907df5b2645fdbd3dff52e285ac6f9b1a..50a8ba36cb765c6b3430e3bfc84abf71c34a203c 100644 (file)
@@ -5,7 +5,7 @@
 #include "Context.h"
 #include "constants.h"
 
-Game_state::Game_state() : game_map{}, player{}, pause_game{false}
+Game_state::Game_state() : game_map{}, player{}, pause_game{false}, gameover{false}
 {
 }
 
@@ -19,8 +19,17 @@ void Game_state::update(Context& context)
         pause_game = false;
         return;
     }
+
+    if (gameover)
+    {
+        context.next_state = std::make_unique<GameOver_menu>();
+        gameover = false;
+        return;
+    }
+
     game_map.update(context);
     player.update(context);
+
 }
 
 void Game_state::render(sf::RenderWindow& window) const
@@ -40,332 +49,19 @@ void Game_state::handle_input(sf::Event& event)
             pause_game = true;
             return;
             break;
-        default:
-            break;
-        }
-        break;
-    default:
-        break;
-    }
-
-    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{}
-{                         
-    //sprite
-    texture.loadFromFile("assets/meny_bild.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");
-    mouse_l.setTexture(texture2);
-
-    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");
-
-    //start 
-    starttext = sf::Text{ "Start Game", font, 24 };
-    sf::FloatRect gbts {starttext.getGlobalBounds()};
-    starttext.setOrigin(gbts.width / 2, gbts.height / 2);
-    starttext.setPosition ((S_WIDTH) / 2, ((S_HEIGHT / 2) - 100));
-
-    //score
-    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));
-
-    //quit
-    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);
-}
-
-void Start_menu::update(Context& context)
-{
-    if (start_game)
-    {
-        context.next_state = std::make_unique<Game_state>();
-    }
-
-    if( menu_index == 1)
-    {
-        starttext.setFillColor(sf::Color::Yellow);
-        scoreboardtext.setFillColor(sf::Color::Black);
-        quittext.setFillColor(sf::Color::Black);  
-    }
-    else if( menu_index == 2)
-    {
-        starttext.setFillColor(sf::Color::Black);
-        scoreboardtext.setFillColor(sf::Color::Yellow);
-        quittext.setFillColor(sf::Color::Black);  
-    }
-        else if( menu_index == 3)
-    {
-        starttext.setFillColor(sf::Color::Black);
-        scoreboardtext.setFillColor(sf::Color::Black);
-        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))); 
-    
-}
-
-void Start_menu::render(sf::RenderWindow& window) const
-{
-    window.draw(sprite);
-    window.draw(mouse_l);
-    window.draw(mouse_r);
-
-    window.draw(starttext);
-    window.draw(scoreboardtext);
-    window.draw(quittext);
-
-    if (exit_game)
-    {
-        window.close();
-    }
-}
-
-void Start_menu::handle_input(sf::Event& event)
-{
-    switch (event.type)
-    {
-    case sf::Event::KeyPressed:
-        switch(event.key.code)
-        {
-        case sf::Keyboard::Enter:
-            if(menu_index == 1)
-            {
-               start_game = true; 
-               menu_index = 1;
-            }
-
-            else if(menu_index == 2)
-            {
-               menu_index = 1;
-            }
-
-            else if(menu_index == 3)
-            {
-               exit_game = true;
-               menu_index = 1;
-            }
-            break;
-        
-
-        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;
-            }
+        case  sf::Keyboard::T:
+            gameover = true;
             break;
 
         default:
             break;
         }
-
         break;
     default:
         break;
     }
-}
-
-
-// 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);;
-
-    sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
-    sf::FloatRect gb {sprite.getGlobalBounds()};
-    sprite.setPosition(0, 0);
-
-    // mouse
-    texture2.loadFromFile("assets/muspekareGul.png");
-    mouse_l.setTexture(texture2);
-
-    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 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)
-{
-    if (resume_game)
-    {
-        context.next_state = std::move(context.saved_game);
-    }
-    else if (menu)
-    {
-        context.next_state = std::make_unique<Start_menu>();
-        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();
-    }
+    player.handle_input(event);
 }
 
-void Pause_menu::handle_input(sf::Event& event)
-{
-    switch (event.type)
-    {
-    case sf::Event::KeyPressed:
-        switch(event.key.code)
-        {
-        case sf::Keyboard::Enter:
-            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::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;
-    }
-}
index 85e4ac1b59989be199613229ca418313e3f4afcb..2b078397518f44d3ff3a4ac1ff966e4bff738d7e 100644 (file)
@@ -32,6 +32,7 @@ protected:
 private:
     Player player;
     bool pause_game;
+    bool gameover;
 };
 
 class Start_menu : public State
@@ -56,6 +57,7 @@ private:
 
     bool start_game;
     bool exit_game;
+    bool scoreboard;
 
     int menu_index;
 };
@@ -87,4 +89,56 @@ private:
 };
 
 
+class Scoreboard_menu : public State
+{
+public:
+    Scoreboard_menu();
+    ~Scoreboard_menu() = default;
+    void update(Context& context) override;
+    void render(sf::RenderWindow& window) const override;
+    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 startmenutext;    
+    sf::Text quittext;
+    sf::Font font;
+
+    bool exit_game;
+    bool menu;
+
+    int menu_index;
+};
+
+
+class GameOver_menu : public State
+{
+public:
+    GameOver_menu();
+    ~GameOver_menu() = default;
+    void update(Context& context) override;
+    void render(sf::RenderWindow& window) const override;
+    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 startmenutext;    
+    sf::Text quittext;
+    sf::Font font;
+
+    bool exit_game;
+    bool menu;
+
+    int menu_index;
+};
+
+
+
+
 #endif
\ No newline at end of file