Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- wn = turtle.Screen()
- wn.title ("Adrian's crappy Pong game")
- wn.bgcolor("black")
- wn.setup(width=800 , height=600)
- wn.tracer(0)
- #Scoring
- pen = turtle.Turtle()
- pen.speed(0)
- pen.color("white")
- pen.penup()
- pen.hideturtle()
- pen.goto(-50, 260)
- pen.write("Nigga A:0 Nigga B:0", align="center", font=("Courier", 24 ,"normal"))
- score_a = 0
- score_b = 0
- #Long Stick A
- longstick_a = turtle.Turtle()
- longstick_a.speed(0)
- longstick_a.shape("square")
- longstick_a.color("red")
- longstick_a.shapesize(stretch_wid=5 , stretch_len=1)
- longstick_a.penup()
- longstick_a.goto(-350, 0)
- #Long Stick B
- longstick_b = turtle.Turtle()
- longstick_b.speed(0)
- longstick_b.shape("square")
- longstick_b.color("red")
- longstick_b.shapesize(stretch_wid=5 , stretch_len=1)
- longstick_b.penup()
- longstick_b.goto(+350, 0)
- #Ball
- Ball = turtle.Turtle()
- Ball.speed(0)
- Ball.shape("circle")
- Ball.color("white")
- Ball.penup()
- Ball.goto(0, 0)
- Ball.dx = 0.2
- Ball.dy = 0.3
- #Functions
- def longstick_b_up():
- y = longstick_b.ycor()
- y += 20
- longstick_b.sety(y)
- def longstick_b_down():
- y = longstick_b.ycor()
- y -= 20
- longstick_b.sety(y)
- def longstick_a_up():
- y = longstick_a.ycor()
- y += 20
- longstick_a.sety(y)
- def longstick_a_down():
- y = longstick_a.ycor()
- y -= 20
- longstick_a.sety(y)
- #Keyboard binding
- wn.listen()
- wn.onkeypress(longstick_a_up, "w" )
- wn.onkeypress(longstick_a_down, "s")
- wn.onkeypress(longstick_b_up, "Up" )
- wn.onkeypress(longstick_b_down, "Down")
- #Main game loop dont forget it moron
- while True:
- wn.update()
- #Move Ball
- Ball.setx(Ball.xcor() + Ball.dx)
- Ball.sety(Ball.ycor() + Ball.dy)
- #Trumps Wall
- if Ball.ycor() < -290:
- Ball.sety(-290)
- Ball.dy *= -1
- if Ball.ycor() > 290:
- Ball.sety(290)
- Ball.dy *= -1
- if Ball.xcor() > 390:
- Ball.goto(0, 0)
- Ball.dx *= -1
- score_a += 1
- pen.clear()
- pen.write("Nigga A: {} Nigga B: {}". format(score_a, score_b), align="center", font=("Courier", 24 ,"normal"))
- if Ball.xcor() < -390:
- Ball.goto(0, 0)
- Ball.dx *= -1
- score_b += 1
- pen.clear()
- pen.write("Nigga A: {} Nigga B: {}". format(score_a, score_b), align="center", font=("Courier", 24 ,"normal"))
- #Collisions
- if Ball.xcor() > 340 and (Ball.ycor() < longstick_b.ycor() + 40 and Ball.ycor() > longstick_b.ycor() - 50):
- Ball.dx *= -1
- Ball.setx(340)
- if Ball.xcor() < -340 and (Ball.ycor() < longstick_a.ycor() + 40 and Ball.ycor() > longstick_a.ycor() - 50):
- Ball.dx *= -1
- Ball.setx(-340)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement