From d5f65eb6cc7d5107b6a9878f46cc02a9a8fda549 Mon Sep 17 00:00:00 2001 From: 12903783 <dylan.swain@student.uts.edu.au> Date: Mon, 21 Oct 2019 18:06:13 +1100 Subject: [PATCH] Fixed score and added 2nd turtle obstacle. --- turtle-tennis | 68 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/turtle-tennis b/turtle-tennis index 0bc4962..81be331 100644 --- a/turtle-tennis +++ b/turtle-tennis @@ -67,7 +67,7 @@ scoreboard2.pendown() score_2 = 0 scoreboard2.write("{}".format(score_2), font=("Arial Black", "60")) -#Obstacle +#Obstacles obstacle = turtle.Turtle() obstacle.shape("turtle") obstacle.color("brown") @@ -75,6 +75,13 @@ obstacle.penup() obstacle.goto(100,-150) obstacle.shapesize(3,3) +obstacle2 = turtle.Turtle() +obstacle2.shape("turtle") +obstacle2.color("purple") +obstacle2.penup() +obstacle2.goto(-50,110) +obstacle2.shapesize(4,4) + #Movement def racquet1up(): @@ -117,12 +124,27 @@ while True: ball.sety(0) ball.showturtle() ball.dx *= -1 - score_1 += 15 + score_1 += 1 + if score_1 == 1: + scoreboard1.clear() + scoreboard1.write("{}".format(15), font=("Arial Black", "60")) + score_1 += 0.1 + if score_1 == 2.1: + scoreboard1.clear() + scoreboard1.write("{}".format(30), font=("Arial Black", "60")) + score_1 += 0.1 + if score_1 == 3.2: scoreboard1.clear() - scoreboard1.write("{}".format(score_1), font=("Arial Black", "60")) - if score_1 > 41: + scoreboard1.write("{}".format(40), font=("Arial Black", "60")) + score_1 += 0.1 + if (score_1 > 4.3 and score_2 < 4.3): scoreboard1.clear() - scoreboard1.write("{}".format(score_1 -5), font=("Arial Black", "60")) + scoreboard1.penup() + scoreboard1.setx(-230) + scoreboard1.write("Winner", font=("Arial Black", "40")) + scoreboard2.clear() + scoreboard2.write("Loser", font=("Arial Black", "40")) + break if ball.ycor() < -290: ball.sety(-290) ball.dy *= -1 @@ -132,17 +154,41 @@ while True: ball.sety(0) ball.showturtle() ball.dx *= -1 - score_2 += 15 + score_2 += 1 + if score_2 == 1: + scoreboard2.clear() + scoreboard2.write("{}".format(15), font=("Arial Black", "60")) + score_2 += 0.1 + if score_2 == 2.1: + scoreboard2.clear() + scoreboard2.write("{}".format(30), font=("Arial Black", "60")) + score_2 += 0.1 + if score_2 == 3.2: scoreboard2.clear() - scoreboard2.write("{}".format(score_2), font=("Arial Black", "60")) - if score_2 > 41: - scoreboard2.clear - scoreboard2.write("{}".format(score_1 -5), font=("Arial Black", "60")) + scoreboard2.write("{}".format(40), font=("Arial Black", "60")) + score_2 += 0.1 + if (score_2 > 4.3 and score_1 < 4.3): + scoreboard2.clear() + scoreboard2.write("Winner", font=("Arial Black", "40")) + scoreboard1.clear() + scoreboard1.penup() + scoreboard1.setx(-210) + scoreboard1.write("Loser", font=("Arial Black", "40")) + break if (ball.xcor() > 275 and ball.xcor() < 285) and (ball.ycor() < racquet2.ycor() +100 and ball.ycor() > racquet2.ycor() -100): ball.dx *= -1 if (ball.xcor() < -275 and ball.xcor() > -285) and (ball.ycor() < racquet1.ycor() +100 and ball.ycor() > racquet1.ycor() -100): ball.dx *= -1 if (ball.xcor() > obstacle.xcor() -20 and ball.xcor() < obstacle.xcor() + 20) and (ball.ycor() > obstacle.ycor() -20 and ball.ycor() < obstacle.ycor() + 20): - ball.dx *= -1 + obstacle.color("red") obstacle.left(475) obstacle.forward(200) + ball.showturtle() + ball.dx *= -1 + obstacle.color("brown") + if (ball.xcor() > obstacle2.xcor() -30 and ball.xcor() < obstacle2.xcor() + 30) and (ball.ycor() > obstacle2.ycor() -30 and ball.ycor() < obstacle2.ycor() + 30): + obstacle2.color("red") + ball.dx *= -1 + obstacle2.right(510) + obstacle2.forward(100) + obstacle2.color("purple") -- GitLab