From 50b2ad88da60fe5d3f00c126a5a4ac53eaeff006 Mon Sep 17 00:00:00 2001 From: sophomore Date: Sun, 6 Oct 2024 12:54:59 +0800 Subject: [PATCH 1/3] Add function RenderSmallScoreRight (cherry picked from commit fd41c2adf5175d97716f2fcdb36a823ea9af217f) --- FlappyBird/app/src/main/jni/game.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/FlappyBird/app/src/main/jni/game.c b/FlappyBird/app/src/main/jni/game.c index 8298626..1799913 100644 --- a/FlappyBird/app/src/main/jni/game.c +++ b/FlappyBird/app/src/main/jni/game.c @@ -411,7 +411,7 @@ 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 RenderSmallScoreLeft(int score, float x, float y, float digitWidth, float digitHeight) { char scoreStr[10]; sprintf(scoreStr, "%d", score); @@ -440,6 +440,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 @@ -602,10 +610,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) { From 92c60b8d6b40d1557c38a28c24e61d3fd77ec2b6 Mon Sep 17 00:00:00 2001 From: sophomore Date: Sun, 6 Oct 2024 17:45:29 +0800 Subject: [PATCH 2/3] Add RenderScoreCenter function (cherry picked from commit c53e80a136832afa58e23d944f8458d0ac1bebec) --- FlappyBird/app/src/main/jni/game.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/FlappyBird/app/src/main/jni/game.c b/FlappyBird/app/src/main/jni/game.c index 1799913..3f8be9c 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,6 +411,14 @@ void RenderScore(int score, float x, float y, float digitWidth, float digitHeigh } } +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]; From 02606b317d431a58eec70897a977dcb06ac641a9 Mon Sep 17 00:00:00 2001 From: sophomore Date: Mon, 7 Oct 2024 10:27:03 +0800 Subject: [PATCH 3/3] fix function name --- FlappyBird/app/src/main/jni/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FlappyBird/app/src/main/jni/game.c b/FlappyBird/app/src/main/jni/game.c index 3f8be9c..13d7f54 100644 --- a/FlappyBird/app/src/main/jni/game.c +++ b/FlappyBird/app/src/main/jni/game.c @@ -560,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) {