MCPcopy Create free account
hub / github.com/EasyRPG/Player / StartPixelPan

Method StartPixelPan

src/game_player.cpp:800–851  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

798}
799
800void Game_Player::StartPixelPan(int h, int v, int speed, bool interpolated, bool centered, bool relative) {
801 if (!Player::IsPatchManiac()) {
802 return;
803 }
804
805 h *= TILE_SIZE;
806 v *= TILE_SIZE;
807
808 maniac_pan_current_x = static_cast<double>(data()->pan_current_x);
809 maniac_pan_current_y = static_cast<double>(data()->pan_current_y);
810
811 int new_pan_x;
812 int new_pan_y;
813
814 if (relative && centered) {
815 int screen_width = static_cast<int>(std::ceil(static_cast<float>(Player::screen_width) / 2)) * TILE_SIZE;
816 int screen_height = static_cast<int>(std::ceil(static_cast<float>(Player::screen_height) / 2)) * TILE_SIZE;
817 new_pan_x = data()->pan_finish_x - (h - screen_width) * 0.5;
818 new_pan_y = data()->pan_finish_y - (v - screen_height) * 0.5;
819 } else if (relative) {
820 new_pan_x = data()->pan_finish_x - h;
821 new_pan_y = data()->pan_finish_y - v;
822 } else if (centered) {
823 new_pan_x = GetSpriteX() + GetDefaultPanX() - h;
824 new_pan_y = GetSpriteY() + GetDefaultPanY() - v;
825 } else {
826 new_pan_x = GetSpriteX() - h;
827 new_pan_y = GetSpriteY() - v;
828 }
829
830 double h_speed;
831 double v_speed;
832
833 if (speed == 0) {
834 // Instant pan if speed is zero
835 h_speed = std::abs((static_cast<double>(new_pan_x) - maniac_pan_current_x));
836 v_speed = std::abs((static_cast<double>(new_pan_y) - maniac_pan_current_y));
837 } else if (interpolated) {
838 // Interpolate distance by number of frames
839 h_speed = std::abs((static_cast<double>(new_pan_x) - maniac_pan_current_x)) / (speed + 1);
840 v_speed = std::abs((static_cast<double>(new_pan_y) - maniac_pan_current_y)) / (speed + 1);
841 } else {
842 // Multiply speed by 0.001
843 h_speed = std::max(static_cast<double>(speed * TILE_SIZE * 0.001), 1.0);
844 v_speed = std::max(static_cast<double>(speed * TILE_SIZE * 0.001), 1.0);
845 }
846
847 data()->pan_finish_x = new_pan_x;
848 data()->pan_finish_y = new_pan_y;
849 data()->maniac_horizontal_pan_speed = h_speed;
850 data()->maniac_vertical_pan_speed = v_speed;
851}
852
853void Game_Player::ResetPan(int speed) {
854 data()->pan_finish_x = GetDefaultPanX();

Callers 1

CommandPanScreenMethod · 0.80

Calls 1

maxFunction · 0.85

Tested by

no test coverage detected