#include #include #include #include #include "vector.h" #pragma once class Sprite { private: std::map frames; SDL_Surface* surface; SDL_Texture* Texture; int_vec2 size; public: SDL_Rect dstrect; int_vec2 scale = { 1, 1 }; double angle = 0; Sprite(SDL_Renderer* renderer, SDL_Surface* surface); void draw(SDL_Renderer* renderer, std::string frame, bool autoRect = true, bool flip = false); void addFrame(std::string name, SDL_Rect rect); void move(int_vec2 position); int_vec2 getSize(std::string frame); void autorect(std::string frame); ~Sprite(); }; class Animation { private: std::vector frames; Sprite* sprite; int currentFrame = 0; int frameDuration = 0; int frameCounter = 0; std::string currentFrameName; int frameIndex = 0; int frameDirection = 1; public: bool loop = true; bool pingpong = false; Animation(std::map frames, Sprite* sprite, int frameDuration); void update(); void draw(SDL_Renderer* renderer, bool autoRect = true, bool flip = false); }; class AnimationManager { private: std::map animations; std::map flip; std::map autoRect; std::string currentAnimation; Sprite* sprite; public: AnimationManager(Sprite* sprite); void addAnimation(std::string name, std::map animation, int frameDuration = 10, bool flip = false, bool autoRect = true, bool loop = true, bool pingpong = false); void setAnimation(std::string name); void update(); void draw(SDL_Renderer* renderer); };