From d1ec962c788286d0eca331ac33b3dd1867618ddb Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 18 Mar 2022 23:04:04 -0400 Subject: fixed a lot of the zoom problems still looks weird while moving --- src/renderer.cpp | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'src/renderer.cpp') diff --git a/src/renderer.cpp b/src/renderer.cpp index 10027dd..94be197 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -125,8 +125,8 @@ void Renderer::renderGame( const Game& game, bool drawDark) { - int windowTileWidth = game.curZoom * ZOOM_X_FACTOR + 2; - int windowTileHeight = game.curZoom * ZOOM_Y_FACTOR + 2; + int windowTileWidth = game.getZoomBasis() * ZOOM_X_FACTOR + 2; + int windowTileHeight = game.getZoomBasis() * ZOOM_Y_FACTOR + 2; texture_ptr canvas( SDL_CreateTexture( @@ -146,8 +146,8 @@ void Renderer::renderGame( SDL_SetRenderDrawColor(ren_.get(), rand() % 255, rand() % 255, rand() % 255, 255); SDL_RenderClear(ren_.get()); - int leftmost = game.player_x - game.curZoom * ZOOM_X_FACTOR / 2 - 1; - int topmost = game.player_y - game.curZoom * ZOOM_Y_FACTOR / 2 - 1; + int leftmost = game.player_x - game.getZoomBasis() * ZOOM_X_FACTOR / 2 - 1; + int topmost = game.player_y - game.getZoomBasis() * ZOOM_Y_FACTOR / 2 - 1; for (int y = topmost; y < topmost + windowTileHeight; y++) { for (int x = leftmost; x < leftmost + windowTileWidth; x++) @@ -332,31 +332,38 @@ void Renderer::renderGame( SDL_SetRenderTarget(ren_.get(), nullptr); - SDL_Rect zoomRect { - TILE_WIDTH, TILE_HEIGHT, (windowTileWidth - 2) * TILE_WIDTH, (windowTileHeight - 2) * TILE_HEIGHT - }; + SDL_Rect zoomRect; + zoomRect.w = game.curZoom * ZOOM_X_FACTOR * TILE_WIDTH; + zoomRect.h = game.curZoom * ZOOM_Y_FACTOR * TILE_HEIGHT; + if (!game.zooming) { + zoomRect.x = TILE_WIDTH; + zoomRect.y = TILE_HEIGHT; - if (game.moving) { - if (game.player_x > game.player_oldx) { - zoomRect.x = game.moveProgress.getProgress(0, TILE_WIDTH); - } else if (game.player_x < game.player_oldx) { - zoomRect.x = game.moveProgress.getProgress(2*TILE_WIDTH, TILE_WIDTH); - } + if (game.moving) { + if (game.player_x > game.player_oldx) { + zoomRect.x = game.moveProgress.getProgress(0, TILE_WIDTH); + } else if (game.player_x < game.player_oldx) { + zoomRect.x = game.moveProgress.getProgress(2*TILE_WIDTH, TILE_WIDTH); + } - if (game.player_y > game.player_oldy) { - zoomRect.y = game.moveProgress.getProgress(0, TILE_HEIGHT); - } else if (game.player_y < game.player_oldy) { - zoomRect.y = game.moveProgress.getProgress(TILE_HEIGHT*2, TILE_HEIGHT); + if (game.player_y > game.player_oldy) { + zoomRect.y = game.moveProgress.getProgress(0, TILE_HEIGHT); + } else if (game.player_y < game.player_oldy) { + zoomRect.y = game.moveProgress.getProgress(TILE_HEIGHT*2, TILE_HEIGHT); + } } - } + } else { + int curZoomDiff = game.getZoomBasis() - game.curZoom; + zoomRect.x = (curZoomDiff * ZOOM_X_FACTOR / 2 + 1) * TILE_WIDTH; + zoomRect.y = (curZoomDiff * ZOOM_Y_FACTOR / 2 + 1) * TILE_HEIGHT; - if (game.zooming) { int oldWidth = game.oldZoom * ZOOM_X_FACTOR * TILE_WIDTH; int oldHeight = game.oldZoom * ZOOM_Y_FACTOR * TILE_HEIGHT; + int oldZoomDiff = game.getZoomBasis() - game.oldZoom; SDL_Rect oldRect { - zoomRect.w / 2 - oldWidth / 2, - zoomRect.h / 2 - oldHeight / 2, + (oldZoomDiff * ZOOM_X_FACTOR / 2 + 1) * TILE_WIDTH, + (oldZoomDiff * ZOOM_Y_FACTOR / 2 + 1) * TILE_HEIGHT, oldWidth, oldHeight }; @@ -364,14 +371,18 @@ void Renderer::renderGame( if (game.moving) { if (game.player_x > game.player_oldx) { oldRect.x += game.moveProgress.getProgress(0, TILE_WIDTH); + zoomRect.x += game.moveProgress.getProgress(0, TILE_WIDTH); } else if (game.player_x < game.player_oldx) { oldRect.x -= game.moveProgress.getProgress(TILE_WIDTH, 0); + zoomRect.x -= game.moveProgress.getProgress(TILE_WIDTH, 0); } if (game.player_y > game.player_oldy) { oldRect.y += game.moveProgress.getProgress(0, TILE_HEIGHT); + zoomRect.y += game.moveProgress.getProgress(0, TILE_HEIGHT); } else if (game.player_y < game.player_oldy) { oldRect.y -= game.moveProgress.getProgress(TILE_HEIGHT, 0); + zoomRect.y -= game.moveProgress.getProgress(TILE_HEIGHT, 0); } } -- cgit 1.4.1