Guest User

Untitled

a guest
Jul 17th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. import random
  2. import turtle as t
  3.  
  4.  
  5. #Creating the snake
  6.  
  7. caterpillar = t.Turtle()
  8. caterpillar.shape('square')
  9. caterpillar.color('red')
  10. caterpillar.speed(0)
  11. caterpillar.penup()
  12. caterpillar.hideturtle()
  13.  
  14.  
  15. # Creating the powerup
  16.  
  17. leaf = t.Turtle()
  18. leaf_shape = ((0,0), (14,2), (18,6), (20,20), (6,18), (2,14))
  19. t.register_shape('leaf', leaf_shape)
  20. leaf.shape('leaf')
  21. leaf.color('green')
  22. leaf.penup()
  23. leaf.hideturtle()
  24. leaf.speed(0)
  25.  
  26.  
  27. # Settling our score
  28.  
  29. game_started = False
  30. text_turtle = t.Turtle()
  31. text_turtle.write('Press SPACE to start', align = 'center', font ('Arial',16,'bold'))
  32. text_turtle.hideturtle()
  33.  
  34. score_turtle - t.Turtle()
  35. score_turtle.hideturtle()
  36. score_turtle.speed(0)
  37.  
  38. # Game functions
  39.  
  40. def outside_window():
  41. pass
  42. def game_over():
  43. pass
  44. def display_score(current_score):
  45. pass
  46. def place_leaf():
  47. pass
  48. def start_game():
  49.  
  50. global game_started
  51.  
  52. if game_started:
  53.  
  54. return
  55.  
  56. game_started = true
  57.  
  58. score = 0
  59. text_turtle.clear()
  60.  
  61. caterpillar_speed = 2
  62. caterpillar_length = 3
  63. caterpillar.shapesize(1, caterpillar_length, 1)
  64. caterpillar.showturtle()
  65. display_score(score)
  66. place_leaf()
  67.  
  68. # Game Drivers
  69.  
  70. while True:
  71.  
  72. caterpillar.forward(caterpillar_speed)
  73.  
  74. if caterpillar.distance(leaf) < 20:
  75.  
  76. place_leaf()
  77. caterpillar_length = caterpillar_length + 1
  78. caterpillar_speed = caterpillar_speed + 1
  79. score = score + 10
  80. display_score(score)
  81.  
  82. if outside_window():
  83. game_over()
  84. break
  85.  
  86. t.onkey(start_game, 'space')
  87. t.listen()
  88. t.mainloop()
  89.  
  90. score_turtle - t.Turtle()
  91. text_turtle.write('Press SPACE to start', align = 'center', font ('Arial',16,'bold'))
  92.  
  93. score_turtle = t.Turtle()
  94. text_turtle.write('Press SPACE to start', align='center', font=('Arial',16,'bold'))
  95.  
  96. from turtle import Turtle, Screen
  97.  
  98. # Game functions
  99.  
  100. def outside_window():
  101. return False # implement this for real
  102.  
  103. def game_over():
  104. pass # implement this for real
  105.  
  106. def display_score(current_score):
  107. pass # implement this for real
  108.  
  109. def place_leaf():
  110. leaf.hideturtle()
  111. leaf.goto(100, 100) # implement this for real
  112. leaf.showturtle()
  113.  
  114. def start_game():
  115. global score
  116. global caterpillar_speed
  117. global caterpillar_length
  118.  
  119. screen.onkey(None, 'space')
  120.  
  121. score = 0
  122. text_turtle.clear()
  123.  
  124. caterpillar_speed = 2
  125. caterpillar_length = 3
  126. caterpillar.shapesize(1, caterpillar_length, 1)
  127. caterpillar.showturtle()
  128.  
  129. display_score(score)
  130. place_leaf()
  131. crawl()
  132.  
  133. # Game Drivers
  134.  
  135. def crawl():
  136. global score
  137. global caterpillar_speed
  138. global caterpillar_length
  139.  
  140. caterpillar.forward(caterpillar_speed)
  141.  
  142. if caterpillar.distance(leaf) < 20:
  143.  
  144. place_leaf()
  145.  
  146. caterpillar_speed = caterpillar_speed + 1
  147. caterpillar_length = caterpillar_length + 1
  148. caterpillar.shapesize(1, caterpillar_length, 1)
  149.  
  150. score = score + 10
  151. display_score(score)
  152.  
  153. if outside_window():
  154. game_over()
  155. else:
  156. screen.ontimer(crawl, 100)
  157.  
  158. screen = Screen()
  159.  
  160. # Creating the powerup
  161.  
  162. leaf_shape = ((0, 0), (14, 2), (18, 6), (20, 20), (6, 18), (2, 14))
  163. screen.register_shape('leaf', leaf_shape)
  164.  
  165. leaf = Turtle('leaf', visible=False)
  166. leaf.color('green')
  167. leaf.speed('fastest')
  168. leaf.penup()
  169.  
  170. # Creating the caterpillar
  171.  
  172. caterpillar = Turtle('square', visible=False)
  173. caterpillar.color('red')
  174. caterpillar.speed('fastest')
  175. caterpillar.penup()
  176.  
  177. # Settling our score
  178.  
  179. text_turtle = Turtle(visible=False)
  180. text_turtle.write('Press SPACE to start', align='center', font=('Arial', 16, 'bold'))
  181.  
  182. score_turtle = Turtle(visible=False)
  183.  
  184. screen.onkey(start_game, 'space')
  185. screen.listen()
  186. screen.mainloop()
Add Comment
Please, Sign In to add comment