dd_animation.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef DD_ANIMATION_H
  2. #define DD_ANIMATION_H
  3. /* Used for creating animations
  4. * Counts from 0 to given value
  5. * Can check if animation is increasing or decreasing
  6. * `update()` moves animation until it ends (reach max or 0)
  7. returns true if updated, false otherwise
  8. * `interpolate()` takes a float (usually a distance)
  9. and calculates the interpolated value from 0 to that float
  10. */
  11. /* so far, 255 values were enough for an animation, I don't know
  12. * if I'll change it later on
  13. */
  14. typedef unsigned char anim_size;
  15. /* Animation struct */
  16. struct dd_animation {
  17. /* Counters */
  18. anim_size counter, max;
  19. /* Boolean */
  20. char positive;
  21. };
  22. /* initializes an animation struct */
  23. void dd_animation_init(struct dd_animation *a, anim_size max_value);
  24. /* updates animation */
  25. int dd_animation_update(struct dd_animation *a);
  26. /* Start animation
  27. * the `0` version starts from 0 and moves positively
  28. * the `max` version starts from max and moves negatively
  29. * flip just changes the direction of the update
  30. */
  31. void dd_animation_start0(struct dd_animation *a);
  32. void dd_animation_startmax(struct dd_animation *a);
  33. void dd_animation_flip(struct dd_animation *a);
  34. /* Get an interpolated value, from 0 to value
  35. * taken from animation's size
  36. */
  37. float dd_animation_interpolate(struct dd_animation *a, float value);
  38. /* issers */
  39. int dd_animation_isrunning(struct dd_animation *a);
  40. #endif