spacebox/src/Sprite.hpp

48 lines
999 B
C++

#ifndef Sprite_h_
#define Sprite_h_
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <SDL.h>
#include <SDL_image.h>
#include "Node.hpp"
#include "Game.hpp"
#include "Location.hpp"
#include "Animation.hpp"
struct Sprite : Node
{
std::vector<SDL_Texture*> frames;
std::vector<fs::path> frame_paths;
int frame_ii = 0;
Location location;
Animation animation = Animation(&Sprite::advance_frame, this);
Sprite(Node*);
Sprite(Node*, std::string);
void set_frame_length(float);
void associate(std::string);
void load();
void load_file(fs::path);
void add_frame(SDL_Texture*);
void unload();
void advance_frame();
void update();
std::string get_class_name() { return "Sprite"; }
template<typename T1, typename T2 = int>
void move(T1 dx, T2 dy = 0)
{
Game *game = get_root();
location.move_ip(game->get_weighted_amount(dx), game->get_weighted_amount(dy));
}
};
#endif