paper.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "paper.h"
  2. #include "paper_plane_icons.h"
  3. void update_sprite_rotation(Paper* dest) {
  4. switch(dest->rotation) {
  5. case -3:
  6. dest->icon = &I_PaperLeft3;
  7. break;
  8. case -2:
  9. dest->icon = &I_PaperLeft2;
  10. break;
  11. case -1:
  12. dest->icon = &I_PaperLeft1;
  13. break;
  14. case 0:
  15. dest->icon = &I_PaperDown;
  16. break;
  17. case 1:
  18. dest->icon = &I_PaperRight1;
  19. break;
  20. case 2:
  21. dest->icon = &I_PaperRight2;
  22. break;
  23. case 3:
  24. dest->icon = &I_PaperRight3;
  25. break;
  26. default:
  27. break;
  28. }
  29. }
  30. void rotate_left(Paper* dest) {
  31. if(dest->rotation > PAPER_MIN_ROTATION) dest->rotation--;
  32. update_sprite_rotation(dest);
  33. }
  34. void rotate_right(Paper* dest) {
  35. if(dest->rotation < PAPER_MAX_ROTATION) dest->rotation++;
  36. update_sprite_rotation(dest);
  37. }
  38. void paper_init(Paper* dest) {
  39. dest->x = PAPER_START_X;
  40. dest->rotation = 0;
  41. dest->y = 0;
  42. update_sprite_rotation(dest);
  43. }
  44. int get_gravity_from_rotation(int rotation) {
  45. return -abs(rotation) + BASE_GRAVITY;
  46. }
  47. void update_position(Paper* dest, int delta_time_ms) {
  48. dest->x += (float)dest->rotation * ROTATION_MULTIPLIER * delta_time_ms / 1000;
  49. dest->y += (float)get_gravity_from_rotation(dest->rotation) * delta_time_ms / 1000;
  50. }