OtsoSilver

Untitled

Sep 26th, 2021
1,034
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. bonus_3 = Actor("bonus", (450, 300))
  15. play = Actor("play", (300, 100))
  16. cross = Actor("cross", (580, 20))
  17. shop = Actor("shop", (300, 200))
  18. collection = Actor("collection", (300, 300))
  19. crocodile = Actor('crocodile', (120,200))
  20. hippo = Actor('hippo', (300,200))
  21. # Переменные
  22. count = 99999
  23. click = 1
  24. mode = 'menu'
  25. price_1 = 15
  26. price_2 = 200
  27. price_3 = 600
  28.  
  29. def draw():
  30.     if mode == 'menu':
  31.         fon.draw()
  32.         play.draw()
  33.         screen.draw.text(count, center=(30, 20), color="white", fontsize = 36)
  34.         shop.draw()
  35.         collection.draw()
  36.    
  37.     elif mode == 'game':    
  38.         fon.draw()
  39.         animal.draw()
  40.         screen.draw.text(count, center=(150, 100), color="white", fontsize = 96)
  41.         bonus_1.draw()
  42.         screen.draw.text("+1$ каждые 2с", center=(450, 80), color="black", fontsize = 20)
  43.         screen.draw.text(price_1, center=(450, 110), color="black", fontsize = 20)
  44.         bonus_2.draw()
  45.         screen.draw.text("+15$ каждые 2с", center=(450, 180), color="black", fontsize = 20)
  46.         screen.draw.text(price_2, center=(450, 210), color="black", fontsize = 20)
  47.         bonus_3.draw()
  48.         screen.draw.text("+50$ каждые 2с", center=(450, 280), color="black", fontsize = 20)
  49.         screen.draw.text(price_3, center=(450, 310), color="black", fontsize = 20)
  50.         cross.draw()
  51.     elif mode == 'shop':
  52.         fon.draw()
  53.         crocodile.draw()
  54.         screen.draw.text("500$", center= (120, 300), color="white", fontsize = 36)
  55.         hippo.draw()
  56.         screen.draw.text("2500$", center= (300, 300), color="white", fontsize = 36)
  57.         cross.draw()
  58.         screen.draw.text(count, center=(30, 20), color="white", fontsize = 36)
  59.  
  60.  
  61.  
  62. def for_bonus_1():
  63.     global count
  64.     count += 1
  65.  
  66. def for_bonus_2():
  67.     global count
  68.     count += 15
  69.  
  70. def for_bonus_3():
  71.     global count
  72.     count += 50
  73.  
  74. def on_mouse_down(button, pos):
  75.     global count
  76.     global mode
  77.     global price_1, price_2, price_3,click
  78.     if button == mouse.LEFT and mode == 'game':
  79.         # Клик по объекту animal
  80.         if animal.collidepoint(pos):
  81.             count += click
  82.             animal.y = 200
  83.             animate(animal, tween='bounce_end', duration=0.5, y=250)
  84.         # Клик по кнопке bonus_1  
  85.         elif bonus_1.collidepoint(pos):
  86.             bonus_1.y = 105
  87.             animate(bonus_1, tween='bounce_end', duration=0.5, y=100)
  88.             if count >= price_1:
  89.                 schedule_interval(for_bonus_1, 2)
  90.                 count -= price_1
  91.                 price_1 *= 2
  92.         # Клик по кнопке bonus_2  
  93.         elif bonus_2.collidepoint(pos):
  94.             bonus_2.y = 205
  95.             animate(bonus_2, tween='bounce_end', duration=0.5, y=200)
  96.             if count >= price_2:
  97.                 schedule_interval(for_bonus_2, 2)
  98.                 count -= price_2
  99.                 price_2 *= 2
  100.         # Клик по кнопке bonus_3
  101.         elif bonus_3.collidepoint(pos):
  102.             bonus_3.y = 305
  103.             animate(bonus_3, tween='bounce_end', duration=0.5, y=300)
  104.             if count >= price_3:
  105.                 schedule_interval(for_bonus_3, 2)
  106.                 count -= price_3
  107.                 price_3 *= 2
  108.         elif cross.collidepoint(pos):
  109.             mode = 'menu'
  110.     elif button == mouse.LEFT and mode == 'shop':
  111.         if cross.collidepoint(pos):
  112.             mode = 'menu'
  113.         if crocodile.collidepoint(pos):
  114.             if count >= 500:
  115.                 count -= 500
  116.                 animal.image = 'crocodile'
  117.                 click = 2
  118.                 crocodile.y = 210
  119.                 animate(crocodile, tween='bounce_end', duration=0.5, y=200)
  120.         if hippo.collidepoint(pos):
  121.             if count >= 2500:
  122.                 count -= 2500
  123.                 animal.image = 'hippo'
  124.                 click = 4
  125.                 hippo.y = 210
  126.                 animate(hippo, tween='bounce_end', duration=0.5, y=200)
  127.        
  128.     # Режим меню
  129.     elif mode == 'menu' and button == mouse.LEFT:
  130.         if play.collidepoint(pos):
  131.             mode = 'game'
  132.         if shop.collidepoint(pos):
  133.             mode = 'shop'
RAW Paste Data