diff --git a/demo1.cpp b/demo1.cpp index 3ab4933..838bc77 100644 --- a/demo1.cpp +++ b/demo1.cpp @@ -988,6 +988,11 @@ RCL_Unit ceilingHeightAt(int16_t x, int16_t y) #undef withinMapReturn +inline int16_t distanceToIntensity(RCL_Unit distance) +{ + return 8 - distance / (RCL_UNITS_PER_SQUARE / 2); +} + /** Function for drawing a single pixel (like fragment shader). Bottleneck => should be as fast as possible. @@ -1001,7 +1006,7 @@ int16_t intensity; uint8_t color; - intensity = 8 - pixel->depth / (RCL_UNITS_PER_SQUARE / 2); + intensity = distanceToIntensity(pixel->depth); if (pixel->isWall) { @@ -1018,8 +1023,6 @@ int16_t intensity; } else { - intensity = 8 - pixel->depth / (RCL_UNITS_PER_SQUARE / 2); - color = pixel->isFloor ? addIntensity(40,intensity): addIntensity(18,intensity); @@ -1057,7 +1060,7 @@ void draw() drawSpriteSquare(image,pos.position.x * SUBSAMPLE, pos.position.y, pos.depth, - RCL_perspectiveScale(sprites[i].mPixelSize,pos.depth)); + RCL_perspectiveScale(sprites[i].mPixelSize,pos.depth),distanceToIntensity(pos.depth)); } /* trick: sort the sprites by distance with bubble sort as we draw - the diff --git a/demo2.cpp b/demo2.cpp index 60b90a0..21dcebc 100644 --- a/demo2.cpp +++ b/demo2.cpp @@ -1035,7 +1035,7 @@ void draw() drawSpriteSquare(spritePlasma,pos.position.x * SUBSAMPLE, pos.position.y,pos.depth, - RCL_perspectiveScale(64,pos.depth)); + RCL_perspectiveScale(64,pos.depth),1); } drawImage(imageBar,0,INFO_BAR_START - 3); diff --git a/general.hpp b/general.hpp index bb856cf..4d50de6 100644 --- a/general.hpp +++ b/general.hpp @@ -236,7 +236,7 @@ inline uint8_t sampleImage(const unsigned char *image, RCL_Unit x, RCL_Unit y) Draws a scaled sprite on screen in an optimized way. The sprite has to be square in resolution. */ -void inline drawSpriteSquare(const unsigned char *sprite, int16_t x, int16_t y, RCL_Unit depth, int16_t size) +void inline drawSpriteSquare(const unsigned char *sprite, int16_t x, int16_t y, RCL_Unit depth, int16_t size, int16_t intensity) { if (size < 0 || size > 200 || // let's not mess up with the incoming array sprite[0] != sprite[1]) // only draw square sprites @@ -271,7 +271,7 @@ void inline drawSpriteSquare(const unsigned char *sprite, int16_t x, int16_t y, c = sprite[columnLocation + samplingIndices[j]]; if (c != TRANSPARENT_COLOR) - pokitto.display.drawPixel(xPos,y + j,c); + pokitto.display.drawPixel(xPos,y + j,addIntensity(c,intensity)); } } }