joystick i startmeny, Nils, Arvid, Stina
authorstian853 <stian853@su15-112.ad.liu.se>
Mon, 4 Dec 2023 08:05:25 +0000 (09:05 +0100)
committerstian853 <stian853@su15-112.ad.liu.se>
Mon, 4 Dec 2023 08:05:25 +0000 (09:05 +0100)
assets/highscore.csv
src/Menus.cc

index 84f9f79576e514b62dbe2e67f209a520b2ea71fc..3cc2c0685d20d6ebc4ec66b83788424b4dbf1e0f 100644 (file)
@@ -1,3 +1,5 @@
 Gorilla,36
 Gorilla,27
+Gorilla,24
+Gorilla,18
 Gorilla,13
index dff5ae569efd8b1d09fb978b9d924306f6583b73..8928d23d83994a9d6ed2c3de8b368639cb6701ba 100644 (file)
@@ -110,10 +110,75 @@ void Start_menu::render(sf::RenderWindow& window) const
 }
 
 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
+                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;
+            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)
         {
         case sf::Keyboard::Enter: