summaryrefslogtreecommitdiff
path: root/src/train.cpp
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2022-03-26 11:50:51 -0600
committercflip <cflip@cflip.net>2022-03-26 11:50:51 -0600
commit8e2fd5758b00036da965effbefdc76c1d373cd23 (patch)
tree3fe911af9e4ef648de856c3942b8fd6ba3cd91ff /src/train.cpp
parent42397536e79fdf68fb194de86bbeb3f1ed098eed (diff)
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.
Diffstat (limited to 'src/train.cpp')
-rw-r--r--src/train.cpp7
1 files changed, 7 insertions, 0 deletions
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) {