Skip to content

Commit

Permalink
Adding colours
Browse files Browse the repository at this point in the history
Whenever the ball hits one of the paddles, the background colour changes
  • Loading branch information
Yadav106 authored May 28, 2022
1 parent 33df5d6 commit 846a4d9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pingpong.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import turtle
from random import randint

colours = ['blue', 'green', 'black', 'gray', 'purple', '#CC3818', '#C4CC18', '#E448D3', '#B7F10D', '#27714D', '#05854F']

wn = turtle.Screen()
wn.title("Pong by @Yadav")
Expand Down Expand Up @@ -114,7 +117,11 @@ def paddle_b_down():

#Paddle and Ball Collisions
if((ball.xcor()>330) and (ball.ycor()<paddle_b.ycor() + 50) and (ball.ycor()>paddle_b.ycor() - 50) and ball.xcor() < 340):
n = randint(5, 10)
wn.bgcolor(colours[n])
ball.dx *= -1

if((ball.xcor()<-330) and (ball.ycor()<paddle_a.ycor() + 50) and (ball.ycor()>paddle_a.ycor() - 50) and ball.xcor() > -340):
n = randint(0, 4)
wn.bgcolor(colours[n])
ball.dx *= -1

0 comments on commit 846a4d9

Please sign in to comment.