I have made a program to move turtle position by pressing the keyboard, but is there a way to make it move in smaller increments of pixels?
and also, is it possible to move turtle up and down instead of only left and right?
from turtle import Screen, Turtle
TURTLE_SIZE = 200
# functions
def go_left():
t.direction = 'left'
def go_right():
t.direction = 'right'
screen = Screen()
screen.setup(1152,648)
screen.tracer(0)
# player
t = Turtle()
t.shape("circle")
t.speed("slowest")
t.color("blue")
t.penup()
t.setx(338)
t.sety(0)
t.direction = 'stop'
# Keyboard
screen.onkeypress(go_left, 'Left')
screen.onkeypress(go_right, 'Right')
screen.listen()
while True:
x = t.xcor()
if t.direction == 'left':
if x > TURTLE_SIZE - 576:
x -= 3
t.setx(x)
else:
t.direction = 'stop'
elif t.direction == 'right':
if x < 576 - TURTLE_SIZE:
x += 3
t.setx(x)
else:
t.direction = 'stop'
screen.update()
screen.mainloop()