Skip to content

Commit

Permalink
Panorama: Fix off-by-one error in panorama position calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Mar 12, 2023
1 parent 5ee793c commit 77237dc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <climits>

#include "async_handler.h"
#include "options.h"
#include "system.h"
#include "game_battle.h"
#include "game_battler.h"
Expand Down Expand Up @@ -1730,7 +1731,11 @@ void Game_Map::Parallax::ResetPositionX() {
}

if (!params.scroll_horz && !LoopHorizontal()) {
int tiles_per_screen = (Player::screen_width / TILE_SIZE * TILE_SIZE + 16) / TILE_SIZE;
int tiles_per_screen = Player::screen_width / TILE_SIZE;
if (Player::screen_width % TILE_SIZE != 0) {
++tiles_per_screen;
}

if (GetWidth() > tiles_per_screen && parallax_width > Player::screen_width) {
const int w = (GetWidth() - tiles_per_screen) * TILE_SIZE;
const int ph = 2 * std::min(w, parallax_width - Player::screen_width) * map_info.position_x / w;
Expand All @@ -1754,9 +1759,13 @@ void Game_Map::Parallax::ResetPositionY() {
}

if (!params.scroll_vert && !Game_Map::LoopVertical()) {
int tiles_per_screen = (Player::screen_height / TILE_SIZE * TILE_SIZE + 16) / TILE_SIZE;
int tiles_per_screen = Player::screen_height / TILE_SIZE;
if (Player::screen_width % TILE_SIZE != 0) {
++tiles_per_screen;
}

if (GetHeight() > tiles_per_screen && parallax_height > Player::screen_height) {
const int h = (GetHeight() - tiles_per_screen) * TILE_SIZE;
const int h = (GetHeight() - 15) * TILE_SIZE;
const int pv = 2 * std::min(h, parallax_height - Player::screen_height) * map_info.position_y / h;
SetPositionY(pv);
} else {
Expand Down

0 comments on commit 77237dc

Please sign in to comment.