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/game.cpp | 2 +- src/renderer.cpp | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index af57b56..beabc55 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -138,7 +138,7 @@ bool Game::movePlayer(int x, int y) player_y = y; muxer.setPlayerLoc(x, y); moving = true; - moveProgress.start(66); + moveProgress.start(1000/6); dirtyLighting = true; int chunkX, chunkY, old_chunkX, old_chunkY; 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