Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This program allows the user to control two turtles with the keyboard.
- from turtle import *
- print("Use arrow keys to move the green turtle.")
- print("Use the w, d, a, and s keys to move the red turtle")
- #These two variables make two turtles.
- turtle_1 = Turtle()
- turtle_2 = Turtle()
- #These two lines of code pick the turtle color.
- turtle_1.color("red")
- turtle_2.color("green")
- #These two lines of code pick the shape of the turtle.
- turtle_1.shape("turtle")
- turtle_2.shape("turtle")
- #This function moves turtle_1 up 3.
- def move_up_1():
- turtle_1.setheading(90)
- turtle_1.forward(30)
- #This function moves turtle_1 right 3.
- def move_right_1():
- turtle_1.setheading(0)
- turtle_1.forward(30)
- #This function moves the turtle down 3.
- def move_down_1():
- turtle_1.setheading(270)
- turtle_1.forward(30)
- #This function moves the turtle left 3.
- def move_left_1():
- turtle_1.setheading(180)
- turtle_1.forward(30)
- #This function moves the turtle up 2.
- def move_up_2():
- turtle_2.setheading(90)
- turtle_2.forward(30)
- #This function moves the turtle right 2.
- def move_right_2():
- turtle_2.setheading(0)
- turtle_2.forward(30)
- #This function moves the turtle down 2.
- def move_down_2():
- turtle_2.setheading(270)
- turtle_2.forward(30)
- #This function moves the turtle left 2.
- def move_left_2():
- turtle_2.setheading(180)
- turtle_2.forward(30)
- listen()
- #The functions below shows what keys move the turtle
- onkey(move_up_1, "Up")
- onkey(move_right_1, "Right")
- onkey(move_left_1, "Left")
- onkey(move_down_1, "Down")
- onkey(move_up_2, "w")
- onkey(move_right_2, "d")
- onkey(move_left_2, "a")
- onkey(move_down_2, "s")
- exitonclick()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement