From cf6a279c9f0b42ebfffa37ebde95933c6a627817 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nils=20Forss=C3=A9n?= Date: Wed, 6 Dec 2023 20:41:40 +0100 Subject: [PATCH] Added joystick functionality to menus, untested --- assets/highscore.csv | 1 + src/GameOver_menu.cc | 57 ++++++++++++++++++++++++++++++++++++++ src/Pause_menu.cc | 62 +++++++++++++++++++++++++++++++++++++++++ src/Scoreboard_menu.cc | 56 +++++++++++++++++++++++++++++++++++++ src/Start_menu.cc | 63 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 239 insertions(+) diff --git a/assets/highscore.csv b/assets/highscore.csv index 1def999..4f8ab68 100644 --- a/assets/highscore.csv +++ b/assets/highscore.csv @@ -1,2 +1,3 @@ Nisseboi, 5 Lukas is KUNG, 5 +Nils, 1 diff --git a/src/GameOver_menu.cc b/src/GameOver_menu.cc index 181ce75..c55f2cb 100644 --- a/src/GameOver_menu.cc +++ b/src/GameOver_menu.cc @@ -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) { diff --git a/src/Pause_menu.cc b/src/Pause_menu.cc index 3c1afc1..cacd995 100644 --- a/src/Pause_menu.cc +++ b/src/Pause_menu.cc @@ -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) { diff --git a/src/Scoreboard_menu.cc b/src/Scoreboard_menu.cc index d7cfac9..b8c5dcc 100644 --- a/src/Scoreboard_menu.cc +++ b/src/Scoreboard_menu.cc @@ -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) { diff --git a/src/Start_menu.cc b/src/Start_menu.cc index 0bda96a..e5c4b85 100644 --- a/src/Start_menu.cc +++ b/src/Start_menu.cc @@ -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) { -- 2.30.2