From a3b8f0972ea1bbaa456a0c3ae70621e91a2c3ce7 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 14 Mar 2022 17:55:38 -0400 Subject: fixed flickering while walking sort of. the (intentional) dust flicker is still there. might want to remove the player trailing dust as they walk. --- src/renderer.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/renderer.cpp') diff --git a/src/renderer.cpp b/src/renderer.cpp index 1f51e0a..61aaf31 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -251,9 +251,20 @@ void Renderer::renderGame( int posToUseX = x - leftmost; int posToUseY = y - topmost; + int xInterp = 0; + int yInterp = 0; if (game.map.at(x,y).lightType == Source::Player && game.moving) { - posToUseX = game.moveProgress.getProgress((game.player_oldx) - leftmost, posToUseX); - posToUseY = game.moveProgress.getProgress((game.player_oldy) - topmost, posToUseY); + if (game.player_x > game.player_oldx) { + xInterp = game.moveProgress.getProgress(-TILE_WIDTH, 0); + } else if (game.player_x < game.player_oldx) { + xInterp = game.moveProgress.getProgress(TILE_WIDTH, 0); + } + + if (game.player_y > game.player_oldy) { + yInterp = game.moveProgress.getProgress(-TILE_HEIGHT, 0); + } else if (game.player_y < game.player_oldy) { + yInterp = game.moveProgress.getProgress(TILE_HEIGHT, 0); + } } int fadeX = posToUseX - game.map.at(x,y).lightRadius; @@ -262,8 +273,8 @@ void Renderer::renderGame( int fadeBottom = posToUseY + game.map.at(x,y).lightRadius; SDL_Rect fadeRect { - fadeX * TILE_WIDTH, - fadeY * TILE_HEIGHT, + fadeX * TILE_WIDTH + xInterp, + fadeY * TILE_HEIGHT + yInterp, (game.map.at(x,y).lightRadius * 2 + 1) * TILE_WIDTH, (game.map.at(x,y).lightRadius * 2 + 1) * TILE_HEIGHT}; @@ -288,8 +299,8 @@ void Renderer::renderGame( if (!game.map.at(x,y).litTiles.count({sx, sy})) { SDL_Rect rect { - (sx - leftmost) * TILE_WIDTH, - (sy - topmost) * TILE_HEIGHT, + (sx - leftmost) * TILE_WIDTH + xInterp, + (sy - topmost) * TILE_HEIGHT + yInterp, TILE_WIDTH, TILE_HEIGHT}; -- cgit 1.4.1