From be9ccb73bc20b03f62c77f5d529602a10ef4eda9 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 12 Mar 2022 12:09:58 -0500 Subject: player has a sprite now thanks to world of solaria --- src/animation.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/animation.h (limited to 'src/animation.h') diff --git a/src/animation.h b/src/animation.h new file mode 100644 index 0000000..0108c12 --- /dev/null +++ b/src/animation.h @@ -0,0 +1,39 @@ +#ifndef ANIMATION_H_332518EB +#define ANIMATION_H_332518EB + +#include +#include +#include +#include +#include +#include "direction.h" +#include "timer.h" + +class Animation { +public: + explicit Animation(std::string_view path); + + void setDirection(Direction dir); + void setAnimation(std::string_view anim); + + const SDL_Rect& getRenderRect() const { + return frames_.at(animations_.at(animationId_).at(animationFrame_)); + } + + void update(int dt); + +private: + + void updateAnim(); + + std::vector frames_; + std::vector> animations_; + std::map> nameDirToAnim_; + Direction dir_ = Direction::down; + std::string animationName_ = "still"; + int animationId_ = 0; + int animationFrame_ = 0; + Timer animTimer_ = {1000/5}; +}; + +#endif /* end of include guard: ANIMATION_H_332518EB */ -- cgit 1.4.1