Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Click in the righthand window to make it active then use your arrow
- # keys to control the spaceship!
- import turtle
- screen = turtle.Screen()
- # this assures that the size of the screen will always be 400x400 ...
- screen.setup(400, 400)
- # ... which is the same size as our image
- # now set the background to our space image
- # https://www.jpl.nasa.gov/spaceimages/details.php?id=pia14417
- # must be converted to PNG file
- screen.bgpic("space.png")
- # Or, set the shape of a turtle
- # https://www.flaticon.com/free-icon/rocket_201901
- screen.addshape("rocket.gif")
- turtle.shape("rocket.gif")
- move_speed = 10
- turn_speed = 20
- # these defs control the movement of our "turtle"
- def forward():
- turtle.forward(move_speed)
- def backward():
- turtle.backward(move_speed)
- def left():
- turtle.left(turn_speed)
- def right():
- turtle.right(turn_speed)
- turtle.update()
- turtle.penup()
- turtle.speed(10)
- turtle.home()
- # now associate the defs from above with certain keyboard events
- screen.onkey(forward, "Up")
- screen.onkey(backward, "Down")
- screen.onkey(left, "Left")
- screen.onkey(right, "Right")
- screen.listen()
Advertisement
Add Comment
Please, Sign In to add comment