Added joystick functionality to menus, untested
authorNils Forssén <nilfo359@student.liu.se>
Wed, 6 Dec 2023 19:41:40 +0000 (20:41 +0100)
committerNils Forssén <nilfo359@student.liu.se>
Wed, 6 Dec 2023 19:41:40 +0000 (20:41 +0100)
assets/highscore.csv
src/GameOver_menu.cc
src/Pause_menu.cc
src/Scoreboard_menu.cc
src/Start_menu.cc

index 1def999e404f4cf6c08da32231a91ee9ff84b32e..4f8ab68fbee6c5e1f7d0111c582a608acc16ac29 100644 (file)
@@ -1,2 +1,3 @@
 Nisseboi, 5
 Lukas is KUNG, 5
+Nils, 1
index 181ce75b3b47e05125a7be9176466990f4d23b64..c55f2cb0fff0c0bbca9fbc9c3d0a4c087fa8fec1 100644 (file)
@@ -172,6 +172,63 @@ void GameOver_menu::handle_input(sf::Event& event)
 {
     switch (event.type)
     {
+    case sf::Event::JoystickButtonPressed:
+        switch (event.joystickButton.button) 
+        {
+            case 0: // A
+                if(menu_index == 1)
+                {
+                    load_to_csv(playerText);
+                    menu = true;
+                    menu_index = 1;
+                }
+
+                else if(menu_index == 2)
+                {
+                    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 == 2)
+                {
+                    break;
+                }
+
+                else
+                {
+                    menu_index += 1;
+                }
+                break; 
+            }
+            break;
+        }
+        break;
     case sf::Event::KeyPressed:
         switch(event.key.code)
         {
index 3c1afc1b98624bf9da4295e67d5819d4902f0117..cacd995955211895c3e882282d454b0644764d8a 100644 (file)
@@ -113,6 +113,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)
         {
index d7cfac95bac84cdafb54caf8b09107f7bbe5f294..b8c5dcc4d212bc211db02978371c0dc395d87421 100644 (file)
@@ -126,6 +126,62 @@ void Scoreboard_menu::handle_input(sf::Event& event)
 {
     switch (event.type)
     {
+    case sf::Event::JoystickButtonPressed:
+        switch (event.joystickButton.button) 
+        {
+            case 0: // A
+                if(menu_index == 1)
+                {
+                    menu = true;
+                    menu_index = 1;
+                }
+
+                else if(menu_index == 2)
+                {
+                    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)
         {
index 0bda96a800d8f6c6b087314688b162c49cd05699..e5c4b85b840feab696a2dadf3a474de2f93979fb 100644 (file)
@@ -115,6 +115,69 @@ void Start_menu::handle_input(sf::Event& event)
 {
     switch (event.type)
     {
+    case sf::Event::JoystickButtonPressed:
+        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)
         {