main_screen.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include <notification/notification_messages.h>
  2. #include "main_screen.h"
  3. static bool is_dirty = false;
  4. static size_t last_start = 0;
  5. static int8_t note = 0;
  6. static const float VOLUME = 0.25f;
  7. static const NotificationMessage note_e4 = {
  8. .type = NotificationMessageTypeSoundOn,
  9. .data.sound.frequency = 329.63f,
  10. .data.sound.volume = VOLUME,
  11. };
  12. static const NotificationMessage note_g4 = {
  13. .type = NotificationMessageTypeSoundOn,
  14. .data.sound.frequency = 392.0f,
  15. .data.sound.volume = VOLUME,
  16. };
  17. static const NotificationMessage note_c5 = {
  18. .type = NotificationMessageTypeSoundOn,
  19. .data.sound.frequency = 523.25f,
  20. .data.sound.volume = VOLUME,
  21. };
  22. static const NotificationMessage note_d4 = {
  23. .type = NotificationMessageTypeSoundOn,
  24. .data.sound.frequency = 293.66f,
  25. .data.sound.volume = VOLUME,
  26. };
  27. static const NotificationMessage note_f4 = {
  28. .type = NotificationMessageTypeSoundOn,
  29. .data.sound.frequency = 349.23f,
  30. .data.sound.volume = VOLUME,
  31. };
  32. static const NotificationMessage note_b4 = {
  33. .type = NotificationMessageTypeSoundOn,
  34. .data.sound.frequency = 493.88f,
  35. .data.sound.volume = VOLUME,
  36. };
  37. static const NotificationMessage* music_notes[] = {
  38. &note_e4, &note_g4, &note_c5, &message_sound_off, &note_g4, &message_sound_off,
  39. &note_e4, &note_g4, &note_c5, &message_sound_off, &note_g4, &message_sound_off,
  40. &note_d4, &note_f4, &note_b4, &message_sound_off, &note_f4, &message_sound_off,
  41. &note_d4, &note_f4, &note_b4, &message_sound_off, &note_f4, &message_sound_off,
  42. };
  43. static NotificationSequence music = {NULL, &message_delay_250, &message_sound_off, NULL};
  44. void start_main_screen(void* data) {
  45. is_dirty = true;
  46. GameState* state = (GameState*)data;
  47. last_start = 0;
  48. note = -1;
  49. state->lateRender = false;
  50. state->isDirty = true;
  51. state->clearBuffer = true;
  52. }
  53. void render_main_screen(void* data) {
  54. GameState* state = (GameState*)data;
  55. Vector logo_pos = (Vector){60, 30};
  56. Vector main_img_pos = (Vector){115, 25};
  57. Vector start_text_pos = (Vector){64, 55};
  58. buffer_draw_all(state->buffer, (Buffer*)&sprite_logo, &logo_pos, 0);
  59. buffer_draw_all(state->buffer, (Buffer*)&sprite_main_image, &main_img_pos, 0);
  60. buffer_draw_all(state->buffer, (Buffer*)&sprite_start, &start_text_pos, 0);
  61. }
  62. void update_main_screen(void* data) {
  63. GameState* state = (GameState*)data;
  64. UNUSED(state);
  65. size_t t = curr_time();
  66. //Play the menu music one note at a time to not block the app
  67. if((last_start - t) > 250) {
  68. if(note >= 0) {
  69. music[0] = music_notes[note];
  70. notification_message_block(
  71. state->notification_app, (const NotificationSequence*)&music);
  72. last_start = t;
  73. }
  74. note = (note + 1) % 24;
  75. }
  76. state->isDirty = is_dirty;
  77. is_dirty = false;
  78. }
  79. void input_main_screen(void* data, InputKey key, InputType type) {
  80. GameState* state = (GameState*)data;
  81. if(key == InputKeyOk && type == InputTypePress) {
  82. state->scene_switch = 1;
  83. }
  84. }