OtsoSilver

Untitled

Sep 19th, 2021
693
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pgzero
  2.  
  3. WIDTH = 600
  4. HEIGHT = 400
  5.  
  6. TITLE = "Animal clicker"
  7. FPS = 30
  8.  
  9. # Объекты
  10. animal = Actor("giraffe", (150, 250))
  11. fon = Actor("fon")
  12. bonus_1 = Actor("bonus", (450, 100))
  13. bonus_2 = Actor("bonus", (450, 200))
  14. price_b1 = 15
  15. price_b2 = 200
  16. # Переменные
  17. count = 0
  18. click = 1
  19.  
  20. def draw():
  21.     fon.draw()
  22.     animal.draw()
  23.     screen.draw.text(count, center=(150, 100), color="white", fontsize = 96)
  24.     bonus_1.draw()
  25.     screen.draw.text("+1$ каждые 2с", center=(450, 80), color="black", fontsize = 20)
  26.     screen.draw.text("цена: "+str(price_b1)+"$", center=(450, 110), color="black", fontsize = 20)
  27.     bonus_2.draw()
  28.     screen.draw.text("+15$ каждые 2с", center=(450, 180), color="black", fontsize = 20)
  29.     screen.draw.text("цена: "+str(price_b2)+"$", center=(450, 210), color="black", fontsize = 20)
  30.  
  31. def for_bonus_1():
  32.     global count
  33.     count += 1
  34.  
  35. def for_bonus_2():
  36.     global count
  37.     count += 15
  38.  
  39. def on_mouse_down(button, pos):
  40.     global count,price_b1,price_b2
  41.     if button == mouse.LEFT:
  42.         # Клик по объекту animal
  43.         if animal.collidepoint(pos):
  44.             count += click
  45.             animal.y = 200
  46.             animate(animal, tween='bounce_end', duration=0.5, y=250)
  47.         # Клик по кнопке bonus_1  
  48.         elif bonus_1.collidepoint(pos):
  49.             if count >= price_b1:
  50.                 schedule_interval(for_bonus_1, 2)
  51.                 count -= price_b1
  52.                 price_b1 *=2
  53.                 bonus_1.y = 105
  54.                 animate(bonus_1, tween='bounce_end', duration=0.5, y=100)
  55.         # Клик по кнопке bonus_2  
  56.         elif bonus_2.collidepoint(pos):
  57.             if count >= price_b2:
  58.                 schedule_interval(for_bonus_2, 2)
  59.                 count -= price_b2
  60.                 price_b2 *=2
  61.                 bonus_2.y = 205
  62.                 animate(bonus_2, tween='bounce_end', duration=0.5, y=200)
  63.  
RAW Paste Data