Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- wn = turtle.Screen()
- wn.title("Pong By Cam")
- wn.bgcolor("black")
- wn.setup(width=800, height=600)
- wn.tracer(0)
- #Paddle A
- Hit = turtle.Turtle()
- Hit.speed(0)
- Hit.shape("square")
- Hit.color("white")
- Hit.shapesize(stretch_wid=5, stretch_len=1)
- Hit.penup()
- Hit.goto(-350, 0)
- #Paddle B
- Hitt = turtle.Turtle()
- Hitt.speed(0)
- Hitt.shape("square")
- Hitt.color("white")
- Hitt.shapesize(stretch_wid=5, stretch_len=1)
- Hitt.penup()
- Hitt.goto(350, 0)
- #Ball
- Ball = turtle.Turtle()
- Ball.speed(0)
- Ball.shape("square")
- Ball.color("white")
- Ball.penup()
- Ball.goto(0, 0)
- Ball.dx = 2
- Ball.dy = 2
- #Functions
- def Hit_up():
- y = Hit.ycor()
- y += 20
- Hit.sety(y)
- def Hit_down():
- y = Hit.ycor()
- y -= 20
- Hit.sety(y)
- def Hitt_up():
- y = Hitt.ycor()
- y += 20
- Hitt.sety(y)
- def Hitt_down():
- y = Hitt.ycor()
- y -= 20
- Hitt.sety(y)
- #Keyboard binding
- wn.listen()
- wn.onkeypress(Hit_up, "w")
- wn.onkeypress(Hit_down, "s")
- wn.onkeypress(Hitt_up, "Up")
- wn.onkeypress(Hitt_down, "Down")
- #Main game loop
- while True:
- wn.update()
- #Move the ball
- Ball.setx(Ball.xcor() + Ball.dx)
- Ball.sety(Ball.ycor() + Ball.dy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement