Untitled
unknown
plain_text
2 years ago
1.2 kB
6
Indexable
import turtle
# Set up the screen.
screen = turtle.Screen()
screen.setup(width=800, height=600)
screen.bgcolor("black")
# Create the paddles.
left_paddle = turtle.Turtle()
left_paddle.shape("square")
left_paddle.color("blue")
left_paddle.speed(0)
left_paddle.penup()
left_paddle.goto(-350, 0)
right_paddle = turtle.Turtle()
right_paddle.shape("square")
right_paddle.color("red")
right_paddle.speed(0)
right_paddle.penup()
right_paddle.goto(350, 0)
# Create the ball.
ball = turtle.Turtle()
ball.shape("circle")
ball.color("white")
ball.speed(0)
ball.penup()
ball.goto(0, 0)
# Set up the game loop.
while True:
# Check for collisions with the paddles.
if ball.xcor() < -350:
ball.xcor() = -350
ball.left(180)
elif ball.xcor() > 350:
ball.xcor() = 350
ball.right(180)
# Check for collisions with the top and bottom of the screen.
if ball.ycor() < -200:
ball.ycor() = -200
ball.up()
elif ball.ycor() > 200:
ball.ycor() = 200
ball.down()
# Move the paddles.
if event.type == "UP":
left_paddle.up()
elif event.type == "DOWN":
left_paddle.down()
# Move the ball.
ball.xcor() += ball.xspeed
ball.Editor is loading...