about_entity.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "about_entity.h"
  18. #include <stddef.h>
  19. #include <furi.h>
  20. #include "src/game.h"
  21. static void
  22. about_update(Entity* self, GameManager* manager, void* _entity_context)
  23. {
  24. UNUSED(self);
  25. UNUSED(_entity_context);
  26. GameContext* game_context = game_manager_game_context_get(manager);
  27. InputState input = game_manager_input_get(manager);
  28. if (input.pressed & (GameKeyOk | GameKeyBack | GameKeyLeft)) {
  29. game_manager_next_level_set(manager, game_context->levels.menu);
  30. }
  31. }
  32. static void
  33. about_render(Entity* self,
  34. GameManager* manager,
  35. Canvas* canvas,
  36. void* _entity_context)
  37. {
  38. UNUSED(self);
  39. UNUSED(manager);
  40. canvas_set_color(canvas, ColorBlack);
  41. canvas_set_font(canvas, FontSecondary);
  42. // Calculate positions
  43. const size_t logo_size = 10;
  44. const size_t space = 3;
  45. size_t title_width =
  46. logo_size + space + canvas_string_width(canvas, GAME_NAME);
  47. int32_t logo_x = SCREEN_WIDTH / 2 - title_width / 2;
  48. int32_t title_x = logo_x + logo_size + space;
  49. int32_t font_height = canvas_current_font_height(canvas);
  50. int32_t first_line_y = 17;
  51. // Draw logo
  52. AboutContext* entity_context = _entity_context;
  53. canvas_draw_sprite(canvas, entity_context->logo_sprite, logo_x, 0);
  54. // Draw game name
  55. canvas_set_font(canvas, FontPrimary);
  56. canvas_draw_str_aligned(canvas, title_x, 1, AlignLeft, AlignTop, GAME_NAME);
  57. // Draw authors
  58. canvas_set_font(canvas, FontSecondary);
  59. canvas_draw_str_aligned(canvas,
  60. 64,
  61. first_line_y,
  62. AlignCenter,
  63. AlignTop,
  64. "Developed by Ivan Barsukov");
  65. canvas_draw_str_aligned(canvas,
  66. 64,
  67. first_line_y + font_height,
  68. AlignCenter,
  69. AlignTop,
  70. "Inspired by David Martinez");
  71. canvas_draw_str_aligned(canvas,
  72. 64,
  73. first_line_y + font_height * 2,
  74. AlignCenter,
  75. AlignTop,
  76. "Graphics by DarKaoz");
  77. // Draw link
  78. canvas_draw_str_aligned(
  79. canvas, 64, 62, AlignCenter, AlignBottom, "github.com/ivanbarsukov");
  80. }
  81. const EntityDescription about_description = {
  82. .start = NULL,
  83. .stop = NULL,
  84. .update = about_update,
  85. .render = about_render,
  86. .collision = NULL,
  87. .event = NULL,
  88. .context_size = sizeof(AboutContext),
  89. };