about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-06-11 16:04:36 -0400
committerCharadon <dev@iotib.net>2022-06-11 16:04:36 -0400
commit3ac845290c617b191015846fbe6797d6477341c5 (patch)
tree238151e313d352a45ef5148d93cf37726eef2a1d /src
parenta35948788efff45c976e799c5913746d9b55b81a (diff)
downloadPong-C-3ac845290c617b191015846fbe6797d6477341c5.tar.gz
Draw Leaderboard
Diffstat (limited to 'src')
-rw-r--r--src/title.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/title.c b/src/title.c
index 73efbbe..93ab433 100644
--- a/src/title.c
+++ b/src/title.c
@@ -5,7 +5,18 @@ struct LeaderboardEntries {
     char Name[16];
 };
 
-struct LeaderboardEntries Top10[10];
+struct LeaderboardEntries Top10[10] = {
+    0, " ",
+    0, " ",
+    0, " ",
+    0, " ",
+    0, " ",
+    0, " ",
+    0, " ",
+    0, " ",
+    0, " ",
+    0, " "
+};
 
 static int compare_int(const void *Score1, const void *Score2) {
     const struct LeaderboardEntries *Entry1 = *(struct LeaderboardEntries**) Score1;
@@ -38,7 +49,7 @@ static void order_leaderboard() {
     }
 
     qsort(TmpStore, size, sizeof(struct LeaderboardEntries *), compare_int);
-    for(int i = 0; i < 10; i++) {
+    for(int i = 0; i < size; i++) {
         strcpy(Top10[i].Name, TmpStore[i]->Name);
         Top10[i].Score = TmpStore[i]->Score;
     }
@@ -181,7 +192,7 @@ int title_screen() {
     MainCamera.offset = (Vector2){0,0};
     MainCamera.target = (Vector2){0,0};
     MainCamera.rotation = 0.0f;
-    struct LeaderboardEntries *Top10[10];
+
     // Load leaderboard
     order_leaderboard();
 
@@ -234,8 +245,8 @@ int title_screen() {
             }
         } else if (CheckCollisionRecs(Mouse, Marathon)) {
             Selected = &Marathon;
+            Choice = 1;
             if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
-                Choice = 1;
                 TitleScreenGoing = false;
             }
         } else if (CheckCollisionRecs(Mouse, Settings)) {
@@ -262,6 +273,22 @@ int title_screen() {
                 DrawText("Settings", 20, 250, 48, WHITE);
                 DrawText("Help", 20, 300, 48, WHITE);
                 DrawText("Exit", 20, 350, 48, WHITE);
+                if(Choice == 1) {
+                    if( Top10[0].Name[0] == ' ' ) {
+                        printf("%s", Top10[0].Name);
+                        puts("E");
+                        goto skip;
+                    }
+                    char LeaderboardText[1024];
+                    DrawText("Leaderboard:", 600, 0, 48, WHITE);
+                    for (int i = 1; i <= 10; i++) {
+                        if(Top10[i].Name[0] != ' ') {
+                            snprintf(LeaderboardText, sizeof(LeaderboardText), "%s: %d", Top10[i-1].Name, Top10[i-1].Score);
+                            DrawText(LeaderboardText, 600, 50*i, 48, WHITE);
+                        }
+                    }
+                }
+                skip:
             EndMode2D();
             DrawText(VersionString, GetScreenWidth()-400, GetScreenHeight()-32, 32, GREEN);
         EndDrawing();