about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-06-11 16:27:38 -0400
committerCharadon <dev@iotib.net>2022-06-11 16:27:38 -0400
commitff49e3709164fccb4862522c116c9e8503fc9eaa (patch)
treec32c571a139e557c23c884679472f0888f44b65b
parent3ac845290c617b191015846fbe6797d6477341c5 (diff)
downloadPong-C-ff49e3709164fccb4862522c116c9e8503fc9eaa.tar.gz
Fixed 2 bugs:
1. Incorrectly set NextTicks on ball for versus mode.
2. Forgot a -i on array in leaderboard drawing.
-rw-r--r--src/title.c21
-rw-r--r--src/versus.c4
2 files changed, 13 insertions, 12 deletions
diff --git a/src/title.c b/src/title.c
index 93ab433..edafd22 100644
--- a/src/title.c
+++ b/src/title.c
@@ -35,9 +35,9 @@ static void order_leaderboard() {
     if((LeaderboardFile = fopen(LeaderboardFilePath, "r")) == NULL) {
         return; //If it doesn't exist yet, we don't need to care.
     }
-    struct LeaderboardEntries *TmpStore[999];
-    for (int size = 0; size < 999; size++)
-        TmpStore[size] = malloc(sizeof(struct LeaderboardEntries)); //If there's 131,000 entries, I dunno what to tell you. You really like pong...
+    struct LeaderboardEntries *TmpStore[UINT16_MAX*2];
+    for (int size = 0; size < (UINT16_MAX*2); size++) //If there's 131,000 entries, I dunno what to tell you. You really like pong...
+        TmpStore[size] = malloc(sizeof(struct LeaderboardEntries)); 
     
     if(*TmpStore == NULL) {
         exit(1);
@@ -53,6 +53,8 @@ static void order_leaderboard() {
         strcpy(Top10[i].Name, TmpStore[i]->Name);
         Top10[i].Score = TmpStore[i]->Score;
     }
+    // Free TmpStore
+    free(*TmpStore); //Truth be told, I dunno if this even works, since the amount of memory used is kilobytes...
     return;
 }
 
@@ -239,8 +241,8 @@ int title_screen() {
         Mouse.y = GetMouseY()/MainCamera.zoom;
         if (CheckCollisionRecs(Mouse, Versus)) {
             Selected = &Versus;
+            Choice = 0;
             if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
-                Choice = 0;
                 TitleScreenGoing = false;
             }
         } else if (CheckCollisionRecs(Mouse, Marathon)) {
@@ -251,6 +253,7 @@ int title_screen() {
             }
         } else if (CheckCollisionRecs(Mouse, Settings)) {
             Selected = &Settings;
+	    Choice = 0;
             if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
                 settings(&MainCamera, TitleMusic);
             }
@@ -274,16 +277,14 @@ int title_screen() {
                 DrawText("Help", 20, 300, 48, WHITE);
                 DrawText("Exit", 20, 350, 48, WHITE);
                 if(Choice == 1) {
+                    DrawText("Leaderboard:", 600, 0, 48, WHITE);
                     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);
+                    for (int i = 1; i <= 9; i++) {
+                        if(Top10[i-1].Name[0] != ' ') {
+                            snprintf(LeaderboardText, sizeof(LeaderboardText), "%d: %s : %d", i, Top10[i-1].Name, Top10[i-1].Score);
                             DrawText(LeaderboardText, 600, 50*i, 48, WHITE);
                         }
                     }
diff --git a/src/versus.c b/src/versus.c
index 45a796d..34914bc 100644
--- a/src/versus.c
+++ b/src/versus.c
@@ -42,8 +42,8 @@ void versus_main() {
         MainCamera.offset = (Vector2){0, 0};
         MainCamera.rotation = 0;
 	bool VersusGoing = true;
-	Ball.NextTick = 0;
-	Enemy.NextTick = 0;
+	Ball.NextTick = SDL_AtomicGet(&Ticks);
+	Enemy.NextTick = SDL_AtomicGet(&Ticks);
     while(VersusGoing == true && GameGoing == true) {
 		
 		if (WindowShouldClose()) { //Quit Game if the window is closed.