From 8e2fd5758b00036da965effbefdc76c1d373cd23 Mon Sep 17 00:00:00 2001 From: cflip Date: Sat, 26 Mar 2022 11:50:51 -0600 Subject: Implement sprite depth sorting This algorithm draws the level in two passes; the ground and rail tiles are drawn first, then the train cars and walls. This method isn't perfect, but it'll do for now. --- src/train.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/train.cpp') diff --git a/src/train.cpp b/src/train.cpp index cfbae97..080a357 100644 --- a/src/train.cpp +++ b/src/train.cpp @@ -57,6 +57,13 @@ void Train::setPosition(int tx, int ty) findNextTile(); } +Point2D Train::getSpritePosition() const +{ + int xi = ceil((float)x + (float)(m_nextX - x) * m_progress); + int yi = ceil((float)y + (float)(m_nextY - y) * m_progress); + return { xi, yi }; +} + void Train::addVehicle(Train* newTrain) { if (!m_prev) { -- cgit v1.2.3