Advertisement
shh_algo_PY

Easter Eggs!

Apr 10th, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.60 KB | None | 0 0
  1. import play
  2. import time
  3. from random import randint
  4.  
  5. frames = 48
  6.  
  7. score = 0
  8. finish = False
  9.  
  10. # Setting up the screen
  11.  
  12. hello_txt = play.new_text(words='Catch them all!', x=0, y=play.screen.height/2-30)
  13.  
  14. hello_txt.color = (120, 120, 120)
  15.  
  16. score_txt = play.new_text(words='0', x=play.screen.width/2-80, y=play.screen.height/2-30, color='gold')
  17. help_txt = play.new_text(words="Use 'q', 'a', 'e', 'd' keys", x=0, y=-play.screen.height/2+30)
  18.  
  19. # Adding in your characters
  20.  
  21. bunny = play.new_image(image='easter-bunny-1.png', x=0, y=20)
  22. bowl = play.new_image(image='bowl.png', x=100,  y=80, size=40)
  23.  
  24. # Making sure your eggs have 4 starting points
  25.  
  26. egg_x = [400, -380]
  27. egg_y = [200, 50]
  28. eggs = []
  29.  
  30. # Starts the time counter
  31.  
  32. old_time=0
  33.  
  34. # How to make a new egg
  35.  
  36. def new_egg():
  37.     egg = play.new_circle(
  38.         color=(255, 212, 59),
  39.         x=egg_x[randint(0, 1)],
  40.         y=egg_y[randint(0, 1)],
  41.         radius=12,
  42.         border_color=(75, 139, 190),
  43.         border_width=5
  44.     )
  45.     egg.start_physics(mass=1, friction=0.7)
  46.     eggs.append(egg)
  47.  
  48. # How to make the shelves
  49.  
  50. def add_shelf(x, y, a):
  51.     shelf = play.new_box(x=x, y=y, width=300, height=10, angle=a)
  52.     shelf.color = (48, 105, 152)
  53.     shelf.start_physics(can_move=False, mass=10, friction=1.0)
  54.  
  55. # Setting up the time and shelves
  56.  
  57. @play.when_program_starts
  58. def start():
  59.     global old_time
  60.     old_time = time.time()
  61.  
  62.     add_shelf(300, 150, 20)
  63.     add_shelf(300, 0, 20)
  64.     add_shelf(-300, 150, -20)
  65.     add_shelf(-300, 0, -20)
  66.     new_egg()
  67.  
  68. # How to catch the eggs
  69.  
  70. @play.repeat_forever
  71. async def game():
  72.     global score, finish, old_time
  73.  
  74.     if play.key_is_pressed('e'):
  75.         bowl.x = 100
  76.         bowl.y = 80
  77.     if play.key_is_pressed('d'):
  78.         bowl.x = 100
  79.         bowl.y = -70
  80.     if play.key_is_pressed('q'):
  81.         bowl.x = -100
  82.         bowl.y = 80
  83.     if play.key_is_pressed('a'):
  84.         bowl.x = -100
  85.         bowl.y = -70    
  86.  
  87.     if time.time()-old_time > 3:
  88.         new_egg()
  89.         old_time = time.time()
  90.  
  91. # WINNING/ LOSING CHECK
  92.  
  93.     for egg in eggs:
  94.         if egg.y < -250:
  95.             hello_txt.words = "That's all folks!"
  96.             hello_txt.color = 'red'
  97.             quit()
  98.         if egg.is_touching(bowl):
  99.             egg.hide()
  100.             eggs.remove(egg)
  101.             score = score + 1
  102.             score_txt.words = score
  103.  
  104.     if score == 10:
  105.         hello_txt.words = "You win!"
  106.         hello_txt.color = 'yellow'
  107.  
  108.     await play.timer(seconds=1/frames)
  109.  
  110. # Signal to start
  111.  
  112. play.start_program()
  113.  
  114. # Don't forget to run and check your code :D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement