Advertisement
Guest User

Falling Skies Part 4

a guest
Oct 20th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. import turtle
  2. import time
  3. import random
  4.  
  5.  
  6. wn = turtle.Screen()
  7. wn.title("They fall, @Pissa6947, code my by Christian Thompson")
  8. wn.bgcolor("green")
  9. wn.setup(width=800, height=600)
  10. wn.tracer(0)
  11.  
  12.  
  13.  
  14. # Add the player
  15. player = turtle.Turtle()
  16. player.speed(0)
  17. player.shape("square")
  18. player.color("white")
  19. player.penup()
  20. player.goto(0, -250)
  21. player.direction = "stop"
  22.  
  23. # create a list for Charlie's
  24. Charlies = []
  25.  
  26. # Add the Charlie
  27. for _ in range(20):
  28.     Charlie = turtle.Turtle()
  29.     Charlie.speed(0)
  30.     Charlie.shape("circle")
  31.     Charlie.color("pink")
  32.     Charlie.penup()
  33.     Charlie.goto(0, 250)
  34.     Charlies.append(Charlies)
  35.  
  36.  
  37.  
  38. # Functions
  39. def go_left():
  40.     player.direction = "left"
  41.  
  42.  
  43. def go_right():
  44.     player.direction = "right"
  45.  
  46. wn.listen()
  47. wn.onkeypress(go_left, "Left")
  48. wn.onkeypress(go_right, "Right")
  49.  
  50. # Main game loop
  51. while True:
  52.     time.sleep(0.1)
  53.     # Update screen
  54.     wn.update()
  55.  
  56.     # Move the player
  57.     if player.direction == "left":
  58.         x = player.xcor()
  59.         x -= 3
  60.         player.setx(x)
  61.  
  62.     if player.direction == "right":
  63.         x = player.xcor()
  64.         x += 3
  65.         player.setx(x)
  66.  
  67.  
  68.     # move Charlie
  69.     for Charlie in Charlies:
  70.         y = Charlie.ycor()
  71.         y -= 3
  72.         Charlie.sety(y)
  73.  
  74.  
  75.         # check if Charlie is of screen
  76.         if y < -300:
  77.            x = random.randint(-380, 380)
  78.            y = random.randint(-300, 400)
  79.            Charlie.goto(0, 250)
  80.  
  81.  
  82.         # check for a collision with the player
  83.         if Charlie.distance(player) < 20:
  84.            x = random.randint(-380, 380)
  85.            y = random.randint(-300, 400)
  86.            Charlie.goto(x, y)
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. wn.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement