diff options
Diffstat (limited to 'src/render.cpp')
-rw-r--r-- | src/render.cpp | 96 |
1 files changed, 72 insertions, 24 deletions
diff --git a/src/render.cpp b/src/render.cpp index 907dcf0..819641f 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -1,43 +1,50 @@ #include "common.hpp" #include <list> +#include <sstream> static sf::RectangleShape wot_rect; static sf::Font font; static void draw_tile(sf::RenderWindow *window, v2f_t x, world::tile_t *tile) { - sf::Color color; - - wot_rect.setTexture(NULL); - wot_rect.setSize(sf::Vector2f(1.0f, 1.0f)); - wot_rect.setPosition(x); + render::tile_t *tile_assets; + sf::Texture *texture; + bool mirror; switch (tile->type) { - case -1: - color = sf::Color(30, 30, 150); - break; - case 0: - color = sf::Color(50, 70, 200); - break; - case 1: - color = sf::Color(255, 255, 90); - break; - case 2: - color = sf::Color(30, 210, 40); - break; - case 3: - color = sf::Color(29, 190, 45); + default: + return; + + case world::TILE_DIRT: + tile_assets = &assets::tile_dirt; break; - case 4: - color = sf::Color(120, 120, 120); + + case world::TILE_WALL: + tile_assets = &assets::tile_wall; break; - default: - ; } - wot_rect.setFillColor(color); + texture = tile_assets->get_texture(tile->neighbors, &mirror); + + wot_rect.setTexture(texture); + wot_rect.setSize(sf::Vector2f(1.0f, 1.0f)); + if (!mirror) { + wot_rect.setPosition(x); + wot_rect.setScale(v2f_t(1, 1)); + } else { + wot_rect.setPosition(x + v2f_t(1.0f, 0)); + wot_rect.setScale(v2f_t(-1, 1)); + } + wot_rect.setFillColor(sf::Color::White); wot_rect.setOutlineColor(sf::Color::Transparent); window->draw(wot_rect); + + std::stringstream ss; + ss << tile->type << ":" << tile->neighbors; + sf::Text text(ss.str(), font, 20); + text.setPosition(x); + text.setScale(0.005, 0.005); + window->draw(text); } static void draw_sector(sf::RenderWindow *window, world::sector_t *sector) @@ -267,4 +274,45 @@ void oriented_sprite_4M2_t::load(std::string prefix, size_t xc, size_t yc) textures[1].load(prefix + "_y_", yc); } +void tile_monotonic_t::load(std::string prefix) +{ + texture.loadFromFile(prefix + ".png"); +} + +void tile_connecting12_t::load(std::string prefix) +{ + for (size_t i = 0; i < 12; i++) + textures[i].loadFromFile(prefix + "_" + std::to_string(i) + ".png"); +} + +sf::Texture *tile_monotonic_t::get_texture(int neighbors, bool *mirror) +{ + *mirror = false; + return &texture; +} + +sf::Texture *tile_connecting12_t::get_texture(int neighbors, bool *mirror) +{ + const static struct{ size_t index; bool mirror; } map[16] = { + {0, false}, + {1, false}, + {2, false}, + {3, false}, + {1, true}, + {4, false}, + {3, true}, + {5, false}, + {6, false}, + {7, false}, + {8, false}, + {9, false}, + {7, true}, + {10, false}, + {9, true} + }; + + *mirror = map[neighbors].mirror; + return textures + map[neighbors].index; +} + } // namespace render |