diff --git a/FlappyBird/app/src/main/jni/game.c b/FlappyBird/app/src/main/jni/game.c index 8298626..13d7f54 100644 --- a/FlappyBird/app/src/main/jni/game.c +++ b/FlappyBird/app/src/main/jni/game.c @@ -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); @@ -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); @@ -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 @@ -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) { @@ -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) {