about summary refs log tree commit diff stats
path: root/src/ball.c
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-06-02 13:35:28 -0400
committerCharadon <dev@iotib.net>2022-06-02 13:35:28 -0400
commit8d19dc629bb1638990f7f9268880d7a139678a8e (patch)
tree124b527e5e48fc8f441a1273565a60501bf47e19 /src/ball.c
parente372341eb2d92ee7df6fcaf43f4dc2a27967e390 (diff)
downloadPong-C-8d19dc629bb1638990f7f9268880d7a139678a8e.tar.gz
Added music and almost done marathon mode.
Diffstat (limited to 'src/ball.c')
-rw-r--r--src/ball.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/ball.c b/src/ball.c
index 95cc0c5..4fc1eb4 100644
--- a/src/ball.c
+++ b/src/ball.c
@@ -3,6 +3,11 @@
 
 void ball(Rectangle *Player, Rectangle *Enemy, struct Balls *Ball, int *PlayerScore, int *EnemyScore) {
 	
+	bool NoEnemy = false;
+	if (Enemy == NULL) {
+		NoEnemy = true;
+	}
+
 	// Moves ball
 	Ball->Y += Ball->Angle;
 	if (Ball->Direction == LEFT) {
@@ -28,18 +33,20 @@ void ball(Rectangle *Player, Rectangle *Enemy, struct Balls *Ball, int *PlayerSc
         }
         play_audio(0);
 	}
-	if (CheckCollisionRecs(*Enemy, Ball->HitBox) && Ball->Direction == RIGHT) {
-		Ball->Direction = LEFT;
-		Ball->Speed *= 1.5f;
-       	if (Ball->Speed > 40) {
-	    	Ball->Speed = 40;
-	    }
-		if (Ball->Speed != 40) {
-		    Ball->Angle = GetRandomValue(-10, 10);
-        } else {
-            Ball->Angle = GetRandomValue(-30, 30);
-        }
-        play_audio(SOUND_BOUNCE);
+	if (NoEnemy == false) {
+		if (CheckCollisionRecs(*Enemy, Ball->HitBox) && Ball->Direction == RIGHT) {
+			Ball->Direction = LEFT;
+			Ball->Speed *= 1.5f;
+			if (Ball->Speed > 40) {
+				Ball->Speed = 40;
+			}
+			if (Ball->Speed != 40) {
+				Ball->Angle = GetRandomValue(-10, 10);
+			} else {
+				Ball->Angle = GetRandomValue(-30, 30);
+			}
+			play_audio(SOUND_BOUNCE);
+		}
 	}
 	
 	// Bounce ball if touches top or bottom of screen.
@@ -50,13 +57,18 @@ void ball(Rectangle *Player, Rectangle *Enemy, struct Balls *Ball, int *PlayerSc
 
 	// Calculates score and resets ball.
 	bool Scored = false;
-	if (Ball->X < 0) {
+	if (Ball->X < 0 && NoEnemy == false) {
 		*EnemyScore += 1;
 		Scored = true;
-	} else if (Ball ->X > 1280) {
+	} else if (Ball ->X > 1280 && NoEnemy == false) {
 		*PlayerScore += 1;
 		Scored = true;
-	}
+	} else if (Ball->X > (1280-32) && NoEnemy == true) {
+		*PlayerScore += 1;
+		Scored = false;
+		Ball->Direction = LEFT;
+		play_audio(SOUND_PLAYER_SCORE);
+	} 
 	if (Scored == true) {
 		Ball->X = 1280/2.0f;
 		Ball->Y = 720/2.0f;