about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--premake5.lua2
-rw-r--r--src/main.c1
-rw-r--r--src/marathon.c62
-rw-r--r--src/title.c119
4 files changed, 118 insertions, 66 deletions
diff --git a/premake5.lua b/premake5.lua
index 8cbcd7a..c88e9cc 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -1,5 +1,5 @@
 workspace("Pong")
-    configurations {"Debug", "Release"}
+    configurations {"Release"}
 
 project("Pong")
     newaction {
diff --git a/src/main.c b/src/main.c
index 51942dd..6f2e96e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,6 +28,7 @@ void set_screen_mode() {
 					goto FullScreenFailed;
 				}
 			}
+			SetWindowPosition(0, 0);
 			SetWindowState(FLAG_VSYNC_HINT);
 			SetWindowState(FLAG_FULLSCREEN_MODE);
 			break;
diff --git a/src/marathon.c b/src/marathon.c
index 135c533..a04519a 100644
--- a/src/marathon.c
+++ b/src/marathon.c
@@ -116,38 +116,38 @@ 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};
+	    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;
+        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;
 
         // End Game
         if(Ball.X < 0 || IsKeyPressed(KEY_Q)) {
@@ -160,7 +160,7 @@ void marathon_main() {
         BeginDrawing();
 		ClearBackground(BLACK);
 		BeginMode2D(MainCamera);
-                DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
+            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);
diff --git a/src/title.c b/src/title.c
index 73101dd..1dd0c87 100644
--- a/src/title.c
+++ b/src/title.c
@@ -63,11 +63,38 @@ static void order_leaderboard() {
     	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);
+	    fclose(LeaderboardFile);
     }
     return;
 }
 
+static void score_screen() {
+    // Find leaderboard file, and open it.
+    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; //If it doesn't exist yet, we don't need to care.
+    }
+    
+    // Init a temporary pointer to store scores and names into. This will be organized into Top10.
+    struct LeaderboardEntries *Scores[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...
+        Scores[size] = malloc(sizeof(struct LeaderboardEntries)); 
+    if(*Scores == NULL) { //Check if memory got assigned correctly.
+        exit(1);
+    }
+
+    // Load Scores and Names
+    int size = 0;
+    for (int a = 0; !feof(LeaderboardFile); a++, size++) { //Load data from file into array.
+        fscanf(LeaderboardFile, "%s %d\n", Scores[a]->Name, &Scores[a]->Score);
+    }
+    qsort(Scores, size, sizeof(struct LeaderboardEntries *), compare_int);
+    
+}
+
 static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
     bool SettingsGoing = true;
     int MusicBarY = 50;
@@ -120,26 +147,39 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
         {95, 326, ScreenButtonLength, 42}
     };
     SetMousePosition(GetScreenWidth()/2, GetScreenHeight()/2);
+    bool MouseCursorIn = true;
     while(SettingsGoing == true && GameGoing == true) {
         MainCamera->zoom = GetScreenHeight()/720.0f;
+        MainCamera->offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
+	    MainCamera->target = (Vector2){1280/2.0f, 720/2.0f};
 	
-	//Mouse
-	DisableCursor();
-	OldPosition = NewPosition;
-	NewPosition = GetMousePosition();
-	MouseCursor.y -= OldPosition.y-NewPosition.y;
-	MouseCursor.x -= OldPosition.x-NewPosition.x;
-	if (MouseCursor.y >= 720 || MouseCursor.y <= 0) {
-		MouseCursor.y += OldPosition.y-NewPosition.y;
-	}
-	if (MouseCursor.x >= 1280 || MouseCursor.x <= 0) {
-		MouseCursor.x += OldPosition.x-NewPosition.x;
-	}
+        //Mouse
+        if (MouseCursorIn == true) {
+            OldPosition = NewPosition;
+            NewPosition = GetMousePosition();
+            MouseCursor.y -= OldPosition.y-NewPosition.y;
+            MouseCursor.x -= OldPosition.x-NewPosition.x;
+            if (MouseCursor.y >= 720 || MouseCursor.y <= 0) {
+                MouseCursor.y += OldPosition.y-NewPosition.y;
+            }
+            if (MouseCursor.x >= 1280 || MouseCursor.x <= 0) {
+                MouseCursor.x += OldPosition.x-NewPosition.x;
+            }
+        }
+
+        if (IsKeyPressed(KEY_ESCAPE)) {
+            EnableCursor();
+            MouseCursorIn = false;
+        } else if (IsCursorOnScreen() && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+            DisableCursor();
+            MouseCursorIn = true;
+        }
 
         Mix_VolumeMusic(GlobalSettings.MusicVolume);
         BeginDrawing();
         ClearBackground(BLACK);
         BeginMode2D(*MainCamera);
+            DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
             // Back Button
             if (CheckCollisionRecs(MouseCursor, BackButton)) {
                 DrawRectangleRec(BackButton, RED);
@@ -151,6 +191,7 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
             // Music
             DrawText("Music Volume:", 50, 10, 42, WHITE);
             DrawText("<", 0,0,128,WHITE);
+            DrawRectangle(45, MusicBarY-5, 555, 60, DARKGRAY);
             for(int i = 0; i < 10; i++) {
                 if (CheckCollisionRecs(MouseCursor, MusicBar[i]) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
                     GlobalSettings.MusicVolume = i*10;
@@ -162,6 +203,7 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
 
             // Sound
             DrawText("Sound Volume:", 50, 108, 42, WHITE);
+            DrawRectangle(45, SoundBarY-5, 555, 60, DARKGRAY);
             DrawText("<", 0,0,128,WHITE);
             for(int i = 0; i < 10; i++) {
                 if (CheckCollisionRecs(MouseCursor, SoundBar[i]) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
@@ -249,7 +291,6 @@ int title_screen() {
     };
     Rectangle *Selected;
     Selected = &Versus;
-    EnableCursor();
 
     //Music
     Mix_Music *TitleMusic = Mix_LoadMUS("resources/title.wav");
@@ -260,6 +301,8 @@ int title_screen() {
     Vector2 OldPosition = GetMousePosition();
     Vector2 NewPosition = GetMousePosition();
     Texture2D MouseCursor = LoadTexture("resources/cursor.png");
+    bool MouseCursorIn = true;
+    DisableCursor();
 
     while(TitleScreenGoing == true && GameGoing == true) {
         
@@ -268,24 +311,32 @@ int title_screen() {
             TitleScreenGoing = false;
         }
 	
-	// Update Camera
+	    // Update Camera
         MainCamera.zoom = GetScreenHeight()/720.0f;
-	MainCamera.offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
-	MainCamera.target = (Vector2){1280/2.0f, 720/2.0f};
+	    MainCamera.offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
+	    MainCamera.target = (Vector2){1280/2.0f, 720/2.0f};
 
-	//Mouse
-	DisableCursor();
-	OldPosition = NewPosition;
-	NewPosition = GetMousePosition();
-	Mouse.y -= OldPosition.y-NewPosition.y;
-	Mouse.x -= OldPosition.x-NewPosition.x;
-	if (Mouse.y >= 720 || Mouse.y <= 0) {
-		Mouse.y += OldPosition.y-NewPosition.y;
-	}
-	if (Mouse.x >= 1280 || Mouse.x <= 0) {
-		Mouse.x += OldPosition.x-NewPosition.x;
-	}
-	printf("%f,%f\n", Mouse.x, Mouse.y);
+        //Mouse
+        if (MouseCursorIn == true) {
+            OldPosition = NewPosition;
+            NewPosition = GetMousePosition();
+            Mouse.y -= OldPosition.y-NewPosition.y;
+            Mouse.x -= OldPosition.x-NewPosition.x;
+            if (Mouse.y >= 720 || Mouse.y <= 0) {
+                Mouse.y += OldPosition.y-NewPosition.y;
+            }
+            if (Mouse.x >= 1280 || Mouse.x <= 0) {
+                Mouse.x += OldPosition.x-NewPosition.x;
+            }
+        }
+        
+        if (IsKeyPressed(KEY_ESCAPE)) {
+            EnableCursor();
+            MouseCursorIn = false;
+        } else if (IsCursorOnScreen() && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+            DisableCursor();
+            MouseCursorIn = true;
+        }
 
         if (CheckCollisionRecs(Mouse, Versus)) {
             Selected = &Versus;
@@ -301,7 +352,7 @@ int title_screen() {
             }
         } else if (CheckCollisionRecs(Mouse, Settings)) {
             Selected = &Settings;
-	    Choice = 0;
+        Choice = 0;
             if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
                 settings(&MainCamera, TitleMusic);
             }
@@ -317,8 +368,8 @@ int title_screen() {
         BeginDrawing();
             ClearBackground(BLACK);
             BeginMode2D(MainCamera);
-		DrawRectangleRec(Mouse, YELLOW);
-		DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
+                DrawRectangleRec(Mouse, YELLOW);
+                DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
                 DrawRectangleRec(*Selected, RED);
                 DrawText("PONG", 0, 0, 128, WHITE);
                 DrawText("Versus", 20, 150, 48, WHITE);
@@ -340,7 +391,7 @@ int title_screen() {
                     }
                 }
                 skip:
-	    	DrawTexture(MouseCursor, Mouse.x, Mouse.y, WHITE);
+            DrawTexture(MouseCursor, Mouse.x, Mouse.y, WHITE);
             EndMode2D();
             DrawText(VersionString, GetScreenWidth()-400, GetScreenHeight()-32, 32, GREEN);
         EndDrawing();