How can i use the turtle module to move up?

M

M B

Guest
I am creating the space invaders game using turtle module. I have added the code to enable me to move left and right. I want to move the turtle Up/going forward. Any suggestions?

# Create Player Turtle

player = turtle.Turtle()
player.color("green")
player.shape("triangle")
player.penup()
player.speed(0)
player.setposition(0, -250)
player.setheading(90)

playerSpeed = 30


# Move the player Left and Right

def move_left():
x = player.xcor()
x -= playerSpeed
if x < -280: #less then
x = - 280 #set it to
player.setx(x)


def move_right():
x = player.xcor()
x += playerSpeed
if x > 280: #greater than
x = 280 #set it to
player.setx(x)


def move_up():
y = player.ycor()
y -= playerSpeed

# Create keyboard bindings
turtle.listen()
turtle.onkey(move_left, "Left")
turtle.onkey(move_right, "Right")
turtle.onkey(move_up, "Up")



turtle.mainloop()

Continue reading...
 
Top