about summary refs log tree commit diff stats
path: root/src/title.c
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-06-09 20:21:26 -0400
committerCharadon <dev@iotib.net>2022-06-09 20:21:26 -0400
commitea25821768c7ac5dc7f7c0617689f6a67a88bb2a (patch)
treeafb98f6c7f5585b143c8f9c9853c37518550ff95 /src/title.c
parent2d032601da11595cbb2c1fab34371d10cd184eb6 (diff)
downloadPong-C-ea25821768c7ac5dc7f7c0617689f6a67a88bb2a.tar.gz
Begun work on organizing leaderboard
Diffstat (limited to 'src/title.c')
-rw-r--r--src/title.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/title.c b/src/title.c
index 04cf0ca..501b3ad 100644
--- a/src/title.c
+++ b/src/title.c
@@ -1,5 +1,46 @@
 #include "pong.h"
 
+static struct {
+    int Score;
+    char *Name;
+}Leaderboard[10];
+
+static void order_leaderboard() {
+    int *Score;
+    bool Parsing = true;
+
+    //Load leaderboard file.
+    char *LeaderboardDirectory = SDL_GetPrefPath("iotib", "Pong");
+	char LeaderboardFilePath[8192];
+	snprintf(LeaderboardFilePath, sizeof(LeaderboardFilePath), "%s/leaderboard.txt", LeaderboardDirectory);
+	FILE *LeaderboardFile;
+    if ((LeaderboardFile = fopen(LeaderboardFilePath, "r")) == NULL) {
+        return;
+    }
+    int Count = 0;
+    for(int i = 0; feof(LeaderboardFile); i++) {
+        Count++;
+        Score = malloc(Count*sizeof(int));
+        if(Score == NULL) {
+            fprintf(stderr, "Failed to load data from leaderboards.txt\n");
+            free(Score);
+            return;
+        }
+        fscanf(LeaderboardFile, "%d", &Score[i]);
+    }
+    int TopSpot = 0;
+    //int Result = 0;
+    //char *ResultName = NULL;
+    //int OldResults[sizeof(Score];)
+    //while(Parsing == true) {
+        for(int a = 0; a <= Count; a++) {
+            
+        }
+        TopSpot += 1;
+    //}
+    return;
+}
+
 static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
     bool SettingsGoing = true;
     int MusicBarY = 50;
@@ -137,6 +178,9 @@ int title_screen() {
     MainCamera.target = (Vector2){0,0};
     MainCamera.rotation = 0.0f;
 
+    // Load leaderboard
+    //order_leaderboard();
+
     bool TitleScreenGoing = true;
     int Choice = 0;