menu_entity.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2025 Ivan Barsukov
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "menu_entity.h"
  18. #include "src/engine/entity.h"
  19. #include "src/engine/game_manager.h"
  20. #include "src/engine/level.h"
  21. #include "src/game.h"
  22. static void
  23. menu_update(Entity* self, GameManager* manager, void* _entity_context)
  24. {
  25. UNUSED(self);
  26. UNUSED(_entity_context);
  27. GameContext* game_context = game_manager_game_context_get(manager);
  28. Level* level = game_manager_current_level_get(manager);
  29. InputState input = game_manager_input_get(manager);
  30. if (input.pressed & GameKeyBack) {
  31. game_manager_game_stop(manager);
  32. } else if (input.pressed & GameKeyOk) {
  33. game_manager_next_level_set(manager, game_context->levels.game);
  34. level_send_event(
  35. level, self, NULL, GameEventSkipAnimation, (EntityEventValue){ 0 });
  36. } else if (input.pressed & GameKeyLeft) {
  37. game_manager_next_level_set(manager, game_context->levels.settings);
  38. level_send_event(
  39. level, self, NULL, GameEventSkipAnimation, (EntityEventValue){ 0 });
  40. } else if (input.pressed & GameKeyRight) {
  41. game_manager_next_level_set(manager, game_context->levels.about);
  42. level_send_event(
  43. level, self, NULL, GameEventSkipAnimation, (EntityEventValue){ 0 });
  44. }
  45. }
  46. const EntityDescription menu_description = {
  47. .start = NULL,
  48. .stop = NULL,
  49. .update = menu_update,
  50. .render = NULL,
  51. .collision = NULL,
  52. .event = NULL,
  53. .context_size = 0,
  54. };