Animator.h 703 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef INCLUDE_ANIMATOR_H
  2. #define INCLUDE_ANIMATOR_H
  3. #include <TINYSTL/vector.h>
  4. #include <TINYSTL/unordered_map.h>
  5. #include "Rect.h"
  6. namespace WalrusRPG
  7. {
  8. struct Frame
  9. {
  10. unsigned frame;
  11. unsigned duration; // 1f = 1s
  12. };
  13. struct Animation
  14. {
  15. tinystl::vector<WalrusRPG::Frame> stripe;
  16. bool looping;
  17. };
  18. class Animator
  19. {
  20. public:
  21. tinystl::unordered_map<unsigned, Animation> animations;
  22. protected:
  23. unsigned elapsed_time;
  24. public:
  25. Animator();
  26. void add_animation(int index, Animation anim);
  27. void update(unsigned dt);
  28. unsigned get_animation_frame(unsigned id);
  29. };
  30. }
  31. #endif