diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-10-10 19:33:33 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-10-10 19:33:33 +0200 |
commit | 753f71536339b78c49468ba6452c96d6b3c345b2 (patch) | |
tree | 0f3edbef6b2a34a738dc37cc8dd8c11a98e54c85 /src/render.cpp | |
parent | ff4929c650e6ed446b6faff9f6b0f078d0a3644c (diff) |
Finish work on world entities, start experimenting with world generation.
Diffstat (limited to 'src/render.cpp')
-rw-r--r-- | src/render.cpp | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/src/render.cpp b/src/render.cpp index d63ca6f..1baf0e0 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -6,9 +6,32 @@ static sf::RectangleShape wot_rect; static void draw_tile(sf::RenderWindow *window, float x, float y, world::tile_t *tile) { + sf::Color color; + wot_rect.setSize(sf::Vector2f(1.0f, 1.0f)); wot_rect.setPosition(sf::Vector2f(x, y)); - wot_rect.setFillColor(sf::Color(tile->type, tile->type, tile->type)); + + 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); + break; + default: + ; + } + + wot_rect.setFillColor(color); wot_rect.setOutlineColor(sf::Color::Transparent); window->draw(wot_rect); } @@ -21,18 +44,12 @@ static void draw_sector(sf::RenderWindow *window, world::sector_t *sector) sector->bounds.left + x, sector->bounds.top + y, sector->tiles + y * SECTOR_SIZE + x); - wot_rect.setSize(sf::Vector2f(SECTOR_SIZE, SECTOR_SIZE)); - wot_rect.setPosition(sf::Vector2f(sector->bounds.left, sector->bounds.top)); - wot_rect.setOutlineColor(sf::Color::Yellow); - wot_rect.setOutlineThickness(0.06f); - wot_rect.setFillColor(sf::Color::Transparent); - window->draw(wot_rect); -} - -static void draw_sector_entities(sf::RenderWindow *window, world::sector_t *sector) -{ - for (world::entity_t *ent : sector->ents) - ent->render(window); + if ((sector->index.x & 2) ^ (sector->index.y & 2)) { + wot_rect.setSize(sf::Vector2f(SECTOR_SIZE, SECTOR_SIZE)); + wot_rect.setPosition(sf::Vector2f(sector->bounds.left, sector->bounds.top)); + wot_rect.setFillColor(sf::Color(0, 0, 0, 50)); + window->draw(wot_rect); + } } void game::state_t::render(sf::RenderWindow *window) @@ -40,8 +57,6 @@ void game::state_t::render(sf::RenderWindow *window) sf::Vector2u size = window->getSize(); sf::Vector2f A, B, C, D; sf::Rect<float> bbox; - sf::Rect<ssize_t> index_box; - std::list<world::sector_t*> sectors; A = window->mapPixelToCoords(sf::Vector2i(0, 0)); B = window->mapPixelToCoords(sf::Vector2i(size.x, 0)); @@ -50,28 +65,14 @@ void game::state_t::render(sf::RenderWindow *window) bbox.left = std::min({A.x, B.x, C.x, D.x}); bbox.top = std::min({A.y, B.y, C.y, D.y}); - bbox.width = std::max({A.x, B.x, C.x, D.x}); - bbox.height = std::max({A.y, B.y, C.y, D.y}); - - index_box.left = floor(bbox.left / SECTOR_SIZE); - index_box.top = floor(bbox.top / SECTOR_SIZE); - index_box.width = ceil(bbox.width / SECTOR_SIZE); - index_box.height = ceil(bbox.height / SECTOR_SIZE); - - for (ssize_t y = index_box.top; y < index_box.height; y++) - for (ssize_t x = index_box.left; x < index_box.width; x++) { - world::sector_index_t index(x, y); - world::sector_t *sector; + bbox.width = std::max({A.x, B.x, C.x, D.x}) - bbox.left; + bbox.height = std::max({A.y, B.y, C.y, D.y}) - bbox.top; - sector = world.get_sector(index); - sectors.push_back(sector); - } - - for (auto *sector : sectors) + for (world::sector_t *sector : world.get_sectors(bbox)) draw_sector(window, sector); - for (auto *sector : sectors) - draw_sector_entities(window, sector); + for (world::entity_t *ent : world.get_entities(bbox)) + ent->render(window); } void game::human_t::render(sf::RenderWindow *window) |