Advertisement
CoderEbraheem

code for tokyoed

Nov 24th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import turtle
  2. import os
  3.  
  4. wn = turtle.Screen()
  5. wn.bgcolor("black")
  6. wn.title("Space Invaders")
  7.  
  8. border_pen = turtle.Turtle()
  9. border_pen.speed(0)
  10. border_pen.color("white")
  11. border_pen.penup()
  12. border_pen.setposition(-300,-300)
  13. border_pen.pensize(3)
  14. for side in range(4):
  15. border_pen.fd(600)
  16. border_pen.lt(90)
  17. border_pen.hideturtle()
  18.  
  19. player = turtle.Turtle()
  20. player.color("blue")
  21. player.shape("triangle")
  22. player.penup()
  23. player.speed(0)
  24. player.setposition(0, -250)
  25. player.setheading(90)
  26.  
  27. playerspeed = 15
  28.  
  29. def move_left():
  30. x = player.xcor()
  31. x -= playerspeed
  32. if x < -280:
  33. x = -280
  34. player.setx(x)
  35.  
  36. def move_right():
  37. x = player.xcor()
  38. x += playerspeed
  39. if x > 280:
  40. x = 280
  41. player.setx(x)
  42.  
  43. turtle.listen()
  44. turtle.onkey(move_left, "Left")
  45. turtle.onkey(move_right, "Right")
  46.  
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement