-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprite.h
More file actions
50 lines (41 loc) · 918 Bytes
/
Sprite.h
File metadata and controls
50 lines (41 loc) · 918 Bytes
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
47
48
49
50
#include <map>
#include <vector>
class Sprite {
//stateless
SDL_Surface* image;
int getWidth();
int getHeight();
void draw(SDL_Surface* screen, int x, int y);
Sprite(std::string filename);
};
Sprite::Sprite(std::string filename) {
image = (SDL_Surface*)malloc(sizeof(SDL_Surface));
image = loadOptimizedSurface(filename.c_str());
}
int Sprite::getWidth() {
return image->w;
}
int Sprite::getHeight() {
return image->h;
}
void Sprite::draw(SDL_Surface* screen, int x, int y) {
applySurface(image, screen, x, y);
}
class SpriteStore {
private:
static SpriteStore single;
map<std::string, Sprite*> spriteMap;
public:
static SpriteStore get();
Sprite getSprite(std::string);
};
SpriteStore SpriteStore::get() {
return single;
}
Sprite SpriteStore::getSprite(std::string key) {
std::map<std::string,Sprite*>::iterator itr;
itr = spriteMap.find(key);
if(itr == spriteMap.end()) {
//
}
}