diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-18 23:04:04 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-18 23:04:04 -0400 |
commit | d1ec962c788286d0eca331ac33b3dd1867618ddb (patch) | |
tree | 75a69270a8e53b68b3e5c721651e63b70b268be2 /src/renderer.cpp | |
parent | 4e228fc4ea0189be7f28eba68d59b99841f91aab (diff) | |
download | ether-d1ec962c788286d0eca331ac33b3dd1867618ddb.tar.gz ether-d1ec962c788286d0eca331ac33b3dd1867618ddb.tar.bz2 ether-d1ec962c788286d0eca331ac33b3dd1867618ddb.zip |
fixed a lot of the zoom problems
still looks weird while moving
Diffstat (limited to 'src/renderer.cpp')
-rw-r--r-- | src/renderer.cpp | 53 |
1 files changed, 32 insertions, 21 deletions
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( | |||
125 | const Game& game, | 125 | const Game& game, |
126 | bool drawDark) | 126 | bool drawDark) |
127 | { | 127 | { |
128 | int windowTileWidth = game.curZoom * ZOOM_X_FACTOR + 2; | 128 | int windowTileWidth = game.getZoomBasis() * ZOOM_X_FACTOR + 2; |
129 | int windowTileHeight = game.curZoom * ZOOM_Y_FACTOR + 2; | 129 | int windowTileHeight = game.getZoomBasis() * ZOOM_Y_FACTOR + 2; |
130 | 130 | ||
131 | texture_ptr canvas( | 131 | texture_ptr canvas( |
132 | SDL_CreateTexture( | 132 | SDL_CreateTexture( |
@@ -146,8 +146,8 @@ void Renderer::renderGame( | |||
146 | SDL_SetRenderDrawColor(ren_.get(), rand() % 255, rand() % 255, rand() % 255, 255); | 146 | SDL_SetRenderDrawColor(ren_.get(), rand() % 255, rand() % 255, rand() % 255, 255); |
147 | SDL_RenderClear(ren_.get()); | 147 | SDL_RenderClear(ren_.get()); |
148 | 148 | ||
149 | int leftmost = game.player_x - game.curZoom * ZOOM_X_FACTOR / 2 - 1; | 149 | int leftmost = game.player_x - game.getZoomBasis() * ZOOM_X_FACTOR / 2 - 1; |
150 | int topmost = game.player_y - game.curZoom * ZOOM_Y_FACTOR / 2 - 1; | 150 | int topmost = game.player_y - game.getZoomBasis() * ZOOM_Y_FACTOR / 2 - 1; |
151 | for (int y = topmost; y < topmost + windowTileHeight; y++) | 151 | for (int y = topmost; y < topmost + windowTileHeight; y++) |
152 | { | 152 | { |
153 | for (int x = leftmost; x < leftmost + windowTileWidth; x++) | 153 | for (int x = leftmost; x < leftmost + windowTileWidth; x++) |
@@ -332,31 +332,38 @@ void Renderer::renderGame( | |||
332 | 332 | ||
333 | SDL_SetRenderTarget(ren_.get(), nullptr); | 333 | SDL_SetRenderTarget(ren_.get(), nullptr); |
334 | 334 | ||
335 | SDL_Rect zoomRect { | 335 | SDL_Rect zoomRect; |
336 | TILE_WIDTH, TILE_HEIGHT, (windowTileWidth - 2) * TILE_WIDTH, (windowTileHeight - 2) * TILE_HEIGHT | 336 | zoomRect.w = game.curZoom * ZOOM_X_FACTOR * TILE_WIDTH; |
337 | }; | 337 | zoomRect.h = game.curZoom * ZOOM_Y_FACTOR * TILE_HEIGHT; |
338 | if (!game.zooming) { | ||
339 | zoomRect.x = TILE_WIDTH; | ||
340 | zoomRect.y = TILE_HEIGHT; | ||
338 | 341 | ||
339 | if (game.moving) { | 342 | if (game.moving) { |
340 | if (game.player_x > game.player_oldx) { | 343 | if (game.player_x > game.player_oldx) { |
341 | zoomRect.x = game.moveProgress.getProgress(0, TILE_WIDTH); | 344 | zoomRect.x = game.moveProgress.getProgress(0, TILE_WIDTH); |
342 | } else if (game.player_x < game.player_oldx) { | 345 | } else if (game.player_x < game.player_oldx) { |
343 | zoomRect.x = game.moveProgress.getProgress(2*TILE_WIDTH, TILE_WIDTH); | 346 | zoomRect.x = game.moveProgress.getProgress(2*TILE_WIDTH, TILE_WIDTH); |
344 | } | 347 | } |
345 | 348 | ||
346 | if (game.player_y > game.player_oldy) { | 349 | if (game.player_y > game.player_oldy) { |
347 | zoomRect.y = game.moveProgress.getProgress(0, TILE_HEIGHT); | 350 | zoomRect.y = game.moveProgress.getProgress(0, TILE_HEIGHT); |
348 | } else if (game.player_y < game.player_oldy) { | 351 | } else if (game.player_y < game.player_oldy) { |
349 | zoomRect.y = game.moveProgress.getProgress(TILE_HEIGHT*2, TILE_HEIGHT); | 352 | zoomRect.y = game.moveProgress.getProgress(TILE_HEIGHT*2, TILE_HEIGHT); |
353 | } | ||
350 | } | 354 | } |
351 | } | 355 | } else { |
356 | int curZoomDiff = game.getZoomBasis() - game.curZoom; | ||
357 | zoomRect.x = (curZoomDiff * ZOOM_X_FACTOR / 2 + 1) * TILE_WIDTH; | ||
358 | zoomRect.y = (curZoomDiff * ZOOM_Y_FACTOR / 2 + 1) * TILE_HEIGHT; | ||
352 | 359 | ||
353 | if (game.zooming) { | ||
354 | int oldWidth = game.oldZoom * ZOOM_X_FACTOR * TILE_WIDTH; | 360 | int oldWidth = game.oldZoom * ZOOM_X_FACTOR * TILE_WIDTH; |
355 | int oldHeight = game.oldZoom * ZOOM_Y_FACTOR * TILE_HEIGHT; | 361 | int oldHeight = game.oldZoom * ZOOM_Y_FACTOR * TILE_HEIGHT; |
356 | 362 | ||
363 | int oldZoomDiff = game.getZoomBasis() - game.oldZoom; | ||
357 | SDL_Rect oldRect { | 364 | SDL_Rect oldRect { |
358 | zoomRect.w / 2 - oldWidth / 2, | 365 | (oldZoomDiff * ZOOM_X_FACTOR / 2 + 1) * TILE_WIDTH, |
359 | zoomRect.h / 2 - oldHeight / 2, | 366 | (oldZoomDiff * ZOOM_Y_FACTOR / 2 + 1) * TILE_HEIGHT, |
360 | oldWidth, | 367 | oldWidth, |
361 | oldHeight | 368 | oldHeight |
362 | }; | 369 | }; |
@@ -364,14 +371,18 @@ void Renderer::renderGame( | |||
364 | if (game.moving) { | 371 | if (game.moving) { |
365 | if (game.player_x > game.player_oldx) { | 372 | if (game.player_x > game.player_oldx) { |
366 | oldRect.x += game.moveProgress.getProgress(0, TILE_WIDTH); | 373 | oldRect.x += game.moveProgress.getProgress(0, TILE_WIDTH); |
374 | zoomRect.x += game.moveProgress.getProgress(0, TILE_WIDTH); | ||
367 | } else if (game.player_x < game.player_oldx) { | 375 | } else if (game.player_x < game.player_oldx) { |
368 | oldRect.x -= game.moveProgress.getProgress(TILE_WIDTH, 0); | 376 | oldRect.x -= game.moveProgress.getProgress(TILE_WIDTH, 0); |
377 | zoomRect.x -= game.moveProgress.getProgress(TILE_WIDTH, 0); | ||
369 | } | 378 | } |
370 | 379 | ||
371 | if (game.player_y > game.player_oldy) { | 380 | if (game.player_y > game.player_oldy) { |
372 | oldRect.y += game.moveProgress.getProgress(0, TILE_HEIGHT); | 381 | oldRect.y += game.moveProgress.getProgress(0, TILE_HEIGHT); |
382 | zoomRect.y += game.moveProgress.getProgress(0, TILE_HEIGHT); | ||
373 | } else if (game.player_y < game.player_oldy) { | 383 | } else if (game.player_y < game.player_oldy) { |
374 | oldRect.y -= game.moveProgress.getProgress(TILE_HEIGHT, 0); | 384 | oldRect.y -= game.moveProgress.getProgress(TILE_HEIGHT, 0); |
385 | zoomRect.y -= game.moveProgress.getProgress(TILE_HEIGHT, 0); | ||
375 | } | 386 | } |
376 | } | 387 | } |
377 | 388 | ||