level_game_over.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "level_game_over.h"
  18. #include <stddef.h>
  19. #include <furi.h>
  20. #include "../../game.h"
  21. #include "../../game_settings.h"
  22. #include "game_over_entity.h"
  23. typedef struct
  24. {
  25. Entity* entitiy;
  26. } GameOverLevelContext;
  27. static void
  28. level_game_over_alloc(Level* level, GameManager* manager, void* context)
  29. {
  30. GameOverLevelContext* game_over_context = context;
  31. game_over_context->entitiy =
  32. level_add_entity(level, &game_over_description);
  33. GameOverEntityContext* entity_context =
  34. entity_context_get(game_over_context->entitiy);
  35. entity_context->logo_sprite =
  36. game_manager_sprite_load(manager, "game_over.fxbm");
  37. entity_context->score = 0;
  38. entity_context->max_score = 0;
  39. }
  40. static void
  41. level_game_over_start(Level* level, GameManager* manager, void* _level_context)
  42. {
  43. UNUSED(level);
  44. GameOverLevelContext* level_context = _level_context;
  45. GameOverEntityContext* entity_context =
  46. entity_context_get(level_context->entitiy);
  47. GameContext* game_context = game_manager_game_context_get(manager);
  48. if (game_context->score > game_context->best_score) {
  49. game_context->best_score = game_context->score;
  50. game_save_settings(game_context);
  51. }
  52. entity_context->score = game_context->score;
  53. entity_context->max_score = game_context->best_score;
  54. FURI_LOG_D(GAME_NAME, "Game over level started");
  55. }
  56. const LevelBehaviour level_game_over = {
  57. .alloc = level_game_over_alloc,
  58. .free = NULL,
  59. .start = level_game_over_start,
  60. .stop = NULL,
  61. .context_size = sizeof(GameOverLevelContext),
  62. };