-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtextures.cpp
50 lines (45 loc) · 1.45 KB
/
textures.cpp
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 "textures.hpp"
#include <iostream>
const char* getTextureFilename(GameTextureID id) {
switch (id) {
case GameTextureID::SPACE:
return "resources/space.png";
case GameTextureID::PLANET:
return "resources/planet.png";
case GameTextureID::PLANET_DEAD:
return "resources/planetDead.png";
case GameTextureID::STAR:
return "resources/star.png";
case GameTextureID::STAR_CONCERNED:
return "resources/starConcerned.png";
case GameTextureID::BLACKHOLE:
return "resources/blackhole.png";
default:
return "";
}
}
bool TextureManager::initialize() {
for (size_t i = 0; i < SIZE; ++i) {
GameTextureID id = static_cast<GameTextureID>(i);
const char* filename = getTextureFilename(id);
sf::Texture* texture = &textures[i];
if (!texture->loadFromFile(filename)) {
std::cerr << "Could not open file " << filename << "\n";
return false;
}
if (id == GameTextureID::SPACE) {
texture->setRepeated(true);
}
}
return true;
}
const sf::Texture* TextureManager::getTexture(GameTextureID id) const {
return &textures[static_cast<size_t>(id)];
}
sf::Font TextureManager::getFont() {
sf::Font font;
if (!font.loadFromFile("resources/JetBrainsMono-Light.ttf")) {
std::cerr << "Could not load font\n";
}
return font;
}