Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. import turtle # Our module's
  2. import random
  3.  
  4. score = 0
  5. lives = 3
  6.  
  7.  
  8. # Screen
  9. ms = turtle.Screen()
  10. ms.title("Falling Piece's mini_game by Rafa94")
  11. ms.bgcolor("light blue")
  12. ms.bgpic("C:/Users/Rafael Perez/PycharmProjects/turtle race/venv/farm5.gif")
  13. ms.setup(width=800, height=600)
  14. ms.tracer(0.0)
  15. #ms.exitonclick()
  16.  
  17. # we are uploading the our images the Screen using the register_shape function from our module
  18. ms.register_shape("C:/Users/Rafael Perez/PycharmProjects/turtle race/venv/rooster.gif")# make sure when you upload images make sure your using the right sequence or Path // - C:
  19. ms.register_shape("C:/Users/Rafael Perez/PycharmProjects/turtle race/venv/rooster_right.gif")
  20. ms.register_shape("C:/Users/Rafael Perez/PycharmProjects/turtle race/venv/fireball2.gif")
  21. ms.register_shape("C:/Users/Rafael Perez/PycharmProjects/turtle race/venv/egg3.gif")
  22.  
  23.  
  24.  
  25. # player
  26. player = turtle.Turtle()
  27. player.shape("C:/Users/Rafael Perez/PycharmProjects/turtle race/venv/rooster.gif")
  28. player.color("blue")
  29. player.penup()
  30. player.goto(0, -250) # y is postive in the up direction y is negative in the down direction
  31. player.speed(0)
  32. player.direction = "stop"
  33.  
  34. # make the pen
  35. pen = turtle.Turtle() # also make the pen before any for _ loops or else it will write over its self
  36. pen.hideturtle()
  37. pen.speed(0)
  38. pen.shape("turtle")
  39. pen.color("blue")
  40. pen.penup()
  41. pen.goto(0, 260) # y is postive in the up direction y is negative in the down direction
  42. font = ("Courier", 24, "normal")
  43. pen.clear()
  44. pen.write("Score: {} Lives: {}".format(score, lives), align="center", font=font)
  45.  
  46. # create a list of good players
  47. goods = [] # Empty list
  48.  
  49. # Addgood players
  50. for _ in range(20): # we are making a set of 20 players
  51. good = turtle.Turtle() # we want the other player basically across from each other thats we copyed the code one on -y and one on +y (first player in the bottom, second player on top of Screen)
  52. good.speed(0)
  53. good.shape("C:/Users/Rafael Perez/PycharmProjects/turtle race/venv/egg3.gif")
  54. good.color("red")
  55. good.penup()
  56. good.goto(-100, 250) # y is postive in the up direction y is negative in the down direction
  57. good.speed = random.randint(1, 4)
  58. goods.append(good)
  59.  
  60.  
  61. # create a list of bad players
  62. bads = [] # Empty list
  63.  
  64. # Addbad players
  65. for _ in range(20): # we are making a set of 20 players
  66. bad = turtle.Turtle() # we want the other player basically across from each other thats we copyed the code one on -y and one on +y (first player in the bottom, second player on top of Screen)
  67. bad.speed(0)
  68. bad.shape("C:/Users/Rafael Perez/PycharmProjects/turtle race/venv/fireball2.gif")
  69. bad.color("yellow")
  70. bad.penup()
  71. bad.goto(100, 250) # y is postive in the up direction y is negative in the down direction
  72. bad.speed = random.randint(1, 4)
  73. bads.append(bad)
  74.  
  75.  
  76.  
  77. # Functions
  78. def go_left():
  79. player.direction = "left"
  80. player.shape("C:/Users/Rafael Perez/PycharmProjects/turtle race/venv/rooster.gif")
  81.  
  82.  
  83. def go_right():
  84. player.direction = "right"
  85. player.shape("C:/Users/Rafael Perez/PycharmProjects/turtle race/venv/rooster_right.gif")
  86.  
  87.  
  88.  
  89.  
  90. # keyboard Binding
  91. ms.listen() # it is bascally saying listen for keyboard input < ^ >
  92. ms.onkeypress(go_left, "Left")
  93. ms.onkeypress(go_right, "Right")
  94.  
  95. # Main game loop # while something is true it will repeat
  96. while True:
  97. # update screen
  98. ms.update()
  99.  
  100. # Move player
  101. if player.direction == "left":
  102. x = player.xcor()
  103. x -= + 3
  104. player.setx(x)
  105.  
  106. if player.direction == "right":
  107. x = player.xcor()
  108. x += + 3
  109. player.setx(x)
  110.  
  111. # Move Good Player
  112. for good in goods:
  113. y = good.ycor()
  114. y -= good.speed # We want the ball to be falling at a smooth speed
  115. good.sety(y)
  116. # Check it off the Screen
  117. if y < -300:
  118. x = random.randint(-380, 380)
  119. y = random.randint(300, 400)
  120. good.goto(x, y)
  121.  
  122. # check for collision with player
  123. if good.distance(player) < 20:
  124. x = random.randint(-380, 380)
  125. y = random.randint(300, 400)
  126. good.goto(x, y)
  127. score += 10
  128. pen.clear()
  129. pen.write("Score: {} Lives: {}".format(score, lives), align="center", font=font)
  130.  
  131.  
  132.  
  133. # Move bad Player
  134. for bad in bads:
  135. y = bad.ycor()
  136. y -= bad.speed # We want the ball to be falling at a slow speed
  137. bad.sety(y)
  138. # Check it off the Screen
  139. if y < -300:
  140. x = random.randint(-380, 380)
  141. y = random.randint(300, 400)
  142. bad.goto(x, y)
  143.  
  144. # check for collision with player
  145. if bad.distance(player) < 20:
  146. x = random.randint(-380, 380)
  147. y = random.randint(300, 400)
  148. bad.goto(x, y)
  149. score -= 10
  150. lives -= 1
  151. pen.clear()
  152. pen.write("Score: {} Lives: {}".format(score, lives), align="center", font=font)
  153.  
  154. ms.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement