scene_controls.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <furi.h>
  2. #include <gui/elements.h>
  3. #include "scene.h"
  4. void dolphin_scene_handle_user_input(SceneState* state, InputEvent* input) {
  5. furi_assert(state);
  6. furi_assert(input);
  7. // dolphin_scene_debug
  8. if(input->type == InputTypeShort) {
  9. if(input->key == InputKeyUp) {
  10. state->debug = !state->debug;
  11. }
  12. }
  13. // toggle mind control on any user interaction
  14. if(input->type == InputTypePress) {
  15. if(input->key == InputKeyLeft || input->key == InputKeyRight || input->key == InputKeyOk) {
  16. state->action = MINDCONTROL;
  17. }
  18. }
  19. // zoom poc for tests
  20. if(input->type == InputTypePress) {
  21. if(input->key == InputKeyDown) {
  22. state->zoom_v = SPEED_X;
  23. }
  24. } else if(input->type == InputTypeRelease) {
  25. if(input->key == InputKeyDown) {
  26. state->zoom_v = -SPEED_X * 2;
  27. state->dialog_progress = 0;
  28. }
  29. }
  30. // mind control
  31. if(state->action == MINDCONTROL) {
  32. if(input->type == InputTypePress) {
  33. if(input->key == InputKeyRight) {
  34. state->player_flipped = false;
  35. state->player_v.x = SPEED_X;
  36. } else if(input->key == InputKeyLeft) {
  37. state->player_flipped = true;
  38. state->player_v.x = -SPEED_X;
  39. }
  40. } else if(input->type == InputTypeRelease) {
  41. if(input->key == InputKeyRight || input->key == InputKeyLeft) {
  42. state->player_v.x = 0;
  43. }
  44. } else if(input->type == InputTypeShort) {
  45. if(input->key == InputKeyOk) {
  46. state->prev_action = MINDCONTROL;
  47. state->action = INTERACT;
  48. state->use_pending = true;
  49. state->action_timeout = 0;
  50. }
  51. }
  52. }
  53. }
  54. void dolphin_scene_coordinates(SceneState* state, uint32_t dt) {
  55. furi_assert(state);
  56. // global pos
  57. state->player_global.x = CLAMP(state->player_global.x + state->player_v.x, WORLD_WIDTH, 0);
  58. // zoom handlers
  59. state->scene_zoom = CLAMP(state->scene_zoom + state->zoom_v, SCENE_ZOOM, 0);
  60. state->player.x = CLAMP(state->player.x - (state->zoom_v * (SPEED_X * 2)), DOLPHIN_CENTER, 0);
  61. state->player.y = CLAMP(state->player.y - (state->zoom_v * SPEED_X / 2), DOLPHIN_DEFAULT_Y, 3);
  62. //center screen
  63. state->screen.x = state->player_global.x - state->player.x;
  64. state->player_anim = (state->player_global.x / 10) % 2;
  65. }