From 422b97ce6b67b095f2c6b64b33c7cbef8fbf32b4 Mon Sep 17 00:00:00 2001
From: g5-chappell <gareth2.chappell@live.uwe.ac.uk>
Date: Mon, 18 Jul 2022 12:39:05 +0000
Subject: [PATCH] Update assignment/assignment.cpp

---
 assignment/assignment.cpp | 141 ++++++++++++++++++++++++++++++++------
 1 file changed, 119 insertions(+), 22 deletions(-)

diff --git a/assignment/assignment.cpp b/assignment/assignment.cpp
index 70526fd..24c3345 100644
--- a/assignment/assignment.cpp
+++ b/assignment/assignment.cpp
@@ -109,27 +109,6 @@ void MyApp::begin()
 	// Init the font used for UI text.
 	UI_font = create_font("./assets/fonts/FreeSans.ttf", 15, uwe::Colour::white());
 	
-	// Adjust ball X/Y values
-	ball_x = 400;
-	ball_y = 600;
-	
-	// Randomise the X gradient for the start.
-	random_x = rand() % 1 - 2;
-	
-	switch (random_x)
-	{
-		case 1:
-		ball_gradient_x = -1;
-		break;
-		
-		case 2:
-		ball_gradient_x = 1;
-		break;
-	}
-	
-	// Set the Y gradient for the ball.
-	ball_gradient_y = -1;
-	
 }
 
 // This functions occur every frame (60 times per second)
@@ -144,7 +123,7 @@ void MyApp::update()
 		ball_x_topleft = ball_x - 10;
 		ball_y_topleft = ball_y - 10;
 		
-		// Update ball X/Y
+		// Update ball X/Y - in other words, move the ball based on gradient
 		ball_x = ball_x + ball_gradient_x;
 		ball_y = ball_y + ball_gradient_y;
 		
@@ -280,6 +259,36 @@ void MyApp::key_pressed(uwe::Scancode scancode, bool repeat)
 			{
 				gameplay_active = true;
 				title_active = false;
+
+				// Adjust ball X/Y values
+				ball_x = 400;
+				ball_y = 600;
+
+				// Paddle
+				paddle_x = 400;
+	
+				// Randomise the X gradient for the start.
+				random_x = rand() % 1 - 2;
+	
+				switch (random_x)
+				{
+				case 1:
+				ball_gradient_x = -1;
+				break;
+		
+				case 2:
+				ball_gradient_x = 1;
+				break;
+				}
+	
+				// Set the Y gradient for the ball.
+				ball_gradient_y = -1;
+
+				// Reset time
+				counter = 0;
+				timer_seconds = 0;
+				timer_minutes = 0;
+
 			}
 
 			// If gameplay active and the paddle isn't touching the left wall
@@ -293,6 +302,36 @@ void MyApp::key_pressed(uwe::Scancode scancode, bool repeat)
 			{
 				gameplay_active = true;
 				gameover_active = false;
+
+				// Adjust ball X/Y values
+				ball_x = 400;
+				ball_y = 600;
+
+				// Paddle
+				paddle_x = 400;
+	
+				// Randomise the X gradient for the start.
+				random_x = rand() % 1 - 2;
+	
+				switch (random_x)
+				{
+				case 1:
+				ball_gradient_x = -1;
+				break;
+		
+				case 2:
+				ball_gradient_x = 1;
+				break;
+				}
+	
+				// Set the Y gradient for the ball.
+				ball_gradient_y = -1;
+
+				// Reset time
+				counter = 0;
+				timer_seconds = 0;
+				timer_minutes = 0;
+
 			}
 
 		}
@@ -305,6 +344,35 @@ void MyApp::key_pressed(uwe::Scancode scancode, bool repeat)
 			{
 				gameplay_active = true;
 				title_active = false;
+
+				// Adjust ball X/Y values
+				ball_x = 400;
+				ball_y = 600;
+
+				// Paddle
+				paddle_x = 400;
+	
+				// Randomise the X gradient for the start.
+				random_x = rand() % 1 - 2;
+	
+				switch (random_x)
+				{
+				case 1:
+				ball_gradient_x = -1;
+				break;
+		
+				case 2:
+				ball_gradient_x = 1;
+				break;
+				}
+	
+				// Set the Y gradient for the ball.
+				ball_gradient_y = -1;
+
+				// Reset time
+				counter = 0;
+				timer_seconds = 0;
+				timer_minutes = 0;
 			}
 
 			// If gameplay active and the paddle isn't touching the right wall
@@ -318,6 +386,35 @@ void MyApp::key_pressed(uwe::Scancode scancode, bool repeat)
 			{
 				gameplay_active = true;
 				gameover_active = false;
+
+				// Adjust ball X/Y values
+				ball_x = 400;
+				ball_y = 600;
+
+				// Paddle
+				paddle_x = 400;
+	
+				// Randomise the X gradient for the start.
+				random_x = rand() % 1 - 2;
+	
+				switch (random_x)
+				{
+				case 1:
+				ball_gradient_x = -1;
+				break;
+		
+				case 2:
+				ball_gradient_x = 1;
+				break;
+				}
+	
+				// Set the Y gradient for the ball.
+				ball_gradient_y = -1;
+
+				// Reset time
+				counter = 0;
+				timer_seconds = 0;
+				timer_minutes = 0;
 			}
 		}
 
-- 
GitLab