worked on start menu - Malin och Alma
authorAlma Dejus <almde515@student.liu.se>
Tue, 14 Nov 2023 14:24:51 +0000 (15:24 +0100)
committerAlma Dejus <almde515@student.liu.se>
Tue, 14 Nov 2023 14:24:51 +0000 (15:24 +0100)
assets/muspekare.png [new file with mode: 0644]
assets/muspekare2.png [new file with mode: 0644]
assets/muspekareGul.png [new file with mode: 0644]
src/States.cc
src/States.h

diff --git a/assets/muspekare.png b/assets/muspekare.png
new file mode 100644 (file)
index 0000000..1458ae7
Binary files /dev/null and b/assets/muspekare.png differ
diff --git a/assets/muspekare2.png b/assets/muspekare2.png
new file mode 100644 (file)
index 0000000..c6ca43b
Binary files /dev/null and b/assets/muspekare2.png differ
diff --git a/assets/muspekareGul.png b/assets/muspekareGul.png
new file mode 100644 (file)
index 0000000..1f22c8b
Binary files /dev/null and b/assets/muspekareGul.png differ
index 00cd9c1ef40bf8a27e4ef6ac98780d5f6ce95b47..8a59ded12ee1a9378fc0c3a2295b9b5e18aab22a 100644 (file)
@@ -1,4 +1,5 @@
 #include <memory>
+#include <iostream>
 
 #include "States.h"
 #include "Context.h"
@@ -50,8 +51,9 @@ void Game_state::handle_input(sf::Event& event)
     player.handle_input(event);
 }
 
-Start_menu::Start_menu() : texture{}, sprite{}, exit_menu{false}, gametitle{}, starttext{}, scoreboardtext{}, quittext{}, font{}
-{
+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);
@@ -60,6 +62,17 @@ Start_menu::Start_menu() : texture{}, sprite{}, exit_menu{false}, gametitle{}, s
     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/ComicNeue-Bold.ttf") )
@@ -86,26 +99,55 @@ Start_menu::Start_menu() : texture{}, sprite{}, exit_menu{false}, gametitle{}, s
     quittext.setPosition (S_WIDTH / 2, S_HEIGHT / 2);
     quittext.setFillColor(sf::Color::Black);
 
-
-
 }
 
 void Start_menu::update(Context& context)
 {
-    if (exit_menu)
+    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(gametitle);
     window.draw(starttext);
     window.draw(scoreboardtext);
     window.draw(quittext);
+
+    if (exit_game == true)
+    {
+        window.close();
+    }
 }
 
 void Start_menu::handle_input(sf::Event& event)
@@ -116,11 +158,57 @@ void Start_menu::handle_input(sf::Event& event)
         switch(event.key.code)
         {
         case sf::Keyboard::Enter:
-            exit_menu = true;
+            if(menu_index == 1)
+            {
+               start_game = true; 
+               menu_index = 1;
+            }
+
+            else if(menu_index == 2)
+            {
+               std::cout << "det funka att se poäng" << std::endl; // lägg in state för scoreboard sen
+               menu_index = 1;
+            }
+
+            else if(menu_index == 3)
+            {
+               exit_game = true;
+               std::cout << "det funka att stänga av" << std::endl;
+               menu_index = 1;
+            }
+            break;
+        
+
+        case sf::Keyboard::Up:
+            std::cout << "det funka att trycka på upp" << std::endl;
+            if(menu_index == 1)
+            {
+                break;    
+            }
+
+            else;
+            {
+               menu_index -= 1;
+            }
+            break;
+
+        case sf::Keyboard::Down:
+            std::cout << "det funka att trycka på ned" << std::endl;
+            if(menu_index == 3)
+            {
+                break;
+            }
+
+            else;
+            {
+                menu_index += 1;
+            }
             break;
+
         default:
             break;
         }
+
         break;
     default:
         break;
@@ -129,12 +217,28 @@ void Start_menu::handle_input(sf::Event& event)
 
 Pause_menu::Pause_menu() : texture{}, sprite{}, resume_game{false}, exit_game{false}
 {
-    texture.loadFromFile("assets/kir.png");
-    sprite.setTexture(texture);
+    /*
+    texture.loadFromFile("assets/Pause_bild.png");
+    sprite.setTexture(texture);;
 
+    sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
     sf::FloatRect gb {sprite.getGlobalBounds()};
-    sprite.setOrigin(gb.width / 2, gb.height / 2);
-    sprite.setPosition(S_WIDTH / 2, S_HEIGHT / 2);
+    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);
+
+    //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);
+    quittext.setFillColor(sf::Color::Black);
+*/
 }
 
 void Pause_menu::update(Context& context)
index fbefefb99500c2616e792afa0fa09ed3d0724f55..8991484ef9a8c592eb3babd1f7aec26ccafccddd 100644 (file)
@@ -45,13 +45,18 @@ public:
 
 private:
     sf::Texture texture;
+    sf::Texture texture2;
     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 exit_menu;
+    bool start_game;
+    bool exit_game;
+    int menu_index;
 };
 
 class Pause_menu : public State