summary refs log tree commit diff stats
path: root/src/renderer.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2022-03-15 09:54:34 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2022-03-15 09:54:34 -0400
commit5ab72bf802e7a79d6eacded4e985740324c4faa7 (patch)
tree69eebbde57275632cc2b7b08f5bfd70506d5e25f /src/renderer.cpp
parent83ac4c41bc447a3372769f2b3ef6e3119d2717a2 (diff)
downloadether-5ab72bf802e7a79d6eacded4e985740324c4faa7.tar.gz
ether-5ab72bf802e7a79d6eacded4e985740324c4faa7.tar.bz2
ether-5ab72bf802e7a79d6eacded4e985740324c4faa7.zip
started adding zooming anim, looks weird esp when moving
Diffstat (limited to 'src/renderer.cpp')
-rw-r--r--src/renderer.cpp36
1 files changed, 31 insertions, 5 deletions
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}