diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-10-14 15:54:01 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-10-14 15:54:01 +0200 |
commit | e4ca910e7731e2a12815a4a8de2582157f519898 (patch) | |
tree | 7bd9e2109bc39e26ea0f790c19b960cce5bd2246 /src/render.cpp | |
parent | bb0a7bfe31714ff56ce1c1ce428cdf240804db14 (diff) |
Correct entity drawing order.
Diffstat (limited to 'src/render.cpp')
-rw-r--r-- | src/render.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/render.cpp b/src/render.cpp index f56cb37..ce9b837 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -79,6 +79,7 @@ void state_t::render(game::state_t *game) sf::Vector2u size = window->getSize(); sf::Vector2f A, B, C, D; sf::Rect<float> bbox; + std::list<world::entity_t*> ents; A = window->mapPixelToCoords(sf::Vector2i(0, 0)); B = window->mapPixelToCoords(sf::Vector2i(size.x, 0)); @@ -93,7 +94,15 @@ void state_t::render(game::state_t *game) for (world::sector_t *sector : game->world.get_sectors(bbox)) draw_sector(window, sector); - for (world::entity_t *ent : game->world.get_entities(bbox)) + ents = game->world.get_entities(bbox); + ents.sort( + [](const world::entity_t *x, const world::entity_t *y) -> bool + { + return x->bounds.top + x->bounds.height + < y->bounds.top + y->bounds.height; + }); + + for (world::entity_t *ent : ents) ent->render_to(this); } |