spacebox/src/Sprite.hpp

170 lines
5.1 KiB
C++

#ifndef Sprite_h_
#define Sprite_h_
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <utility>
#include <SDL.h>
#include <SDL_image.h>
#include "Node.hpp"
#include "Box.hpp"
#include "Animation.hpp"
#include "Color.hpp"
struct Game;
struct Frameset;
struct Sprite : Node
{
std::vector<SDL_Texture*> frames;
std::vector<fs::path> frame_paths;
std::vector<Box> boxes = {{{0, 0}, {0, 0}}};
Animation frame_animation = Animation(&Sprite::advance_frame, this),
blink_animation = Animation(&Sprite::toggle_hidden, this, 500),
wipe_animation = Animation(&Sprite::wipe, this, 40);
bool hidden = false;
glm::vec2 step = {0, 0};
float scale = 1;
std::string scale_quality = "nearest";
std::uint8_t alpha_mod = 255;
SDL_Color color_mod = {255, 255, 255, 255};
std::map<std::string, Frameset> framesets;
std::string current_frameset_name;
glm::bvec2 wrap = {false, false};
int texture_access = SDL_TEXTUREACCESS_TARGET;
int wipe_index = 0;
Box wrap_frame, subsection_destination;
bool leave_memory_allocated = false;
std::vector<std::vector<Box>> wipe_blinds;
SDL_Rect subsection;
Sprite();
Sprite(Node*);
Sprite(Node*, std::string);
virtual void reset();
virtual void associate(std::string);
virtual void load();
void load_file(fs::path);
void add_frames(SDL_Texture*);
void add_frames(const std::vector<SDL_Texture*>&);
const std::vector<SDL_Texture*>& get_frames() const;
Frameset& get_all_frames_frameset();
Frameset& add_frameset(std::string);
Frameset& set_frameset(std::string);
Frameset& get_current_frameset();
void set_frame_length(float);
const Frameset& get_current_frameset() const;
SDL_Texture* get_current_frame() const;
const Box& get_box(int = 0) const;
const std::vector<Box>& get_boxes() const;
void add_box(glm::vec2, bool = false);
void update_size(bool = false);
void set_scale(float);
void set_scale_quality(const std::string&);
float get_scale() const;
bool is_loaded() const;
virtual void unload();
void advance_frame();
void hide();
void unhide();
void toggle_hidden();
bool is_hidden() const;
void set_step(glm::vec2);
void set_alpha_mod(Uint8);
Uint8 get_alpha_mod() const;
void set_color_mod(const SDL_Color&);
const SDL_Color& get_color_mod() const;
float get_w();
float get_h();
glm::vec2 get_size();
float get_top(int = 0);
float get_right(int = 0);
float get_bottom(int = 0);
float get_left(int = 0);
float get_center_x(int = 0);
float get_center_y(int = 0);
glm::vec2 get_nw(int = 0);
glm::vec2 get_north(int = 0);
glm::vec2 get_ne(int = 0);
glm::vec2 get_east(int = 0);
glm::vec2 get_se(int = 0);
glm::vec2 get_south(int = 0);
glm::vec2 get_sw(int = 0);
glm::vec2 get_west(int = 0);
glm::vec2 get_center(int = 0);
void set_top(float);
void set_right(float);
void set_bottom(float);
void set_left(float);
void set_center_x(float);
void set_center_y(float);
void set_nw(const glm::vec2&);
void set_ne(const glm::vec2&);
void set_se(const glm::vec2&);
void set_south(const glm::vec2&);
void set_sw(const glm::vec2&);
void set_west(const glm::vec2&);
void set_center(const glm::vec2&);
void add_wrap(bool, bool);
void add_wrap(bool, bool, Box);
void add_hue_shift_frames(int);
virtual glm::vec2 move(const glm::vec2&);
virtual glm::vec2 move_weighted(const glm::vec2&);
bool collide(const glm::vec2&, bool = false) const;
bool collide(const Segment&, glm::vec2* = NULL, bool = false) const;
bool collide(const Segment&, glm::vec2&, bool = false) const;
bool collide(const Box&, bool = false, Box* = NULL, bool = false, SDL_Texture* = NULL) const;
bool collide(const Box&, Box&, bool = false, bool = false) const;
bool collide(const Sprite&, bool = false, Box* = NULL, bool = false, bool = false) const;
bool collide(const Sprite&, Box&, bool = false, bool = false, bool = false) const;
void wipe();
const std::vector<Box>& get_current_wipe_blinds();
virtual void update();
void set_to_leave_memory_allocated();
void set_to_deallocate_memory();
virtual std::string get_class_name() { return "Sprite"; }
~Sprite() { unload(); }
};
struct Frameset
{
Sprite* sprite;
std::vector<int> order;
int order_index = 0;
float frame_length = 0;
bool reversed = false;
glm::vec2 size = {0, 0};
Frameset();
Frameset(Sprite*);
void add_frame_index(int);
void add_frame_indicies(const std::vector<int>&);
void set_frame_length(float);
float get_frame_length() const;
void reset();
void clear();
int get_order_index() const;
void set_order_index(int);
int get_current_frame_index() const;
glm::vec2 measure() const;
void set_size();
void set_size(const glm::vec2&);
const glm::vec2& get_size() const;
void step();
void increment_index();
void increment_index(int);
int get_frame_count() const;
void reverse();
};
#endif