-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sprite.h
46 lines (34 loc) · 1.38 KB
/
Sprite.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef MAIN_SPRITE_H
#define MAIN_SPRITE_H
#include <string>
#include <vector>
#include "General.h"
#include "Image.h"
struct SpritePixSz
{
int width;
SpritePixSz(int w) : width(w) {}
};
struct Sprite
{
Sprite() {};
Sprite(const std::string &path, int p_frames, int ms_on_frame = 125, int scale = 1, bool _loop = true);
Sprite(const std::string &path, SpritePixSz frame_sz, int ms_on_frame = 125, int scale = 1, bool _loop = true);
Sprite(Image &img, SpritePixSz frame_sz, int ms_on_frame = 125, int scale = 1, bool _loop = true);
void Draw(Image &canvas, const Point p, bool flip_OX = false, bool flip_OY = false);
void Draw(Image &canvas, const Point p, double time_start, bool flip_OX = false, bool flip_OY = false);
void Restart() { time_start_prev_frame = GameTime::Now().GetTime(); frame_now = 0; }
double AnimTime() const { return s_per_frame * frames; }
int Width()const { return frames == 0 ? frames : imgs[frame_now].Width(); }
int Height()const { return frames == 0 ? frames : imgs[frame_now].Height(); }
const Image &GetFrame(int frame) const { return imgs.at(frame); }
private:
void SpriteFromImg(Image &img, int p_frames, int ms_on_frame = 125, int scale = 1);
int frames = 0;
int frame_now = 0;
double s_per_frame = 0.075;
double time_start_prev_frame = -1;
std::vector<Image> imgs;
bool loop = true;
};
#endif