Commit b7ab1769 authored by 12903783's avatar 12903783
Browse files

Paddles now move correctly. Ball moves. Setup boundaries. Changed colours.

parent c86f5474
......@@ -2,13 +2,13 @@ import turtle
wn = turtle.Screen()
wn.setup(width=800, height=600)
wn.bgcolor ("black")
wn.bgcolor ("#0fb300")
#Paddle 1
paddle1 = turtle.Turtle()
paddle1.hideturtle()
paddle1.shape("square")
paddle1.color("white")
paddle1.color("red")
paddle1.shapesize(10,1,5)
paddle1.penup()
paddle1.setx(-300)
......@@ -18,7 +18,7 @@ paddle1.showturtle()
paddle2 = turtle.Turtle()
paddle2.hideturtle()
paddle2.shape("square")
paddle2.color("white")
paddle2.color("blue")
paddle2.shapesize(10,1,5)
paddle2.penup()
paddle2.setx(300)
......@@ -26,9 +26,11 @@ paddle2.showturtle()
#Ball
ball = turtle.Turtle()
ball.shape("square")
ball.color("white")
ball.shape("circle")
ball.color("#d2fc03")
ball.penup()
ball.dx = 4
ball.dy = 4
#Scoreboard
scoreboard = turtle.Turtle()
......@@ -39,4 +41,49 @@ scoreboard.penup()
scoreboard.setx(-110)
scoreboard.sety(200)
scoreboard.pendown()
scoreboard.write("0 0", font=("Arial Black", "60"))
\ No newline at end of file
scoreboard.write("0 0", font=("Arial Black", "60"))
#Movement
def paddle1up():
y = paddle1.ycor()
y += 20
paddle1.sety(y)
def paddle1down():
y = paddle1.ycor()
y -= 20
paddle1.sety(y)
def paddle2up():
y = paddle2.ycor()
y += 20
paddle2.sety(y)
def paddle2down():
y = paddle2.ycor()
y -= 20
paddle2.sety(y)
#Controls
wn.listen()
wn.onkeypress(paddle1up, "w")
wn.onkeypress(paddle1down, "s")
wn.onkeypress(paddle2up, "k")
wn.onkeypress(paddle2down, "m")
while True:
ball.setx(ball.xcor() + ball.dx)
ball.sety(ball.ycor() + ball.dy)
if ball.ycor() > 290:
ball.sety(290)
ball.dy *= -1
if ball.xcor() > 390:
ball.setx(390)
ball.dx *= -1
if ball.ycor() < -290:
ball.sety(-290)
ball.dy *= -1
if ball.xcor() < -390:
ball.setx(-390)
ball.dx *= -1
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment