diff options
-rw-r--r-- | src/game.cpp | 14 | ||||
-rw-r--r-- | src/game.h | 8 | ||||
-rw-r--r-- | src/renderer.cpp | 36 |
3 files changed, 47 insertions, 11 deletions
diff --git a/src/game.cpp b/src/game.cpp index beabc55..fc57acc 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
@@ -523,8 +523,10 @@ void Game::setZoom(size_t zoom) | |||
523 | return; | 523 | return; |
524 | } | 524 | } |
525 | 525 | ||
526 | zoomProgress = 0; | 526 | /*zoomProgress = 0; |
527 | zoomLength = std::abs(static_cast<long>(zoom - curZoom)) * TILE_WIDTH; | 527 | zoomLength = std::abs(static_cast<long>(zoom - curZoom)) * TILE_WIDTH;*/ |
528 | zoomProgress.start(62 * std::abs(static_cast<long>(zoom - curZoom)) * TILE_WIDTH); | ||
529 | oldZoom = curZoom; | ||
528 | curZoom = zoom; | 530 | curZoom = zoom; |
529 | zooming = true; | 531 | zooming = true; |
530 | loadMap(); | 532 | loadMap(); |
@@ -824,7 +826,7 @@ void Game::update(size_t frameTime) { | |||
824 | recalculateRender(); | 826 | recalculateRender(); |
825 | } | 827 | } |
826 | 828 | ||
827 | zoomTimer.accumulate(frameTime); | 829 | /*zoomTimer.accumulate(frameTime); |
828 | while (zoomTimer.step()) | 830 | while (zoomTimer.step()) |
829 | { | 831 | { |
830 | if (zooming) | 832 | if (zooming) |
@@ -836,6 +838,12 @@ void Game::update(size_t frameTime) { | |||
836 | zooming = false; | 838 | zooming = false; |
837 | } | 839 | } |
838 | } | 840 | } |
841 | }*/ | ||
842 | if (zooming) { | ||
843 | zoomProgress.tick(frameTime); | ||
844 | if (zoomProgress.isComplete()) { | ||
845 | zooming = false; | ||
846 | } | ||
839 | } | 847 | } |
840 | 848 | ||
841 | playerAnim.update(frameTime); | 849 | playerAnim.update(frameTime); |
diff --git a/src/game.h b/src/game.h index 40ace3d..93ca81a 100644 --- a/src/game.h +++ b/src/game.h | |||
@@ -78,9 +78,11 @@ public: | |||
78 | 78 | ||
79 | int maxZoom = INIT_ZOOM; | 79 | int maxZoom = INIT_ZOOM; |
80 | int curZoom = INIT_ZOOM; | 80 | int curZoom = INIT_ZOOM; |
81 | int oldZoom; | ||
81 | bool zooming = false; | 82 | bool zooming = false; |
82 | int zoomProgress = 0; | 83 | //int zoomProgress = 0; |
83 | int zoomLength; | 84 | //int zoomLength; |
85 | Interpolation zoomProgress; | ||
84 | 86 | ||
85 | Input keystate; | 87 | Input keystate; |
86 | bool firstInput = false; | 88 | bool firstInput = false; |
@@ -95,7 +97,7 @@ public: | |||
95 | Timer inputTimer = {50}; | 97 | Timer inputTimer = {50}; |
96 | Timer losePopLampTimer = {800}; | 98 | Timer losePopLampTimer = {800}; |
97 | Timer losePopPlayerTimer = {3000}; | 99 | Timer losePopPlayerTimer = {3000}; |
98 | Timer zoomTimer = {62}; | 100 | //Timer zoomTimer = {62}; |
99 | 101 | ||
100 | private: | 102 | private: |
101 | 103 | ||
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( | |||
325 | 325 | ||
326 | SDL_SetRenderTarget(ren_.get(), nullptr); | 326 | SDL_SetRenderTarget(ren_.get(), nullptr); |
327 | 327 | ||
328 | // TODO: this is just moving interp. we also need zoom | ||
329 | SDL_Rect zoomRect { | 328 | SDL_Rect zoomRect { |
330 | TILE_WIDTH, TILE_HEIGHT, (windowTileWidth - 2) * TILE_WIDTH, (windowTileHeight - 2) * TILE_HEIGHT | 329 | TILE_WIDTH, TILE_HEIGHT, (windowTileWidth - 2) * TILE_WIDTH, (windowTileHeight - 2) * TILE_HEIGHT |
331 | }; | 330 | }; |
332 | 331 | ||
333 | if (game.moving) { | 332 | if (game.moving) { |
334 | double interp = | ||
335 | static_cast<double>(game.zoomProgress) / | ||
336 | static_cast<double>(game.zoomLength); | ||
337 | |||
338 | if (game.player_x > game.player_oldx) { | 333 | if (game.player_x > game.player_oldx) { |
339 | zoomRect.x = game.moveProgress.getProgress(0, TILE_WIDTH); | 334 | zoomRect.x = game.moveProgress.getProgress(0, TILE_WIDTH); |
340 | } else if (game.player_x < game.player_oldx) { | 335 | } else if (game.player_x < game.player_oldx) { |
@@ -348,6 +343,37 @@ void Renderer::renderGame( | |||
348 | } | 343 | } |
349 | } | 344 | } |
350 | 345 | ||
346 | if (game.zooming) { | ||
347 | int oldWidth = game.oldZoom * ZOOM_X_FACTOR * TILE_WIDTH; | ||
348 | int oldHeight = game.oldZoom * ZOOM_Y_FACTOR * TILE_HEIGHT; | ||
349 | |||
350 | SDL_Rect oldRect { | ||
351 | zoomRect.w / 2 - oldWidth / 2, | ||
352 | zoomRect.h / 2 - oldHeight / 2, | ||
353 | oldWidth, | ||
354 | oldHeight | ||
355 | }; | ||
356 | |||
357 | if (game.moving) { | ||
358 | if (game.player_x > game.player_oldx) { | ||
359 | oldRect.x += game.moveProgress.getProgress(0, TILE_WIDTH); | ||
360 | } else if (game.player_x < game.player_oldx) { | ||
361 | oldRect.x -= game.moveProgress.getProgress(TILE_WIDTH, 0); | ||
362 | } | ||
363 | |||
364 | if (game.player_y > game.player_oldy) { | ||
365 | oldRect.y += game.moveProgress.getProgress(0, TILE_HEIGHT); | ||
366 | } else if (game.player_y < game.player_oldy) { | ||
367 | oldRect.y -= game.moveProgress.getProgress(TILE_HEIGHT, 0); | ||
368 | } | ||
369 | } | ||
370 | |||
371 | zoomRect.x = game.zoomProgress.getProgress(oldRect.x, zoomRect.x); | ||
372 | zoomRect.y = game.zoomProgress.getProgress(oldRect.y, zoomRect.y); | ||
373 | zoomRect.w = game.zoomProgress.getProgress(oldRect.w, zoomRect.w); | ||
374 | zoomRect.h = game.zoomProgress.getProgress(oldRect.h, zoomRect.h); | ||
375 | } | ||
376 | |||
351 | SDL_RenderCopy(ren_.get(), canvas.get(), &zoomRect, nullptr); | 377 | SDL_RenderCopy(ren_.get(), canvas.get(), &zoomRect, nullptr); |
352 | SDL_RenderPresent(ren_.get()); | 378 | SDL_RenderPresent(ren_.get()); |
353 | } | 379 | } |