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:
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;
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:
}
}
+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
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;