about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-06-14 20:32:17 -0400
committerCharadon <dev@iotib.net>2022-06-14 20:32:17 -0400
commit43a23590acdc63709f4e67a1caf39cf41be32dba (patch)
treed0beeddeaa4ea582097e5c677ad38dfdb2380d47
parentbf525fba47c8ea8972bbbd8353b83b607522a194 (diff)
downloadPong-C-43a23590acdc63709f4e67a1caf39cf41be32dba.tar.gz
#6 Added pause screen
-rw-r--r--src/marathon.c20
-rw-r--r--src/pong.h1
-rw-r--r--src/versus.c15
3 files changed, 24 insertions, 12 deletions
diff --git a/src/marathon.c b/src/marathon.c
index c2492a6..07a9fe3 100644
--- a/src/marathon.c
+++ b/src/marathon.c
@@ -133,7 +133,12 @@ void marathon_main() {
         } else if (IsKeyDown(KEY_DOWN)) {
             Player.Y += 10;
         } else if(IsKeyPressed(KEY_ESCAPE)) {
-            EnableCursor();
+			Mix_PauseMusic();
+			BeginDrawing();
+			EndDrawing();
+			MarathonGoing = pause_screen(&MainCamera);
+			Mix_ResumeMusic();
+			Ball.NextTick = SDL_AtomicGet(&Ticks)+1;
         } else if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsCursorHidden() == true) {
             Player.Y = GetMouseY()-PaddleSprite.height/2.0f;
             DisableCursor();
@@ -152,16 +157,13 @@ void marathon_main() {
             Player.Y = 480;
         }
 
-            // Collision
+        // Collision
         ball(&Player.HitBox, NULL, &Ball, &Player.Score, NULL);
-            //Updates hitbox with player's position.
+        //Updates hitbox with player's position.
         Player.HitBox.y = Player.Y;
 
         // End Game
-        if(Ball.X < 0 || IsKeyPressed(KEY_Q)) {
-	    if (Player.Score > 0) {
-            	leaderboard_record(Player.Score);
-	    }
+        if(Ball.X < 0) {
             MarathonGoing = false;
         }
 
@@ -176,7 +178,9 @@ void marathon_main() {
 	EndDrawing();
     }
     Mix_HaltMusic();
+	if (Player.Score > 0) {
+    	leaderboard_record(Player.Score);
+	}
     Mix_FreeMusic(Background);
-    EnableCursor();
     return;
 }
diff --git a/src/pong.h b/src/pong.h
index 2e2fd44..dd469f5 100644
--- a/src/pong.h
+++ b/src/pong.h
@@ -62,5 +62,6 @@ int title_screen();
 void versus_main();
 void marathon_main();
 void set_screen_mode();
+bool pause_screen(Camera2D *MainCamera);
 
 #endif
diff --git a/src/versus.c b/src/versus.c
index 34914bc..7b140ae 100644
--- a/src/versus.c
+++ b/src/versus.c
@@ -38,9 +38,10 @@ void versus_main() {
     char PlayerScore[50]; // Used later to display score on screen.
     // Init Camera
     Camera2D MainCamera;
-        MainCamera.target = (Vector2){0, 0};
-        MainCamera.offset = (Vector2){0, 0};
-        MainCamera.rotation = 0;
+    MainCamera.target = (Vector2){0, 0};
+    MainCamera.offset = (Vector2){0, 0};
+    MainCamera.rotation = 0;
+
 	bool VersusGoing = true;
 	Ball.NextTick = SDL_AtomicGet(&Ticks);
 	Enemy.NextTick = SDL_AtomicGet(&Ticks);
@@ -91,7 +92,13 @@ void versus_main() {
 		} else if (IsKeyDown(KEY_DOWN)) {
 			Player.Y += 10;
 		} else if(IsKeyPressed(KEY_ESCAPE)) {
-			EnableCursor();
+				Mix_PauseMusic();
+				BeginDrawing();
+				EndDrawing();
+				VersusGoing = pause_screen(&MainCamera);
+				Mix_ResumeMusic();
+				Ball.NextTick = SDL_AtomicGet(&Ticks)+1;
+				Enemy.NextTick = SDL_AtomicGet(&Ticks)+1;
 		} else if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsCursorHidden() == true) {
 			Player.Y = GetMouseY()-PaddleSprite.height/2.0f;
 			DisableCursor();