You are on page 1of 1

import turtle

dx=0.1
dy=0.1
win=turtle.Screen()
win.bgcolor("black")
win.title("brick breaker")
win.setup(width=600,height=600)
win.tracer(0)

#draw paddle
paddle=turtle.Turtle()
paddle.color('white')
paddle.penup()
paddle.shape('square')
paddle.goto(0,-260)
paddle.shapesize(stretch_wid=1,stretch_len=5)

#draw ball
ball=turtle.Turtle()
ball.color('red')
ball.shape('circle')
ball.penup()
ball.setposition(0,-240)
def move_Left():

x=paddle.xcor()
if x>-300:
x-=20
paddle.setx(x)

def move_right():
x=paddle.xcor()
if x<300:
x+=20
paddle.setx(x)
def move():
x=ball.xcor()
y=ball.ycor()
ball.setx(x+dx)
ball.sety(y+dy)

#keyboard binding
win.listen()
win.onkeypress(move_Left,'Left')
win.onkeypress(move_right,'Right')

while True:
win.update()
move()

You might also like