Tiles now record their textures and this is loaded from the map then converted to an indexed integer on the fly.
This commit is contained in:
parent
9e3e347e4a
commit
a67d25ee10
10 changed files with 64 additions and 66 deletions
33
texture.cpp
33
texture.cpp
|
@ -29,21 +29,29 @@ void TexturePack::load_sprites() {
|
|||
}
|
||||
|
||||
sword = sprite_textures["sword"];
|
||||
|
||||
floor = load_image(assets["sprites"]["floor"]);
|
||||
ceiling = load_image(assets["sprites"]["ceiling"]);
|
||||
}
|
||||
|
||||
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");
|
||||
void TexturePack::load_tiles() {
|
||||
Config assets("assets/tiles.json");
|
||||
auto &tiles = assets.json();
|
||||
|
||||
for(string tile_path : assets["textures"]) {
|
||||
surfaces.emplace_back(load_image(tile_path));
|
||||
for(auto &el : tiles.items()) {
|
||||
auto &config = el.value();
|
||||
surfaces.emplace_back(load_image(config["texture"]));
|
||||
|
||||
std::wstring display = assets.wstring(el.key(), "display");
|
||||
int surface_i = surfaces.size() - 1;
|
||||
wchar_t tid = display[0];
|
||||
|
||||
char_to_texture[tid] = surface_i;
|
||||
}
|
||||
|
||||
floor = load_image(assets["sprites"]["floor"]);
|
||||
ceiling = load_image(assets["sprites"]["ceiling"]);
|
||||
}
|
||||
|
||||
const uint32_t* TexturePack::get_surface(size_t num) {
|
||||
|
@ -53,3 +61,14 @@ const uint32_t* TexturePack::get_surface(size_t num) {
|
|||
Sprite &TexturePack::get_sprite(size_t sprite_num) {
|
||||
return sprites[sprite_num];
|
||||
}
|
||||
|
||||
matrix::Matrix TexturePack::convert_char_to_texture(matrix::Matrix &tile_ids) {
|
||||
auto result = matrix::make(matrix::width(tile_ids), matrix::height(tile_ids));
|
||||
|
||||
for(matrix::each_cell it(tile_ids); it.next();) {
|
||||
wchar_t tid = tile_ids[it.y][it.x];
|
||||
result[it.y][it.x] = char_to_texture.at(tid);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue