fixed functions - alma, lukas, malin
authormalak585 <malak585@su15-111.ad.liu.se>
Mon, 11 Dec 2023 08:12:16 +0000 (09:12 +0100)
committermalak585 <malak585@su15-111.ad.liu.se>
Mon, 11 Dec 2023 08:12:16 +0000 (09:12 +0100)
src/Start_menu.cc
src/States.h

index 5472f943e64321630e4749ce477ac2cc48ae37c2..faa78004f9683711b181d11aed4db3597320738c 100644 (file)
@@ -119,29 +119,12 @@ void Start_menu::handle_input(sf::Event& event)
         switch (event.joystickButton.button) 
         {
             case 0: // A
-                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;
-                }   
+                if_enter();
                 break;
-            default:
-                
+
+            default: 
                 break;
         }
-        
         break;
         
     case sf::Event::JoystickMoved:
@@ -151,28 +134,12 @@ void Start_menu::handle_input(sf::Event& event)
         case sf::Joystick::PovY:
             if (event.joystickMove.position <= -50)
             {
-                if(menu_index == 1)
-                {
-                    break;    
-                }
-
-                else
-                {
-                menu_index -= 1;
-                }
+                if_up();
                 break;
             }
             else if (event.joystickMove.position >= 50)
             {
-                if(menu_index == 3)
-                {
-                    break;
-                }
-
-                else
-                {
-                    menu_index += 1;
-                }
+                if_down();
                 break; 
             }
             break;
@@ -182,48 +149,16 @@ void Start_menu::handle_input(sf::Event& event)
         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;
-            }   
+            if_enter();
             break;
         
 
         case sf::Keyboard::Up:
-            if(menu_index == 1)
-            {
-                break;    
-            }
-
-            else
-            {
-               menu_index -= 1;
-            }
+            if_up();
             break;
 
         case sf::Keyboard::Down:
-            if(menu_index == 3)
-            {
-                break;
-            }
-
-            else
-            {
-                menu_index += 1;
-            }
+            if_down();
             break;
 
         default:
@@ -236,3 +171,50 @@ void Start_menu::handle_input(sf::Event& event)
     }
 }
 
+void Start_menu::if_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;
+    }   
+}
+
+void Start_menu::if_up()
+{
+    if(menu_index == 1)
+    {
+        return;    
+    }
+
+    else
+    {
+        menu_index -= 1;
+    }
+
+}
+
+void Start_menu::if_down()
+{
+    if(menu_index == 3)
+    {
+        return;
+    }
+
+    else
+    {
+        menu_index += 1;
+    }
+}
\ No newline at end of file
index 8e97c34315666263ba4e4f1f4720f09673ddc724..3e4033b0982b07ca30f08ca291ef4ea01b357e65 100644 (file)
@@ -67,6 +67,9 @@ public:
     void update(Context& context) override;
     void render(sf::RenderWindow& window) const override;
     void handle_input(sf::Event& event) override;
+    void if_enter();
+    void if_up();
+    void if_down();
 
 private:
     sf::Texture texture;