From b81993656adbb373fc82efff8d3b07a46f6c3c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Tue, 4 Sep 2018 16:08:14 +0200 Subject: [PATCH] Sort sprites --- game.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/game.cpp b/game.cpp index 17e51ba..2b35924 100644 --- a/game.cpp +++ b/game.cpp @@ -379,13 +379,15 @@ void drawSprite(const unsigned char *sprite, int16_t x, int16_t y, Unit depth, i { for (Unit i = max(-1 * x,0); i < iTo; ++i) { - if (!mask[i]) + int16_t xPos = x + i; + + if (!mask[xPos / SUBSAMPLE]) continue; c = sampleImage(sprite,(i * UNITS_PER_SQUARE) / size,(j * UNITS_PER_SQUARE) / size); if (c != 0xff) - p.display.drawPixel(x + i,y + j,c); + p.display.drawPixel(xPos,y + j,c); } } } @@ -528,6 +530,8 @@ void draw() render(player.mCamera,heightFunc,pixelFunc,c); + Unit previousDepth; + for (uint8_t i = 0; i < SPRITES; ++i) { PixelInfo pos = mapToScreen(sprites[i].mPosition,sprites[i].mHeight,player.mCamera); @@ -535,6 +539,15 @@ void draw() if (pos.depth > 0) drawSprite(sprite,pos.position.x * SUBSAMPLE,pos.position.y, pos.depth,perspectiveScale(32,pos.depth)); + + if (i != 0 && pos.depth > previousDepth) + { + Sprite tmp = sprites[i]; + sprites[i] = sprites[i - 1]; + sprites[i - 1] = tmp; + } + + previousDepth = pos.depth; } }