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

Method Jump

src/game_character.cpp:676–733  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

674}
675
676bool Game_Character::Jump(int x, int y) {
677 if (!IsStopping()) {
678 return true;
679 }
680
681 auto begin_x = GetX();
682 auto begin_y = GetY();
683 const auto dx = x - begin_x;
684 const auto dy = y - begin_y;
685
686 if (std::abs(dy) >= std::abs(dx)) {
687 SetDirection(dy >= 0 ? Down : Up);
688 } else {
689 SetDirection(dx >= 0 ? Right : Left);
690 }
691
692 SetJumping(true);
693
694 if (dx != 0 || dy != 0) {
695 if (!IsFacingLocked()) {
696 SetFacing(GetDirection());
697 }
698
699 // FIXME: Remove dependency on jump from within Game_Map::MakeWay?
700 // RPG_RT passes INT_MAX into from_x to tell it to skip self tile checks, which is hacky..
701 if (!MakeWay(begin_x, begin_y, x, y)) {
702 SetJumping(false);
703 return false;
704 }
705 }
706
707 // Adjust positions for looping maps. jump begin positions
708 // get set off the edge of the map to preserve direction.
709 if (Game_Map::LoopHorizontal()
710 && (x < 0 || x >= Game_Map::GetTilesX()))
711 {
712 const auto old_x = x;
713 x = Game_Map::RoundX(x);
714 begin_x += x - old_x;
715 }
716
717 if (Game_Map::LoopVertical()
718 && (y < 0 || y >= Game_Map::GetTilesY()))
719 {
720 auto old_y = y;
721 y = Game_Map::RoundY(y);
722 begin_y += y - old_y;
723 }
724
725 SetBeginJumpX(begin_x);
726 SetBeginJumpY(begin_y);
727 SetX(x);
728 SetY(y);
729 SetJumping(true);
730 SetRemainingStep(SCREEN_TILE_SIZE);
731
732 return true;
733}

Callers 4

testJumpFunction · 0.80
testStopFunction · 0.80
testAnimSpinFunction · 0.80
testAnimJumpFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected