Sort sprites

This commit is contained in:
Miloslav Číž 2018-09-04 16:08:14 +02:00
parent 86d2334a52
commit b81993656a

View file

@ -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) for (Unit i = max(-1 * x,0); i < iTo; ++i)
{ {
if (!mask[i]) int16_t xPos = x + i;
if (!mask[xPos / SUBSAMPLE])
continue; continue;
c = sampleImage(sprite,(i * UNITS_PER_SQUARE) / size,(j * UNITS_PER_SQUARE) / size); c = sampleImage(sprite,(i * UNITS_PER_SQUARE) / size,(j * UNITS_PER_SQUARE) / size);
if (c != 0xff) 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); render(player.mCamera,heightFunc,pixelFunc,c);
Unit previousDepth;
for (uint8_t i = 0; i < SPRITES; ++i) for (uint8_t i = 0; i < SPRITES; ++i)
{ {
PixelInfo pos = mapToScreen(sprites[i].mPosition,sprites[i].mHeight,player.mCamera); PixelInfo pos = mapToScreen(sprites[i].mPosition,sprites[i].mHeight,player.mCamera);
@ -535,6 +539,15 @@ void draw()
if (pos.depth > 0) if (pos.depth > 0)
drawSprite(sprite,pos.position.x * SUBSAMPLE,pos.position.y, drawSprite(sprite,pos.position.x * SUBSAMPLE,pos.position.y,
pos.depth,perspectiveScale(32,pos.depth)); 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;
} }
} }