Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Python Game Programming Tutorial: Space Invaders 2

a guest May 22nd, 2018 77 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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.pendown()
  14. border_pen.pensize(3)
  15. for side in range (4):
  16.     border_pen.fd(600)
  17.     border_pen.lt(90)
  18. border_pen.hideturtle()
  19.  
  20. player = turtle.Turtle()
  21. player.color("blue")
  22. player.shape("triangle")
  23. player.penup()
  24. player.speed(0)
  25. player.setposition(0, -250)
  26. player.setheading(90)
  27.  
  28. playerspeed = 15
  29.  
  30. def move_left():
  31.     x = player.xcor()
  32.     x -= playerspeed
  33.     if x < -280:
  34.         x = - 280
  35.     player.setx(x)
  36.  
  37. def move_right():
  38.     x = player.xcor()
  39.     x += playerspeed
  40.     if x > 280:
  41.         x = 280
  42.     player.setx(x)    
  43.  
  44.     wn.listen()
  45.     wn.onkey(move_left, "Left")
  46.     wn.onkey(move_right, "Right")
  47.  
  48.  
  49.  
  50.  
  51. delay = input("Press enter to finsh.")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top