summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-06-05 19:01:26 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-06-05 19:01:26 -0400
commit5e94c9fb603dc4648fe6ab4c153ba4114b6bb486 (patch)
tree1360b6a0b734b245bfc234c9f4c5afc076e39096 /src
parentf838a08ef531ad643e28ced2c9b1ae5bd9d57765 (diff)
downloadether-5e94c9fb603dc4648fe6ab4c153ba4114b6bb486.tar.gz
ether-5e94c9fb603dc4648fe6ab4c153ba4114b6bb486.tar.bz2
ether-5e94c9fb603dc4648fe6ab4c153ba4114b6bb486.zip
improved overlapping lights
radius of light seems kind of diminished though.
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp63
1 files 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(
199 } 199 }
200 200
201 SDL_SetRenderTarget(ren, playerFade.get()); 201 SDL_SetRenderTarget(ren, playerFade.get());
202 SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); 202 SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE);
203 SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);
203 SDL_RenderClear(ren); 204 SDL_RenderClear(ren);
204 SDL_RenderCopy(ren, origFade.get(), nullptr, nullptr); 205 SDL_RenderCopy(ren, origFade.get(), nullptr, nullptr);
205 206
@@ -218,7 +219,8 @@ void render(
218 219
219 SDL_SetRenderTarget(ren, lampFade.get()); 220 SDL_SetRenderTarget(ren, lampFade.get());
220 221
221 SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); 222 SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE);
223 SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);
222 SDL_RenderClear(ren); 224 SDL_RenderClear(ren);
223 SDL_RenderCopy(ren, origFade.get(), nullptr, nullptr); 225 SDL_RenderCopy(ren, origFade.get(), nullptr, nullptr);
224 226
@@ -241,7 +243,8 @@ void render(
241 243
242 SDL_SetRenderTarget(ren, dustFade.get()); 244 SDL_SetRenderTarget(ren, dustFade.get());
243 245
244 SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); 246 SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE);
247 SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);
245 SDL_RenderClear(ren); 248 SDL_RenderClear(ren);
246 SDL_RenderCopy(ren, origFade.get(), nullptr, nullptr); 249 SDL_RenderCopy(ren, origFade.get(), nullptr, nullptr);
247 250
@@ -276,14 +279,14 @@ void render(
276 if ((game.player_x == x && game.player_y == y) && game.renderPlayer) 279 if ((game.player_x == x && game.player_y == y) && game.renderPlayer)
277 { 280 {
278 SDL_SetRenderDrawColor(ren, 255, 255, 0, 255); 281 SDL_SetRenderDrawColor(ren, 255, 255, 0, 255);
279 /*} else if (!game.map.at(x,y).lit) 282 } else if (!game.map.at(x,y).lit)
280 { 283 {
281 if (drawDark) 284 if (drawDark)
282 { 285 {
283 SDL_SetRenderDrawColor(ren, 40, 40, 40, 255); 286 SDL_SetRenderDrawColor(ren, 40, 40, 40, 255);
284 } else { 287 } else {
285 draw = false; 288 draw = false;
286 }*/ 289 }
287 } else { 290 } else {
288 int alpha = 255; 291 int alpha = 255;
289 292
@@ -346,7 +349,7 @@ void render(
346 } 349 }
347 350
348 SDL_SetRenderTarget(ren, mask.get()); 351 SDL_SetRenderTarget(ren, mask.get());
349 SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); 352 SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);
350 SDL_RenderClear(ren); 353 SDL_RenderClear(ren);
351 354
352 for (int y = game.map.getTop(); y < game.map.getBottom(); y++) 355 for (int y = game.map.getTop(); y < game.map.getBottom(); y++)
@@ -369,40 +372,52 @@ void render(
369 } 372 }
370 373
371 SDL_SetRenderTarget(ren, sourceMask.get()); 374 SDL_SetRenderTarget(ren, sourceMask.get());
372 SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); 375 SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE);
376 SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);
373 SDL_RenderClear(ren); 377 SDL_RenderClear(ren);
374 378
375 SDL_SetRenderDrawColor(ren, 255, 255, 255, 255); 379 int fadeX = game.map.getTrueX(x) - game.map.at(x,y).lightRadius;
376 380 int fadeY = game.map.getTrueY(y) - game.map.at(x,y).lightRadius;
377 for (const coord& xy : game.map.at(x,y).litTiles) 381 int fadeRight = game.map.getTrueX(x) + game.map.at(x,y).lightRadius;
378 { 382 int fadeBottom = game.map.getTrueY(y) + game.map.at(x,y).lightRadius;
379 SDL_Rect rect {
380 game.map.getTrueX(std::get<0>(xy)) * TILE_WIDTH,
381 game.map.getTrueY(std::get<1>(xy)) * TILE_HEIGHT,
382 TILE_WIDTH,
383 TILE_HEIGHT};
384
385 SDL_RenderFillRect(ren, &rect);
386 }
387 383
388 SDL_Rect fadeRect { 384 SDL_Rect fadeRect {
389 (game.map.getTrueX(x) - game.map.at(x,y).lightRadius) * TILE_WIDTH, 385 fadeX * TILE_WIDTH,
390 (game.map.getTrueY(y) - game.map.at(x,y).lightRadius) * TILE_HEIGHT, 386 fadeY * TILE_HEIGHT,
391 (game.map.at(x,y).lightRadius * 2 + 1) * TILE_WIDTH, 387 (game.map.at(x,y).lightRadius * 2 + 1) * TILE_WIDTH,
392 (game.map.at(x,y).lightRadius * 2 + 1) * TILE_HEIGHT}; 388 (game.map.at(x,y).lightRadius * 2 + 1) * TILE_HEIGHT};
393 389
394 if (game.map.at(x,y).lightType == Source::Lamp) 390 if (game.map.at(x,y).lightType == Source::Lamp)
395 { 391 {
396 SDL_SetTextureBlendMode(lampFade.get(), SDL_BLENDMODE_MOD); 392 SDL_SetTextureBlendMode(lampFade.get(), SDL_BLENDMODE_NONE);
397 SDL_RenderCopy(ren, lampFade.get(), nullptr, &fadeRect); 393 SDL_RenderCopy(ren, lampFade.get(), nullptr, &fadeRect);
398 } else if (game.map.at(x,y).lightType == Source::Player) { 394 } else if (game.map.at(x,y).lightType == Source::Player) {
399 SDL_SetTextureBlendMode(playerFade.get(), SDL_BLENDMODE_MOD); 395 SDL_SetTextureBlendMode(playerFade.get(), SDL_BLENDMODE_NONE);
400 SDL_RenderCopy(ren, playerFade.get(), nullptr, &fadeRect); 396 SDL_RenderCopy(ren, playerFade.get(), nullptr, &fadeRect);
401 } else if (game.map.at(x,y).lightType == Source::Dust) { 397 } else if (game.map.at(x,y).lightType == Source::Dust) {
402 SDL_SetTextureBlendMode(dustFade.get(), SDL_BLENDMODE_MOD); 398 SDL_SetTextureBlendMode(dustFade.get(), SDL_BLENDMODE_NONE);
403 SDL_RenderCopy(ren, dustFade.get(), nullptr, &fadeRect); 399 SDL_RenderCopy(ren, dustFade.get(), nullptr, &fadeRect);
404 } 400 }
405 401
402 SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);
403
404 for (int sy = fadeY; sy < fadeBottom; sy++)
405 {
406 for (int sx = fadeX; sx < fadeRight; sx++)
407 {
408 if (!game.map.at(x,y).litTiles.count({sx, sy}))
409 {
410 SDL_Rect rect {
411 game.map.getTrueX(sx) * TILE_WIDTH,
412 game.map.getTrueY(sy) * TILE_HEIGHT,
413 TILE_WIDTH,
414 TILE_HEIGHT};
415
416 SDL_RenderFillRect(ren, &rect);
417 }
418 }
419 }
420
406 SDL_SetRenderTarget(ren, mask.get()); 421 SDL_SetRenderTarget(ren, mask.get());
407 SDL_SetTextureBlendMode(sourceMask.get(), SDL_BLENDMODE_ADD); 422 SDL_SetTextureBlendMode(sourceMask.get(), SDL_BLENDMODE_ADD);
408 SDL_RenderCopy(ren, sourceMask.get(), nullptr, nullptr); 423 SDL_RenderCopy(ren, sourceMask.get(), nullptr, nullptr);