From 5ab72bf802e7a79d6eacded4e985740324c4faa7 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 15 Mar 2022 09:54:34 -0400 Subject: started adding zooming anim, looks weird esp when moving --- src/renderer.cpp | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'src/renderer.cpp') diff --git a/src/renderer.cpp b/src/renderer.cpp index 21c4746..befad8a 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -325,16 +325,11 @@ void Renderer::renderGame( SDL_SetRenderTarget(ren_.get(), nullptr); - // TODO: this is just moving interp. we also need zoom SDL_Rect zoomRect { TILE_WIDTH, TILE_HEIGHT, (windowTileWidth - 2) * TILE_WIDTH, (windowTileHeight - 2) * TILE_HEIGHT }; if (game.moving) { - double interp = - static_cast(game.zoomProgress) / - static_cast(game.zoomLength); - if (game.player_x > game.player_oldx) { zoomRect.x = game.moveProgress.getProgress(0, TILE_WIDTH); } else if (game.player_x < game.player_oldx) { @@ -348,6 +343,37 @@ void Renderer::renderGame( } } + if (game.zooming) { + int oldWidth = game.oldZoom * ZOOM_X_FACTOR * TILE_WIDTH; + int oldHeight = game.oldZoom * ZOOM_Y_FACTOR * TILE_HEIGHT; + + SDL_Rect oldRect { + zoomRect.w / 2 - oldWidth / 2, + zoomRect.h / 2 - oldHeight / 2, + oldWidth, + oldHeight + }; + + if (game.moving) { + if (game.player_x > game.player_oldx) { + oldRect.x += game.moveProgress.getProgress(0, TILE_WIDTH); + } else if (game.player_x < game.player_oldx) { + oldRect.x -= game.moveProgress.getProgress(TILE_WIDTH, 0); + } + + if (game.player_y > game.player_oldy) { + oldRect.y += game.moveProgress.getProgress(0, TILE_HEIGHT); + } else if (game.player_y < game.player_oldy) { + oldRect.y -= game.moveProgress.getProgress(TILE_HEIGHT, 0); + } + } + + zoomRect.x = game.zoomProgress.getProgress(oldRect.x, zoomRect.x); + zoomRect.y = game.zoomProgress.getProgress(oldRect.y, zoomRect.y); + zoomRect.w = game.zoomProgress.getProgress(oldRect.w, zoomRect.w); + zoomRect.h = game.zoomProgress.getProgress(oldRect.h, zoomRect.h); + } + SDL_RenderCopy(ren_.get(), canvas.get(), &zoomRect, nullptr); SDL_RenderPresent(ren_.get()); } -- cgit 1.4.1