From 5e94c9fb603dc4648fe6ab4c153ba4114b6bb486 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 5 Jun 2018 19:01:26 -0400 Subject: improved overlapping lights radius of light seems kind of diminished though. --- src/main.cpp | 63 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dacc646..03e7cda 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -199,7 +199,8 @@ void render( } SDL_SetRenderTarget(ren, playerFade.get()); - SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); + SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE); + SDL_SetRenderDrawColor(ren, 0, 0, 0, 0); SDL_RenderClear(ren); SDL_RenderCopy(ren, origFade.get(), nullptr, nullptr); @@ -218,7 +219,8 @@ void render( SDL_SetRenderTarget(ren, lampFade.get()); - SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); + SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE); + SDL_SetRenderDrawColor(ren, 0, 0, 0, 0); SDL_RenderClear(ren); SDL_RenderCopy(ren, origFade.get(), nullptr, nullptr); @@ -241,7 +243,8 @@ void render( SDL_SetRenderTarget(ren, dustFade.get()); - SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); + SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE); + SDL_SetRenderDrawColor(ren, 0, 0, 0, 0); SDL_RenderClear(ren); SDL_RenderCopy(ren, origFade.get(), nullptr, nullptr); @@ -276,14 +279,14 @@ void render( if ((game.player_x == x && game.player_y == y) && game.renderPlayer) { SDL_SetRenderDrawColor(ren, 255, 255, 0, 255); - /*} else if (!game.map.at(x,y).lit) + } else if (!game.map.at(x,y).lit) { if (drawDark) { SDL_SetRenderDrawColor(ren, 40, 40, 40, 255); } else { draw = false; - }*/ + } } else { int alpha = 255; @@ -346,7 +349,7 @@ void render( } SDL_SetRenderTarget(ren, mask.get()); - SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); + SDL_SetRenderDrawColor(ren, 0, 0, 0, 0); SDL_RenderClear(ren); for (int y = game.map.getTop(); y < game.map.getBottom(); y++) @@ -369,40 +372,52 @@ void render( } SDL_SetRenderTarget(ren, sourceMask.get()); - SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); + SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE); + SDL_SetRenderDrawColor(ren, 0, 0, 0, 0); SDL_RenderClear(ren); - SDL_SetRenderDrawColor(ren, 255, 255, 255, 255); - - for (const coord& xy : game.map.at(x,y).litTiles) - { - SDL_Rect rect { - game.map.getTrueX(std::get<0>(xy)) * TILE_WIDTH, - game.map.getTrueY(std::get<1>(xy)) * TILE_HEIGHT, - TILE_WIDTH, - TILE_HEIGHT}; - - SDL_RenderFillRect(ren, &rect); - } + int fadeX = game.map.getTrueX(x) - game.map.at(x,y).lightRadius; + int fadeY = game.map.getTrueY(y) - game.map.at(x,y).lightRadius; + int fadeRight = game.map.getTrueX(x) + game.map.at(x,y).lightRadius; + int fadeBottom = game.map.getTrueY(y) + game.map.at(x,y).lightRadius; SDL_Rect fadeRect { - (game.map.getTrueX(x) - game.map.at(x,y).lightRadius) * TILE_WIDTH, - (game.map.getTrueY(y) - game.map.at(x,y).lightRadius) * TILE_HEIGHT, + fadeX * TILE_WIDTH, + fadeY * TILE_HEIGHT, (game.map.at(x,y).lightRadius * 2 + 1) * TILE_WIDTH, (game.map.at(x,y).lightRadius * 2 + 1) * TILE_HEIGHT}; if (game.map.at(x,y).lightType == Source::Lamp) { - SDL_SetTextureBlendMode(lampFade.get(), SDL_BLENDMODE_MOD); + SDL_SetTextureBlendMode(lampFade.get(), SDL_BLENDMODE_NONE); SDL_RenderCopy(ren, lampFade.get(), nullptr, &fadeRect); } else if (game.map.at(x,y).lightType == Source::Player) { - SDL_SetTextureBlendMode(playerFade.get(), SDL_BLENDMODE_MOD); + SDL_SetTextureBlendMode(playerFade.get(), SDL_BLENDMODE_NONE); SDL_RenderCopy(ren, playerFade.get(), nullptr, &fadeRect); } else if (game.map.at(x,y).lightType == Source::Dust) { - SDL_SetTextureBlendMode(dustFade.get(), SDL_BLENDMODE_MOD); + SDL_SetTextureBlendMode(dustFade.get(), SDL_BLENDMODE_NONE); SDL_RenderCopy(ren, dustFade.get(), nullptr, &fadeRect); } + SDL_SetRenderDrawColor(ren, 0, 0, 0, 0); + + for (int sy = fadeY; sy < fadeBottom; sy++) + { + for (int sx = fadeX; sx < fadeRight; sx++) + { + if (!game.map.at(x,y).litTiles.count({sx, sy})) + { + SDL_Rect rect { + game.map.getTrueX(sx) * TILE_WIDTH, + game.map.getTrueY(sy) * TILE_HEIGHT, + TILE_WIDTH, + TILE_HEIGHT}; + + SDL_RenderFillRect(ren, &rect); + } + } + } + SDL_SetRenderTarget(ren, mask.get()); SDL_SetTextureBlendMode(sourceMask.get(), SDL_BLENDMODE_ADD); SDL_RenderCopy(ren, sourceMask.get(), nullptr, nullptr); -- cgit 1.4.1