Skip to content

Aligned text #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions FlappyBird/app/src/main/jni/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void UpdateBirdTextureForLogo()
}
}

void RenderScore(int score, float x, float y, float digitWidth, float digitHeight)
void RenderScoreLeft(int score, float x, float y, float digitWidth, float digitHeight)
{
char scoreStr[10];
sprintf(scoreStr, "%d", score);
Expand Down Expand Up @@ -411,7 +411,15 @@ void RenderScore(int score, float x, float y, float digitWidth, float digitHeigh
}
}

void RenderSmallScore(int score, float x, float y, float digitWidth, float digitHeight)
void RenderScoreCenter(int score, float x, float y, float digitWidth, float digitHeight)
{
char scoreStr[10];
sprintf(scoreStr, "%d", score);
int len = strlen(scoreStr);
RenderScoreLeft(score, x - (len - 1) / 2.f * digitWidth, y, digitWidth, digitHeight);
}

void RenderSmallScoreLeft(int score, float x, float y, float digitWidth, float digitHeight)
{
char scoreStr[10];
sprintf(scoreStr, "%d", score);
Expand Down Expand Up @@ -440,6 +448,14 @@ void RenderSmallScore(int score, float x, float y, float digitWidth, float digit
}
}

void RenderSmallScoreRight(int score, float x, float y, float digitWidth, float digitHeight)
{
char scoreStr[10];
sprintf(scoreStr, "%d", score);
int len = strlen(scoreStr);
RenderSmallScoreLeft(score, x - len * digitWidth, y, digitWidth, digitHeight);
}

void Render()
{
//background
Expand Down Expand Up @@ -544,7 +560,7 @@ void Render()
RenderBird();

if (score > 0)
RenderScore(score, ScaleX(45.f), ScaleY(7.f), ScaleX(8.f), ScaleY(5.f));
RenderScoreCenter(score, ScaleX(45.f), ScaleY(7.f), ScaleX(8.f), ScaleY(5.f));
}
else if (currentState == STOP_GAME)
{
Expand Down Expand Up @@ -602,10 +618,10 @@ void Render()
RenderTexture(t_panel, ScaleX(15.f), panelY, ScaleX(70.f), ScaleY(17.5f));

// Render default score
RenderSmallScore(score, ScaleX(70.f), panelY + ScaleY(5.f), ScaleX(4.f), ScaleY(3.f));
RenderSmallScoreRight(score, ScaleX(78), panelY + ScaleY(5), ScaleX(4), ScaleY(3));

// Render best score
RenderSmallScore(bestScore, ScaleX(70.f), panelY + ScaleY(11.5f), ScaleX(4.f), ScaleY(3.f));
RenderSmallScoreRight(bestScore, ScaleX(78), panelY + ScaleY(11.5f), ScaleX(4), ScaleY(3));

if (newBestScore)
{
Expand Down