about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-06-11 16:49:37 -0400
committerCharadon <dev@iotib.net>2022-06-11 16:49:37 -0400
commitd3bd312749481a660556de4c14b47ffaa26c8374 (patch)
tree2542826406583828a1e8c664aa34b4ac80ddf401
parentff49e3709164fccb4862522c116c9e8503fc9eaa (diff)
downloadPong-C-d3bd312749481a660556de4c14b47ffaa26c8374.tar.gz
Fixed some tabbing, and a memory leak
-rw-r--r--src/marathon.c74
-rw-r--r--src/title.c10
2 files changed, 46 insertions, 38 deletions
diff --git a/src/marathon.c b/src/marathon.c
index 064f873..6e871fa 100644
--- a/src/marathon.c
+++ b/src/marathon.c
@@ -116,54 +116,56 @@ void marathon_main() {
 
         snprintf(PlayerScore, 50, "Player: %d", Player.Score);
         MainCamera.zoom = GetScreenHeight()/720.0f;
-		MainCamera.offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
-		MainCamera.target = (Vector2){1280/2.0f, 720/2.0f};
-
-        //Controls
-		if(IsKeyDown(KEY_UP)) {
-			Player.Y -= 10;
-		} else if (IsKeyDown(KEY_DOWN)) {
-			Player.Y += 10;
-		} else if(IsKeyPressed(KEY_ESCAPE)) {
-			EnableCursor();
-		} else if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsCursorHidden() == true) {
-			Player.Y = GetMouseY()-PaddleSprite.height/2.0f;
-			DisableCursor();
-		}
-		
-		if(GetMouseY() < 0) {
-			SetMousePosition(0, 0);
-		} else if(GetMouseY() > 720) {
-			SetMousePosition(0, 720);
-		}
-
-		//Check if players are off-screen
-		if (Player.Y < 0) {
-			Player.Y = 0;
-		} else if (Player.Y > 480) {
-			Player.Y = 480;
-		}
+	MainCamera.offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
+	MainCamera.target = (Vector2){1280/2.0f, 720/2.0f};
+
+       	//Controls
+	if(IsKeyDown(KEY_UP)) {
+		Player.Y -= 10;
+	} else if (IsKeyDown(KEY_DOWN)) {
+		Player.Y += 10;
+	} else if(IsKeyPressed(KEY_ESCAPE)) {
+		EnableCursor();
+	} else if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsCursorHidden() == true) {
+		Player.Y = GetMouseY()-PaddleSprite.height/2.0f;
+		DisableCursor();
+	}
+	
+	if(GetMouseY() < 0) {
+		SetMousePosition(0, 0);
+	} else if(GetMouseY() > 720) {
+		SetMousePosition(0, 720);
+	}
+
+	//Check if players are off-screen
+	if (Player.Y < 0) {
+		Player.Y = 0;
+	} else if (Player.Y > 480) {
+		Player.Y = 480;
+	}
 
         // Collision
         ball(&Player.HitBox, NULL, &Ball, &Player.Score, NULL);
         //Updates hitbox with player's position.
-		Player.HitBox.y = Player.Y;
+	Player.HitBox.y = Player.Y;
 
         // End Game
         if(Ball.X < 0 || IsKeyPressed(KEY_Q)) {
-            leaderboard_record(Player.Score);
+	    if (Player.Score > 0) {
+            	leaderboard_record(Player.Score);
+	    }
             MarathonGoing = false;
         }
 
         BeginDrawing();
-			ClearBackground(BLACK);
-			BeginMode2D(MainCamera);
+		ClearBackground(BLACK);
+		BeginMode2D(MainCamera);
                 DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
-				DrawTexture(PaddleSprite, 0, Player.Y, WHITE);
-				DrawTexture(BallSprite, Ball.X, Ball.Y, WHITE);
-				DrawText(PlayerScore, 0, 0, 32, BLUE);
-			EndMode2D();
-		EndDrawing();
+			DrawTexture(PaddleSprite, 0, Player.Y, WHITE);
+			DrawTexture(BallSprite, Ball.X, Ball.Y, WHITE);
+			DrawText(PlayerScore, 0, 0, 32, BLUE);
+		EndMode2D();
+	EndDrawing();
     }
     Mix_HaltMusic();
     Mix_FreeMusic(Background);
diff --git a/src/title.c b/src/title.c
index edafd22..71bf04a 100644
--- a/src/title.c
+++ b/src/title.c
@@ -54,7 +54,13 @@ static void order_leaderboard() {
         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...
+    for(int i = 0; i < (UINT16_MAX*2); i++)
+    	free(TmpStore[i]); //Truth be told, I dunno if this even works, since the amount of memory used is kilobytes...
+    
+    // Close leaderboard file.
+    if (LeaderboardFile != NULL) {
+	fclose(LeaderboardFile);
+    }
     return;
 }
 
@@ -282,7 +288,7 @@ int title_screen() {
                         goto skip;
                     }
                     char LeaderboardText[1024];
-                    for (int i = 1; i <= 9; i++) {
+                    for (int i = 1; i <= 10; 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);