Skip to content

Commit

Permalink
Add support for .relative & .centered
Browse files Browse the repository at this point in the history
When using .relative & .centered tags for PixelScrolling, do the following:
- Get half the width/height of the screen
- Move screen by ( h/v - screen_width/height ) divided by two.

When compared to Maniacs Patch 240822, it works as expected.
Tested using different resolutions, works like it should.

Revert "Add support for .relative & .centered"

This reverts commit 7525e75.

Add support for .relative & .centered

When using .relative & .centered tags for PixelScrolling, do the following:
- Get half the width/height of the screen
- Move screen by ( h/v - screen_width/height ) divided by two.

When compared to Maniacs Patch 240822, it works as expected.
Tested using different resolutions, works like it should.
  • Loading branch information
ToolMan2k committed Nov 23, 2024
1 parent 118cc2b commit 1436b8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 39 deletions.
37 changes: 0 additions & 37 deletions src/game_interpreter_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,15 +608,6 @@ bool Game_Interpreter_Map::CommandPanScreen(lcf::rpg::EventCommand const& com) {
int speed;
bool waiting_pan_screen = false;

// Maniac has new functions for pixel scrolling, which also have X and Y offsets
bool is_maniac = Player::IsPatchManiac();
int h;
int v;
double h_speed;
double v_speed;
bool centered = false;
bool relative = false;

auto& player = *Main_Data::game_player;

switch (com.parameters[0]) {
Expand Down Expand Up @@ -645,34 +636,6 @@ bool Game_Interpreter_Map::CommandPanScreen(lcf::rpg::EventCommand const& com) {
distance /= SCREEN_TILE_SIZE;
break;
}
if (is_maniac && com.parameters.size() > 5) {
h = ValueOrVariableBitfield(com, 1, 0, 2);
v = ValueOrVariableBitfield(com, 1, 1, 3);
waiting_pan_screen = (com.parameters[4] & 0x01) != 0;
speed = ValueOrVariableBitfield(com, 1, 2, 5);
switch (com.parameters[0]) {
case 4: // Relative Pixel Pan (speed)
centered = false;
relative = true;
player.StartPixelPan(h, v, speed, false, centered, relative);
break;
case 5: // Relative Pixel Pan (interpolated)
centered = false;
relative = true;
player.StartPixelPan(h, v, speed, true, centered, relative);
break;
case 6: // Absolute Pixel Pan (speed)
centered = (com.parameters[4] & 0x02) != 0;
relative = (com.parameters[4] & 0x04) != 0;
player.StartPixelPan(h, v, speed, false, centered, relative);
break;
case 7: // Absolute Pixel Pan (interpolated)
centered = (com.parameters[4] & 0x02) != 0;
relative = (com.parameters[4] & 0x04) != 0;
player.StartPixelPan(h, v, speed, true, centered, relative);
break;
}
}

if (Player::IsPatchManiac() && com.parameters.size() > 5) {
// Pixel scrolling with h/v offsets
Expand Down
8 changes: 6 additions & 2 deletions src/game_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,12 @@ void Game_Player::StartPixelPan(int h, int v, int speed, bool interpolated, bool
int new_pan_x;
int new_pan_y;

// FIXME: Fails when relative and centered are used in combination
if (relative) {
if (relative && centered) {
int screen_width = static_cast<int>(std::ceil(static_cast<float>(Player::screen_width) / 2)) * TILE_SIZE;
int screen_height = static_cast<int>(std::ceil(static_cast<float>(Player::screen_height) / 2)) * TILE_SIZE;
new_pan_x = data()->pan_finish_x - (h - screen_width) * 0.5;
new_pan_y = data()->pan_finish_y - (v - screen_height) * 0.5;
} else if (relative) {
new_pan_x = data()->pan_finish_x - h;
new_pan_y = data()->pan_finish_y - v;
} else if (centered) {
Expand Down

0 comments on commit 1436b8c

Please sign in to comment.