joystick in pausmeny
authorstian853 <stian853@su15-112.ad.liu.se>
Mon, 4 Dec 2023 08:08:39 +0000 (09:08 +0100)
committerstian853 <stian853@su15-112.ad.liu.se>
Mon, 4 Dec 2023 08:08:39 +0000 (09:08 +0100)
src/Menus.cc

index 8928d23d83994a9d6ed2c3de8b368639cb6701ba..09f1d5c5972a7b743057f558641eb17069798562 100644 (file)
@@ -114,7 +114,6 @@ void Start_menu::handle_input(sf::Event& event)
     switch (event.type)
     {
     case sf::Event::JoystickButtonPressed:
-        std::cout << event.joystickButton.button << std::endl;
         switch (event.joystickButton.button) 
         {
             case 0: // A
@@ -343,6 +342,68 @@ void Pause_menu::handle_input(sf::Event& event)
 {
     switch (event.type)
     {
+    case sf::Event::JoystickButtonPressed:
+        switch (event.joystickButton.button) 
+        {
+            case 0: // A
+                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;
+            default:
+                
+                break;
+        }
+        
+        break;
+    case sf::Event::JoystickMoved:
+        switch(event.joystickMove.axis)
+        {
+        case sf::Joystick::Y:
+        case sf::Joystick::PovY:
+            if (event.joystickMove.position <= -50)
+            {
+                if(menu_index == 1)
+                {
+                    break;    
+                }
+
+                else
+                {
+                menu_index -= 1;
+                }
+                break;
+            }
+            else if (event.joystickMove.position >= 50)
+            {
+                if(menu_index == 3)
+                {
+                    break;
+                }
+
+                else
+                {
+                    menu_index += 1;
+                }
+                break; 
+            }
+            break;
+        }
+        break;
     case sf::Event::KeyPressed:
         switch(event.key.code)
         {