Amit's code mostly converted to use the new texture.hpp but there's an error on line amt/pixel.hpp:472
parent
c91e8fc543
commit
4d31a4daf2
@ -0,0 +1,34 @@ |
||||
#include <SFML/Graphics/Image.hpp> |
||||
#include "dbc.hpp" |
||||
#include <fmt/core.h> |
||||
#include "config.hpp" |
||||
#include "amt/texture.hpp" |
||||
|
||||
Image TexturePack::load_image(std::string filename) { |
||||
sf::Image img; |
||||
bool good = img.loadFromFile(filename); |
||||
dbc::check(good, format("failed to load {}", filename)); |
||||
return amt::PixelBuf(img.getPixelsPtr(), TEXTURE_HEIGHT, TEXTURE_WIDTH); |
||||
} |
||||
|
||||
void TexturePack::load_textures() { |
||||
Config assets("assets/config.json"); |
||||
for(string tile_path : assets["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["floor"]); |
||||
ceiling = load_image(assets["ceiling"]); |
||||
} |
||||
|
||||
Image& TexturePack::get_texture(size_t num) { |
||||
return images[num]; |
||||
} |
||||
|
||||
Sprite &TexturePack::get_sprite(size_t sprite_num) { |
||||
return sprites[sprite_num]; |
||||
} |
@ -0,0 +1,34 @@ |
||||
#pragma once |
||||
|
||||
#include <cstdint> |
||||
#include <vector> |
||||
#include <string> |
||||
#include "amt/pixel.hpp" |
||||
|
||||
struct Sprite { |
||||
double x; |
||||
double y; |
||||
int texture; |
||||
// ZED: this should be a separate transform parameter
|
||||
double elevation=0; |
||||
int uDiv=1; |
||||
int vDiv=1; |
||||
}; |
||||
|
||||
using Image = amt::PixelBuf; |
||||
|
||||
struct TexturePack { |
||||
int NUM_SPRITES=1; |
||||
static const int TEXTURE_WIDTH=256; // must be power of two
|
||||
static const int TEXTURE_HEIGHT=256; // must be power of two
|
||||
|
||||
std::vector<amt::PixelBuf> images; |
||||
std::vector<Sprite> sprites{{4.0, 3.55, 6}}; |
||||
Image floor; |
||||
Image ceiling; |
||||
|
||||
void load_textures(); |
||||
amt::PixelBuf load_image(std::string filename); |
||||
Sprite& get_sprite(size_t sprite_num); |
||||
Image& get_texture(size_t num); |
||||
}; |
Loading…
Reference in new issue