# Pong.
# Player 1 (left side) uses W to move upward and S to move downward
# Player 2 (Right) uses the Up and Down Arrow Keys
# knock the ball back and forth and try not to get it past your paddle
ball = Circle(200,200,15)
[Link] = ["blue",'red','teal']
[Link]=0
# function to color the ball when it hits any wall
def ballColorThingamajig():
[Link] = ([Link] + 1) % len([Link])
print([Link])
for j in range(len([Link])):
if (j == [Link]):
[Link] = [Link][j]
paddle1 = Rect(0,120, 10,50,fill='purple')
paddle2 = Rect (390, 120, 10,50,fill='gold')
#Find a random dx and dy
[Link] = randrange(-5,10)
[Link] = randrange(-5,10)
[Link] = 100
#Labels for score
score1 = Label(0,50,50, size = 20)
score2 = Label(0,350,50, size = 20)
#part that lets the ball move
def onStep():
#move the ball by dx and dy
[Link] += [Link]
[Link] += [Link]
#sends ball back
if ([Link] < 0 or [Link] > 400):
[Link] = -[Link]
ballColorThingamajig()
#score adding
if ([Link] < 12):
[Link] += 1
[Link] = -[Link]
if ([Link] > 388):
[Link]+=1
[Link] = -[Link]
if([Link](paddle1) or [Link](paddle2)):
[Link] = -[Link]
#movement of the paddles
def onKeyHold(keys):
if ( 'up' in keys):
[Link] -= 10
elif ('down' in keys):
[Link] += 10
if ("w" in keys):
[Link] -=10
if ('s' in keys):
[Link]+=10
# the part that swaps the ball colour around
[Link]=0
if ([Link] < 0 or [Link] > 400):
[Link]+=1
if ([Link] == 2):
[Link] = 0