MenuState.hxx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #ifndef SNAKE_MENUSTATE_HXX
  3. #define SNAKE_MENUSTATE_HXX
  4. #include "GameState.hxx"
  5. #include "ui/Button.hxx"
  6. #include <optional>
  7. class PlayingState;
  8. class MenuState final : public GameState {
  9. public:
  10. void on_enter(GameStateManager& gsm) override;
  11. void on_leave() override;
  12. void on_event(GameStateManager& gsm, SDL_Event const& evt) override;
  13. void update(GameStateManager& gsm, std::chrono::milliseconds delta_time) override;
  14. void render(SDLRenderer& renderer) override;
  15. private:
  16. static int constexpr ACTIVE_SIZE_DIFF = 32;
  17. static int constexpr BUTTON_HEIGHT = 80;
  18. static int constexpr BUTTON_WIDTH = 350;
  19. void handle_key_up(GameStateManager& gsm, SDL_Scancode scancode);
  20. void handle_key_down(SDL_Scancode scancode);
  21. void handle_controller_button_up(GameStateManager& gsm, std::uint8_t button);
  22. void handle_controller_button_down(std::uint8_t button);
  23. void handle_mouse_movement(int x, int y);
  24. void handle_controller_axis_motion(std::uint8_t axis, std::int16_t value);
  25. void select_previous_button();
  26. void select_next_button();
  27. void trigger_active_button();
  28. Button new_game_button_{0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, UiColor::Green};
  29. Button continue_button_{0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, UiColor::Blue};
  30. Button high_score_button_{0, 0, BUTTON_WIDTH, BUTTON_HEIGHT};
  31. Button credits_button_{0, 0, BUTTON_WIDTH, BUTTON_HEIGHT};
  32. Button quit_button_{0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, UiColor::Red};
  33. std::optional<PlayingState*> game_{};
  34. int active_button_{0};
  35. int last_controller_direction_{0};
  36. };
  37. #endif // SNAKE_MENUSTATE_HXX