scene_controls.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. state->last_group = state->frame_group;
  8. if(input->type == InputTypePress) {
  9. state->action = MINDCONTROL;
  10. }
  11. if(state->action == MINDCONTROL) {
  12. if(input->type == InputTypePress) {
  13. if(input->key == InputKeyRight) {
  14. state->player_v.y = 0;
  15. state->player_v.x = SPEED_X;
  16. } else if(input->key == InputKeyLeft) {
  17. state->player_v.y = 0;
  18. state->player_v.x = -SPEED_X;
  19. } else if(input->key == InputKeyUp) {
  20. state->player_v.x = 0;
  21. state->player_v.y = -SPEED_Y;
  22. } else if(input->key == InputKeyDown) {
  23. state->player_v.x = 0;
  24. state->player_v.y = SPEED_Y;
  25. }
  26. }
  27. if(input->type == InputTypeRelease) {
  28. state->player_v.x = 0;
  29. state->player_v.y = 0;
  30. } else if(input->type == InputTypeShort) {
  31. if(input->key == InputKeyOk) {
  32. state->prev_action = MINDCONTROL;
  33. state->action = INTERACT;
  34. state->use_pending = true;
  35. state->action_timeout = 0;
  36. }
  37. }
  38. }
  39. }
  40. void dolphin_scene_coordinates(SceneState* state, uint32_t dt) {
  41. furi_assert(state);
  42. // global pos
  43. state->player_global.x = CLAMP(state->player_global.x + state->player_v.x, WORLD_WIDTH, 0);
  44. state->player_global.y = CLAMP(state->player_global.y + state->player_v.y, WORLD_HEIGHT, 0);
  45. // nudge camera postition
  46. if(state->player_global.x > 170) {
  47. state->player.x =
  48. CLAMP(state->player.x - state->player_v.x / 2, DOLPHIN_CENTER, -DOLPHIN_WIDTH / 2);
  49. } else if(state->player_global.x < 70) {
  50. state->player.x =
  51. CLAMP(state->player.x - state->player_v.x / 2, DOLPHIN_WIDTH * 2, DOLPHIN_CENTER);
  52. }
  53. }