Made some progress on the refactoring but I need to start getting serious and not reworking this code to death.
This commit is contained in:
parent
6ed57cd4a8
commit
51c1e04f61
5 changed files with 46 additions and 33 deletions
37
texture.cpp
37
texture.cpp
|
@ -5,6 +5,8 @@
|
|||
#include "config.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
using std::shared_ptr, std::make_shared;
|
||||
|
||||
sf::Image TexturePack::load_image(std::string filename) {
|
||||
sf::Image texture;
|
||||
bool good = texture.loadFromFile(filename);
|
||||
|
@ -12,6 +14,27 @@ sf::Image TexturePack::load_image(std::string filename) {
|
|||
return texture;
|
||||
}
|
||||
|
||||
void TexturePack::load_sprites() {
|
||||
Config assets("assets/config.json");
|
||||
|
||||
for(auto& el : assets["sprites"].items()) {
|
||||
string path = el.value();
|
||||
auto texture = make_shared<sf::Texture>(path);
|
||||
|
||||
texture->setSmooth(false);
|
||||
auto sprite = make_shared<sf::Sprite>(*texture);
|
||||
|
||||
string name = el.key();
|
||||
sprite_textures[name] = {sprite, texture};
|
||||
}
|
||||
|
||||
sword = sprite_textures["sword"];
|
||||
}
|
||||
|
||||
void TexturePack::position_sprite(double x, double y, string name) {
|
||||
sprites.emplace_back(x, y, sprite_textures[name]);
|
||||
}
|
||||
|
||||
void TexturePack::load_textures() {
|
||||
Config assets("assets/config.json");
|
||||
|
||||
|
@ -19,22 +42,8 @@ void TexturePack::load_textures() {
|
|||
images.emplace_back(load_image(tile_path));
|
||||
}
|
||||
|
||||
for(string tile_path : assets["sprites"]) {
|
||||
images.emplace_back(load_image(tile_path));
|
||||
}
|
||||
|
||||
floor = load_image(assets["sprites"]["floor"]);
|
||||
ceiling = load_image(assets["sprites"]["ceiling"]);
|
||||
|
||||
sf::Texture* sprite_texture = new sf::Texture(assets["sprites"]["evil_eye"]);
|
||||
sprite_texture->setSmooth(false);
|
||||
sf::Sprite* sf_sprite = new sf::Sprite(*sprite_texture);
|
||||
|
||||
sprites.push_back({4.0, 3.55, 6, sf_sprite, sprite_texture});
|
||||
|
||||
sword.sprite_texture = new sf::Texture("assets/cinqueda_1-512.png");
|
||||
sword.sprite_texture->setSmooth(false);
|
||||
sword.sprite = new sf::Sprite(*sword.sprite_texture);
|
||||
}
|
||||
|
||||
const uint32_t* TexturePack::get_texture(size_t num) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue