import turtle
player = {"name": "Player 1", "turtle" : turtle.Turtle(), "color":"blue", "radius": 10, "move_distance" : 5 }
#TODO: hide the player turtle
screen = player["turtle"].getscreen()
def up():
print("starting up")
t = player["turtle"] # for convenience
t.clear()
current_y = t.ycor()
# TODO: add the player's move distance to the current y
t.sety(new_y)
# TODO: use the player's radius
t.dot()
# TODO: create down, left and right functions
screen.onkey(up, "Up")
# TODO: hook up key event handlers so that arrow keys trigger appropriate function
# Can multiple keys trigger the same function? Give it a try
screen.listen()
Ans:
'''
The required program in turtle python can be implemented in the following manner so as to satisfy the above mentioned TODO's:
'''
# PROGRAM :
import turtle
player = {"name": "Player 1", "turtle" : turtle.Turtle(), "color":"blue", "radius": 10, "move_distance" : 5 }
#TODO: hide the player turtle
player["turtle"].hideturtle() # to hide the turtle
screen = player["turtle"].getscreen()
def up():
print("starting up")
t = player["turtle"] # for convenience
t.clear()
current_y = t.ycor()
# TODO: add the player's move distance to the current y
new_y = current_y + player["move_distance"]
t.sety(new_y)
# TODO: use the player's radius
t.dot(player["radius"])
# TODO: create down, left and right functions
def down():
print("starting down")
def left():
print("starting left")
def right():
print("starting right")
screen.onkey(up, "Up")
# TODO: hook up key event handlers so that arrow keys trigger appropriate function
screen.onkey(down, "Down")
screen.onkey(left, "Left")
screen.onkey(right, "Right")
# Can multiple keys trigger the same function? Give it a
try
'''
no! on trying multiple keys at the same time the same function
doesn't
get invoked! Separate functions is needed to handle such an
event
'''
screen.listen()
# OUTPUT OF A SAMPLE RUN:
# PLEASE DO LIKE AND UPVOTE IF THIS WAS HELPFUL!
# THANK YOU SO MUCH IN ADVANCE!
Get Answers For Free
Most questions answered within 1 hours.