From e4ca910e7731e2a12815a4a8de2582157f519898 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sat, 14 Oct 2017 15:54:01 +0200 Subject: Correct entity drawing order. --- src/render.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/render.cpp') 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 bbox; + std::list 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); } -- cgit