diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp index a0085cb..4b13051 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -81,7 +81,11 @@ void tick(Game& game, bool onlyDark = false) | |||
81 | 81 | ||
82 | bool movePlayer(Game& game, int x, int y) | 82 | bool movePlayer(Game& game, int x, int y) |
83 | { | 83 | { |
84 | if (game.map.inBounds(x, y) && game.map.at(x,y).tile == Tile::Floor) | 84 | if (x >= game.curBoundX && |
85 | y >= game.curBoundY && | ||
86 | x < game.curBoundX + game.curZoom * ZOOM_X_FACTOR && | ||
87 | y < game.curBoundY + game.curZoom * ZOOM_Y_FACTOR && | ||
88 | game.map.at(x,y).tile == Tile::Floor) | ||
85 | { | 89 | { |
86 | if (game.map.at(game.player_x, game.player_y).tile == Tile::Floor) | 90 | if (game.map.at(game.player_x, game.player_y).tile == Tile::Floor) |
87 | { | 91 | { |
@@ -366,11 +370,36 @@ void setZoom(Game& game, size_t zoom) | |||
366 | growMap(game, zoom); | 370 | growMap(game, zoom); |
367 | } | 371 | } |
368 | 372 | ||
369 | // TODO: don't think this works well with rapid zoom changes | 373 | std::tie( |
370 | game.zoomProgress += (zoom - game.curZoom) * TILE_WIDTH; | 374 | game.lastZoomLeft, |
371 | //game.oldZoom = game.curZoom; | 375 | game.lastZoomTop, |
376 | game.lastZoomWidth, | ||
377 | game.lastZoomHeight) = | ||
378 | Renderer::calculateZoomRect(game); | ||
379 | |||
380 | game.zoomProgress = 0; | ||
381 | game.zoomLength = | ||
382 | std::abs(static_cast<long>(zoom - game.curZoom)) * TILE_WIDTH; | ||
372 | game.curZoom = zoom; | 383 | game.curZoom = zoom; |
373 | game.zooming = true; | 384 | game.zooming = true; |
385 | |||
386 | game.curBoundX = game.player_x - zoom * ZOOM_X_FACTOR / 2; | ||
387 | if (game.curBoundX < game.map.getLeft()) | ||
388 | { | ||
389 | game.curBoundX = game.map.getLeft(); | ||
390 | } else if (game.curBoundX + zoom * ZOOM_X_FACTOR >= game.map.getRight()) | ||
391 | { | ||
392 | game.curBoundX = game.map.getRight() - zoom * ZOOM_X_FACTOR; | ||
393 | } | ||
394 | |||
395 | game.curBoundY = game.player_y - zoom * ZOOM_Y_FACTOR / 2; | ||
396 | if (game.curBoundY < game.map.getTop()) | ||
397 | { | ||
398 | game.curBoundY = game.map.getTop(); | ||
399 | } else if (game.curBoundY + zoom * ZOOM_Y_FACTOR >= game.map.getBottom()) | ||
400 | { | ||
401 | game.curBoundY = game.map.getBottom() - zoom * ZOOM_Y_FACTOR; | ||
402 | } | ||
374 | } | 403 | } |
375 | 404 | ||
376 | int main(int, char**) | 405 | int main(int, char**) |
@@ -691,15 +720,9 @@ int main(int, char**) | |||
691 | { | 720 | { |
692 | if (game.zooming) | 721 | if (game.zooming) |
693 | { | 722 | { |
694 | if (game.zoomProgress > 0) | 723 | game.zoomProgress++; |
695 | { | ||
696 | game.zoomProgress--; | ||
697 | } else if (game.zoomProgress < 0) | ||
698 | { | ||
699 | game.zoomProgress++; | ||
700 | } | ||
701 | 724 | ||
702 | if (game.zoomProgress == 0) | 725 | if (game.zoomProgress == game.zoomLength) |
703 | { | 726 | { |
704 | game.zooming = false; | 727 | game.zooming = false; |
705 | } | 728 | } |