summaryrefslogtreecommitdiff
path: root/src/level.cpp
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2022-03-29 16:29:56 -0600
committercflip <cflip@cflip.net>2022-03-29 16:29:56 -0600
commit2b35b393203403704b740f7627af701968c2dfcc (patch)
tree12647094e966bbab9f48a9c8c586380ca8b7dfa0 /src/level.cpp
parent94212b5fda87b6983465103d6f35253c874a2915 (diff)
Fix sprite sorting when rendering the level
This fixes a misuse of std::find_if and vector iterators. Previously, the first vehicle in the currently drawing tile would be drawn, and then every other vehicle would be drawn regardless of position.
Diffstat (limited to 'src/level.cpp')
-rw-r--r--src/level.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/level.cpp b/src/level.cpp
index e88191a..e09f74a 100644
--- a/src/level.cpp
+++ b/src/level.cpp
@@ -76,13 +76,14 @@ void Level::draw(Bitmap& bitmap, int xo, int yo)
for (int y = 0; y < m_height; ++y) {
for (int x = 0; x < m_width; ++x) {
- auto vehiclesInTile = std::find_if(m_vehicles.begin(), m_vehicles.end(), [x, y](const auto& vehicle) {
+ auto isInTile = [x, y](const auto& vehicle) {
return vehicle.getSpritePosition().x == x && vehicle.getSpritePosition().y == y;
- });
+ };
+ auto vehiclesInTile = std::find_if(m_vehicles.begin(), m_vehicles.end(), isInTile);
while (vehiclesInTile != m_vehicles.end()) {
vehiclesInTile->draw(bitmap, xo, yo);
- ++vehiclesInTile;
+ vehiclesInTile = std::find_if(++vehiclesInTile, m_vehicles.end(), isInTile);
}
auto tile = get(x, y);