From e09948ac1329a3b3cda193b15702496070d2aa85 Mon Sep 17 00:00:00 2001 From: malak585 Date: Mon, 11 Dec 2023 09:12:16 +0100 Subject: [PATCH] fixed functions - alma, lukas, malin --- src/Start_menu.cc | 128 ++++++++++++++++++++-------------------------- src/States.h | 3 ++ 2 files changed, 58 insertions(+), 73 deletions(-) diff --git a/src/Start_menu.cc b/src/Start_menu.cc index 5472f94..faa7800 100644 --- a/src/Start_menu.cc +++ b/src/Start_menu.cc @@ -119,29 +119,12 @@ void Start_menu::handle_input(sf::Event& event) 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; - } + if_enter(); break; - default: - + + default: break; } - break; case sf::Event::JoystickMoved: @@ -151,28 +134,12 @@ void Start_menu::handle_input(sf::Event& event) case sf::Joystick::PovY: if (event.joystickMove.position <= -50) { - if(menu_index == 1) - { - break; - } - - else - { - menu_index -= 1; - } + if_up(); break; } else if (event.joystickMove.position >= 50) { - if(menu_index == 3) - { - break; - } - - else - { - menu_index += 1; - } + if_down(); break; } break; @@ -182,48 +149,16 @@ void Start_menu::handle_input(sf::Event& event) switch(event.key.code) { case sf::Keyboard::Enter: - 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; - } + if_enter(); break; case sf::Keyboard::Up: - if(menu_index == 1) - { - break; - } - - else - { - menu_index -= 1; - } + if_up(); break; case sf::Keyboard::Down: - if(menu_index == 3) - { - break; - } - - else - { - menu_index += 1; - } + if_down(); break; default: @@ -236,3 +171,50 @@ void Start_menu::handle_input(sf::Event& event) } } +void Start_menu::if_enter() +{ + 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; + } +} + +void Start_menu::if_up() +{ + if(menu_index == 1) + { + return; + } + + else + { + menu_index -= 1; + } + +} + +void Start_menu::if_down() +{ + if(menu_index == 3) + { + return; + } + + else + { + menu_index += 1; + } +} \ No newline at end of file diff --git a/src/States.h b/src/States.h index 8e97c34..3e4033b 100644 --- a/src/States.h +++ b/src/States.h @@ -67,6 +67,9 @@ public: void update(Context& context) override; void render(sf::RenderWindow& window) const override; void handle_input(sf::Event& event) override; + void if_enter(); + void if_up(); + void if_down(); private: sf::Texture texture; -- 2.30.2