-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSprites.h
47 lines (40 loc) · 982 Bytes
/
Sprites.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
47
#pragma once
#include "lib/leetlib.h"
struct Sprite
{
void* texture = nullptr;
Sprite() {}
Sprite(void* texture_) : texture(texture_) {}
operator void* () const { return texture; }
};
class Sprites
{
public:
const Sprite Enemy = LoadSprite("gfx/Little Invader.png");
const Sprite Player = LoadSprite("gfx/Big Invader.png");
const Sprite Bullet = LoadSprite("gfx/bullet.png");
std::map<char, Sprite> Glyphs;
static Sprite LoadGlyph(char glyph)
{
using namespace std::string_literals;
std::string path = "gfx/";
if (glyph >= 'a' && glyph <= 'z')
path += glyph + "let.png"s;
else if (glyph >= '0' && glyph <= '9')
path += "num"s + glyph + ".png"s;
else
throw std::exception("Non-existent glyph requested");
return LoadSprite(path.c_str());
}
Sprites()
{
for (char c = 'a'; c <= 'z'; ++c) {
Glyphs[c] = LoadGlyph(c);
}
for (char c = '0'; c <= '9'; ++c) {
Glyphs[c] = LoadGlyph(c);
}
Glyphs[' '] = {};
}
};
Sprites& GetSprites();