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 | |
| 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
| -rw-r--r-- | res/read_instruction.psd | bin | 0 -> 132202 bytes | |||
| -rw-r--r-- | src/game.cpp | 15 | ||||
| -rw-r--r-- | src/game.h | 4 | ||||
| -rw-r--r-- | src/renderer.cpp | 53 |
4 files changed, 44 insertions, 28 deletions
| diff --git a/res/read_instruction.psd b/res/read_instruction.psd new file mode 100644 index 0000000..1c05291 --- /dev/null +++ b/res/read_instruction.psd | |||
| Binary files differ | |||
| diff --git a/src/game.cpp b/src/game.cpp index 08c96ee..8e4dac5 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
| @@ -163,6 +163,8 @@ bool Game::movePlayer(int x, int y) | |||
| 163 | moveProgress.start(1000/6); | 163 | moveProgress.start(1000/6); |
| 164 | dirtyLighting = true; | 164 | dirtyLighting = true; |
| 165 | 165 | ||
| 166 | std::cout << player_x << "," << player_y << std::endl; | ||
| 167 | |||
| 166 | int chunkX, chunkY, old_chunkX, old_chunkY; | 168 | int chunkX, chunkY, old_chunkX, old_chunkY; |
| 167 | toChunkPos(player_x, player_y, chunkX, chunkY); | 169 | toChunkPos(player_x, player_y, chunkX, chunkY); |
| 168 | toChunkPos(player_oldx, player_oldy, old_chunkX, old_chunkY); | 170 | toChunkPos(player_oldx, player_oldy, old_chunkX, old_chunkY); |
| @@ -394,7 +396,7 @@ void Game::recalculateRender() { | |||
| 394 | 396 | ||
| 395 | if (wallRenders.at(renderDesc) == TilesetIndex(21, 12) && renderDesc != 255) { | 397 | if (wallRenders.at(renderDesc) == TilesetIndex(21, 12) && renderDesc != 255) { |
| 396 | //std::cout << renderDesc << std::endl; | 398 | //std::cout << renderDesc << std::endl; |
| 397 | std::cout << ((renderDesc & (1 << 7)) ? 'X' : 'O'); | 399 | /*std::cout << ((renderDesc & (1 << 7)) ? 'X' : 'O'); |
| 398 | std::cout << ((renderDesc & (1 << 6)) ? 'X' : 'O'); | 400 | std::cout << ((renderDesc & (1 << 6)) ? 'X' : 'O'); |
| 399 | std::cout << ((renderDesc & (1 << 5)) ? 'X' : 'O'); | 401 | std::cout << ((renderDesc & (1 << 5)) ? 'X' : 'O'); |
| 400 | std::cout << std::endl; | 402 | std::cout << std::endl; |
| @@ -405,7 +407,7 @@ void Game::recalculateRender() { | |||
| 405 | std::cout << ((renderDesc & (1 << 1)) ? 'X' : 'O'); | 407 | std::cout << ((renderDesc & (1 << 1)) ? 'X' : 'O'); |
| 406 | std::cout << ((renderDesc & (1 << 2)) ? 'X' : 'O'); | 408 | std::cout << ((renderDesc & (1 << 2)) ? 'X' : 'O'); |
| 407 | std::cout << ((renderDesc & (1 << 3)) ? 'X' : 'O'); | 409 | std::cout << ((renderDesc & (1 << 3)) ? 'X' : 'O'); |
| 408 | std::cout << std::endl; | 410 | std::cout << std::endl;*/ |
| 409 | } | 411 | } |
| 410 | } | 412 | } |
| 411 | } | 413 | } |
| @@ -562,8 +564,9 @@ void Game::processKickup() | |||
| 562 | } | 564 | } |
| 563 | 565 | ||
| 564 | void Game::loadMap() { | 566 | void Game::loadMap() { |
| 565 | int newChunksHoriz = std::ceil(static_cast<double>(curZoom) * ZOOM_X_FACTOR / CHUNK_WIDTH) + 4; | 567 | double zoomBasis = getZoomBasis(); |
| 566 | int newChunksVert = std::ceil(static_cast<double>(curZoom) * ZOOM_Y_FACTOR / CHUNK_HEIGHT) + 4; | 568 | int newChunksHoriz = std::ceil(zoomBasis * ZOOM_X_FACTOR / CHUNK_WIDTH) + 4; |
| 569 | int newChunksVert = std::ceil(zoomBasis * ZOOM_Y_FACTOR / CHUNK_HEIGHT) + 4; | ||
| 567 | int curPlayerChunkX, curPlayerChunkY; | 570 | int curPlayerChunkX, curPlayerChunkY; |
| 568 | toChunkPos(player_x, player_y, curPlayerChunkX, curPlayerChunkY); | 571 | toChunkPos(player_x, player_y, curPlayerChunkX, curPlayerChunkY); |
| 569 | 572 | ||
| @@ -584,14 +587,14 @@ void Game::loadMap() { | |||
| 584 | 587 | ||
| 585 | void Game::setZoom(size_t zoom) | 588 | void Game::setZoom(size_t zoom) |
| 586 | { | 589 | { |
| 587 | if (zoom == curZoom) | 590 | if (zoom == curZoom || zooming) |
| 588 | { | 591 | { |
| 589 | return; | 592 | return; |
| 590 | } | 593 | } |
| 591 | 594 | ||
| 592 | /*zoomProgress = 0; | 595 | /*zoomProgress = 0; |
| 593 | zoomLength = std::abs(static_cast<long>(zoom - curZoom)) * TILE_WIDTH;*/ | 596 | zoomLength = std::abs(static_cast<long>(zoom - curZoom)) * TILE_WIDTH;*/ |
| 594 | zoomProgress.start(62 * std::abs(static_cast<long>(zoom - curZoom)) * TILE_WIDTH); | 597 | zoomProgress.start(62 * std::abs(static_cast<long>(zoom) - curZoom) * TILE_WIDTH); |
| 595 | oldZoom = curZoom; | 598 | oldZoom = curZoom; |
| 596 | curZoom = zoom; | 599 | curZoom = zoom; |
| 597 | zooming = true; | 600 | zooming = true; |
| diff --git a/src/game.h b/src/game.h index c75d43b..6e676ae 100644 --- a/src/game.h +++ b/src/game.h | |||
| @@ -82,12 +82,14 @@ public: | |||
| 82 | 82 | ||
| 83 | int maxZoom = INIT_ZOOM; | 83 | int maxZoom = INIT_ZOOM; |
| 84 | int curZoom = INIT_ZOOM; | 84 | int curZoom = INIT_ZOOM; |
| 85 | int oldZoom; | 85 | int oldZoom = INIT_ZOOM; |
| 86 | bool zooming = false; | 86 | bool zooming = false; |
| 87 | //int zoomProgress = 0; | 87 | //int zoomProgress = 0; |
| 88 | //int zoomLength; | 88 | //int zoomLength; |
| 89 | Interpolation zoomProgress; | 89 | Interpolation zoomProgress; |
| 90 | 90 | ||
| 91 | double getZoomBasis() const { return zooming ? std::max(curZoom, oldZoom) : curZoom; } | ||
| 92 | |||
| 91 | Input keystate; | 93 | Input keystate; |
| 92 | bool firstInput = false; | 94 | bool firstInput = false; |
| 93 | Input lastInput; | 95 | Input lastInput; |
| 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 | ||
