From 5801772395f328867659019368866040180ac93a Mon Sep 17 00:00:00 2001 From: stian853 Date: Mon, 4 Dec 2023 09:05:25 +0100 Subject: [PATCH] joystick i startmeny, Nils, Arvid, Stina --- assets/highscore.csv | 2 ++ src/Menus.cc | 67 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/assets/highscore.csv b/assets/highscore.csv index 84f9f79..3cc2c06 100644 --- a/assets/highscore.csv +++ b/assets/highscore.csv @@ -1,3 +1,5 @@ Gorilla,36 Gorilla,27 +Gorilla,24 +Gorilla,18 Gorilla,13 diff --git a/src/Menus.cc b/src/Menus.cc index dff5ae5..8928d23 100644 --- a/src/Menus.cc +++ b/src/Menus.cc @@ -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: -- 2.30.2