Skip to content

Commit

Permalink
♻️ Leverage 'Point' in 'DrawPlayerHelper' function
Browse files Browse the repository at this point in the history
  • Loading branch information
julealgon authored and AJenbo committed Sep 5, 2021
1 parent bb093ff commit 3a9b4c0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions Source/scrollrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,14 +794,12 @@ void DrawMonsterHelper(const Surface &out, int x, int y, int oy, int sx, int sy)
/**
* @brief Check if and how a player should be rendered
* @param out Output buffer
* @param y dPiece coordinate
* @param x dPiece coordinate
* @param sx Output buffer coordinate
* @param sy Output buffer coordinate
* @param tilePosition dPiece coordinates
* @param targetBufferPosition Output buffer coordinates
*/
void DrawPlayerHelper(const Surface &out, int x, int y, int sx, int sy)
void DrawPlayerHelper(const Surface &out, Point tilePosition, Point targetBufferPosition)
{
int8_t p = dPlayer[x][y];
int8_t p = dPlayer[tilePosition.x][tilePosition.y];
p = p > 0 ? p - 1 : -(p + 1);

if (p < 0 || p >= MAX_PLRS) {
Expand All @@ -814,10 +812,11 @@ void DrawPlayerHelper(const Surface &out, int x, int y, int sx, int sy)
if (player.IsWalking()) {
offset = GetOffsetForWalking(player.AnimInfo, player._pdir);
}
int px = sx + offset.deltaX - CalculateWidth2(player.AnimInfo.pCelSprite == nullptr ? 96 : player.AnimInfo.pCelSprite->Width());
int py = sy + offset.deltaY;

DrawPlayer(out, p, x, y, px, py);
const int width { CalculateWidth2(player.AnimInfo.pCelSprite == nullptr ? 96 : player.AnimInfo.pCelSprite->Width()) };
const Point playerRenderPosition { targetBufferPosition + offset - Displacement { width, 0 } };

DrawPlayer(out, p, tilePosition.x, tilePosition.y, playerRenderPosition.x, playerRenderPosition.y);
}

/**
Expand Down Expand Up @@ -884,7 +883,7 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit
if ((bFlag & BFLAG_PLAYERLR) != 0) {
int syy = tilePosition.y - 1;
assert(syy >= 0 && syy < MAXDUNY);
DrawPlayerHelper(out, tilePosition.x, syy, targetBufferPosition.x, targetBufferPosition.y);
DrawPlayerHelper(out, { tilePosition.x, syy }, targetBufferPosition);
}
if ((bFlag & BFLAG_MONSTLR) != 0 && negMon < 0) {
DrawMonsterHelper(out, tilePosition.x, tilePosition.y, -1, targetBufferPosition.x, targetBufferPosition.y);
Expand All @@ -893,7 +892,7 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit
DrawDeadPlayer(out, tilePosition.x, tilePosition.y, targetBufferPosition.x, targetBufferPosition.y);
}
if (dPlayer[tilePosition.x][tilePosition.y] > 0) {
DrawPlayerHelper(out, tilePosition.x, tilePosition.y, targetBufferPosition.x, targetBufferPosition.y);
DrawPlayerHelper(out, tilePosition, targetBufferPosition);
}
if (dMonster[tilePosition.x][tilePosition.y] > 0) {
DrawMonsterHelper(out, tilePosition.x, tilePosition.y, 0, targetBufferPosition.x, targetBufferPosition.y);
Expand Down

0 comments on commit 3a9b4c0

Please sign in to comment.