user.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include <furi.h>
  2. #include <gui/elements.h>
  3. #include "dolphin_scene/dolphin_scene.h"
  4. void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas) {
  5. furi_assert(state);
  6. furi_assert(canvas);
  7. if(state->scene_zoom == SCENE_ZOOM) {
  8. state->dolphin_gfx = I_DolphinExcited_64x63;
  9. } else if(state->action == SLEEP && state->player_global.x == 154) {
  10. state->dolphin_gfx = A_FX_Sitting_40x27;
  11. state->dolphin_gfx_b = I_FX_SittingB_40x27;
  12. } else if(state->action != INTERACT) {
  13. if(state->player_v.x < 0 || state->player_flipped) {
  14. if(state->player_anim == 0) {
  15. state->dolphin_gfx = I_WalkL1_32x32;
  16. state->dolphin_gfx_b = I_WalkLB1_32x32;
  17. } else {
  18. state->dolphin_gfx = I_WalkL2_32x32;
  19. state->dolphin_gfx_b = I_WalkLB2_32x32;
  20. }
  21. } else if(state->player_v.x > 0 || !state->player_flipped) {
  22. if(state->player_anim == 0) {
  23. state->dolphin_gfx = I_WalkR1_32x32;
  24. state->dolphin_gfx_b = I_WalkRB1_32x32;
  25. } else {
  26. state->dolphin_gfx = I_WalkR2_32x32;
  27. state->dolphin_gfx_b = I_WalkRB2_32x32;
  28. }
  29. }
  30. }
  31. // zoom handlers
  32. canvas_set_bitmap_mode(canvas, true);
  33. canvas_set_color(canvas, ColorWhite);
  34. canvas_draw_icon_name(canvas, state->player.x, state->player.y, state->dolphin_gfx_b);
  35. canvas_set_color(canvas, ColorBlack);
  36. canvas_draw_icon_name(canvas, state->player.x, state->player.y, state->dolphin_gfx);
  37. canvas_set_bitmap_mode(canvas, false);
  38. }
  39. void dolphin_scene_handle_user_input(SceneState* state, InputEvent* input) {
  40. furi_assert(state);
  41. furi_assert(input);
  42. // dolphin_scene_debug
  43. if(input->type == InputTypeShort) {
  44. if(input->key == InputKeyUp) {
  45. state->debug = !state->debug;
  46. }
  47. }
  48. // toggle mind control on any user interaction
  49. if(input->type == InputTypePress) {
  50. if(input->key == InputKeyLeft || input->key == InputKeyRight || input->key == InputKeyOk) {
  51. state->action = MINDCONTROL;
  52. }
  53. }
  54. // zoom poc for tests
  55. if(input->type == InputTypePress) {
  56. if(input->key == InputKeyDown) {
  57. state->zoom_v = SPEED_X;
  58. }
  59. } else if(input->type == InputTypeRelease) {
  60. if(input->key == InputKeyDown) {
  61. state->zoom_v = -SPEED_X * 2;
  62. state->dialog_progress = 0;
  63. }
  64. }
  65. // mind control
  66. if(state->action == MINDCONTROL) {
  67. if(input->type == InputTypePress) {
  68. if(input->key == InputKeyRight) {
  69. state->player_flipped = false;
  70. state->player_v.x = SPEED_X;
  71. } else if(input->key == InputKeyLeft) {
  72. state->player_flipped = true;
  73. state->player_v.x = -SPEED_X;
  74. }
  75. } else if(input->type == InputTypeRelease) {
  76. if(input->key == InputKeyRight || input->key == InputKeyLeft) {
  77. state->player_v.x = 0;
  78. }
  79. } else if(input->type == InputTypeShort) {
  80. if(input->key == InputKeyOk) {
  81. state->prev_action = MINDCONTROL;
  82. state->action = INTERACT;
  83. state->use_pending = true;
  84. state->action_timeout = 0;
  85. }
  86. }
  87. }
  88. }
  89. void dolphin_scene_coordinates(SceneState* state, uint32_t dt) {
  90. furi_assert(state);
  91. // global pos
  92. state->player_global.x = CLAMP(state->player_global.x + state->player_v.x, WORLD_WIDTH, 0);
  93. // zoom handlers
  94. state->scene_zoom = CLAMP(state->scene_zoom + state->zoom_v, SCENE_ZOOM, 0);
  95. state->player.x = CLAMP(state->player.x - (state->zoom_v * (SPEED_X * 2)), DOLPHIN_CENTER, 0);
  96. state->player.y = CLAMP(state->player.y - (state->zoom_v * SPEED_X / 2), DOLPHIN_DEFAULT_Y, 3);
  97. //center screen
  98. state->screen.x = state->player_global.x - state->player.x;
  99. state->player_anim = (state->player_global.x / 10) % 2;
  100. }