Skip to content

Commit

Permalink
Fix event screen x and y to match RPG_RT
Browse files Browse the repository at this point in the history
  • Loading branch information
fmatthew5876 committed Mar 16, 2019
1 parent 85a40f0 commit 560907c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
32 changes: 18 additions & 14 deletions src/game_character.cpp
Expand Up @@ -98,29 +98,38 @@ int Game_Character::GetJumpHeight() const {
return 0;
}

int Game_Character::GetScreenX(bool apply_shift) const {
int x = GetSpriteX() / TILE_SIZE - Game_Map::GetDisplayX() / TILE_SIZE + (TILE_SIZE / 2);
int Game_Character::GetScreenX(bool force_shift) const {
int x = (GetSpriteX() - Game_Map::GetDisplayX()) / TILE_SIZE + TILE_SIZE;

if (apply_shift) {
if (Game_Map::LoopHorizontal()) {
x = Utils::PositiveModulo(x, Game_Map::GetWidth() * TILE_SIZE);
}
x -= TILE_SIZE / 2;

if (force_shift) {
x += Game_Map::GetWidth() * TILE_SIZE;
}

return x;
}

int Game_Character::GetScreenY(bool apply_shift) const {
int Game_Character::GetScreenY(bool force_shift) const {
int y = GetSpriteY() / TILE_SIZE - Game_Map::GetDisplayY() / TILE_SIZE + TILE_SIZE;

y -= GetJumpHeight();

if (apply_shift) {
if (Game_Map::LoopVertical()) {
y = Utils::PositiveModulo(y, Game_Map::GetHeight() * TILE_SIZE);
}

if (force_shift) {
y += Game_Map::GetHeight() * TILE_SIZE;
}

return y;
}

int Game_Character::GetScreenZ(bool apply_shift) const {
int Game_Character::GetScreenZ(bool force_shift) const {
int z = 0;

if (IsFlying()) {
Expand All @@ -134,7 +143,7 @@ int Game_Character::GetScreenZ(bool apply_shift) const {
}

// For events on the screen, this should be inside a 0-40 range
z += GetScreenY(apply_shift) >> 3;
z += GetScreenY(force_shift) >> 3;

return z;
}
Expand Down Expand Up @@ -826,10 +835,8 @@ int Game_Character::GetSpriteX() const {
x -= GetRemainingStep();
else if (d == Left || d == UpLeft || d == DownLeft)
x += GetRemainingStep();
} else if (IsJumping())
} else if (IsJumping()) {
x -= ((GetX() - GetBeginJumpX()) * GetRemainingStep());
if (x < 0 && Game_Map::LoopHorizontal()) {
x += Game_Map::GetWidth() * SCREEN_TILE_SIZE;
}

return x;
Expand All @@ -844,11 +851,8 @@ int Game_Character::GetSpriteY() const {
y -= GetRemainingStep();
else if (d == Up || d == UpRight || d == UpLeft)
y += GetRemainingStep();
} else if (IsJumping())
} else if (IsJumping()) {
y -= (GetY() - GetBeginJumpY()) * GetRemainingStep();

if (y < 0 && Game_Map::LoopVertical()) {
y += Game_Map::GetHeight() * SCREEN_TILE_SIZE;
}

return y;
Expand Down
4 changes: 2 additions & 2 deletions src/game_character.h
Expand Up @@ -637,15 +637,15 @@ class Game_Character {
* @param apply_shift When true the coordinate is shifted by the map width (for looping maps)
* @return screen x coordinate in pixels.
*/
virtual int GetScreenX(bool apply_shift = false) const;
virtual int GetScreenX(bool force_shift = false) const;

/**
* Gets sprite y coordinate transformed to screen coordinate in pixels.
*
* @param apply_shift When true the coordinate is shifted by the map height (for looping maps)
* @return screen y coordinate in pixels.
*/
virtual int GetScreenY(bool apply_shift = false) const;
virtual int GetScreenY(bool force_shift = false) const;

/**
* Gets screen z coordinate in pixels.
Expand Down

0 comments on commit 560907c

Please sign in to comment.