Advertisement
OtsoSilver

Untitled

Sep 5th, 2021
1,056
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.88 KB | None | 0 0
  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. crocodile = Actor('crocodile', (120, 200))
  12. hippo = Actor('hippo', (300, 200))
  13.  
  14. fon = Actor("fon")
  15. bonus_1 = Actor("bonus", (450, 100))
  16. bonus_2 = Actor("bonus", (450, 200))
  17. bonus_3 = Actor("bonus", (450, 300))
  18. play = Actor("play", (300, 100))
  19. cross = Actor("cross", (580, 20))
  20. shop = Actor("shop", (300, 200))
  21. collection = Actor("collection", (300, 300))
  22. animals = []
  23. # Переменные
  24. count = 99999
  25. click = 1
  26. mode = 'menu'
  27. price_1 = 15
  28. price_2 = 200
  29. price_3 = 600
  30.  
  31. def draw():
  32.     if mode == 'menu':
  33.         fon.draw()
  34.         play.draw()
  35.         screen.draw.text(count, center=(30, 20), color="white", fontsize = 36)
  36.         shop.draw()
  37.         collection.draw()
  38.    
  39.     elif mode == 'game':    
  40.         fon.draw()
  41.         animal.draw()
  42.         screen.draw.text(count, center=(150, 100), color="white", fontsize = 96)
  43.         bonus_1.draw()
  44.         screen.draw.text("+1$ каждые 2с", center=(450, 80), color="black", fontsize = 20)
  45.         screen.draw.text(price_1, center=(450, 110), color="black", fontsize = 20)
  46.         bonus_2.draw()
  47.         screen.draw.text("+15$ каждые 2с", center=(450, 180), color="black", fontsize = 20)
  48.         screen.draw.text(price_2, center=(450, 210), color="black", fontsize = 20)
  49.         bonus_3.draw()
  50.         screen.draw.text("+50$ каждые 2с", center=(450, 280), color="black", fontsize = 20)
  51.         screen.draw.text(price_3, center=(450, 310), color="black", fontsize = 20)
  52.         cross.draw()
  53.     elif mode == 'shop':
  54.         fon.draw()
  55.         screen.draw.text(count, center=(30, 20), color="white", fontsize = 36)
  56.         crocodile.draw()
  57.         screen.draw.text('500$', center=(120, 300), color="white", fontsize = 36)
  58.         hippo.draw()
  59.         screen.draw.text('2500$', center=(300, 300), color="white", fontsize = 36)
  60.         cross.draw()
  61.     elif mode == 'collection':
  62.         fon.draw()
  63.         screen.draw.text(count, center=(30, 20), color="white", fontsize = 36)
  64.         screen.draw.text('+2$', center=(120, 300), color="white", fontsize = 36)
  65.         screen.draw.text('+4$', center=(300, 300), color="white", fontsize = 36)
  66.         for anim in animals:
  67.             anim.draw()
  68.  
  69.  
  70.  
  71.  
  72. def for_bonus_1():
  73.     global count
  74.     count += 1
  75.  
  76. def for_bonus_2():
  77.     global count
  78.     count += 15
  79.  
  80. def for_bonus_3():
  81.     global count
  82.     count += 50
  83.  
  84. def on_mouse_down(button, pos):
  85.     global count, click
  86.     global mode
  87.     global price_1, price_2, price_3
  88.     if button == mouse.LEFT and mode == 'game':
  89.         # Клик по объекту animal
  90.         if animal.collidepoint(pos):
  91.             count += click
  92.             animal.y = 200
  93.             animate(animal, tween='bounce_end', duration=0.5, y=250)
  94.         # Клик по кнопке bonus_1  
  95.         elif bonus_1.collidepoint(pos):
  96.             bonus_1.y = 105
  97.             animate(bonus_1, tween='bounce_end', duration=0.5, y=100)
  98.             if count >= price_1:
  99.                 schedule_interval(for_bonus_1, 2)
  100.                 count -= price_1
  101.                 price_1 *= 2
  102.         # Клик по кнопке bonus_2  
  103.         elif bonus_2.collidepoint(pos):
  104.             bonus_2.y = 205
  105.             animate(bonus_2, tween='bounce_end', duration=0.5, y=200)
  106.             if count >= price_2:
  107.                 schedule_interval(for_bonus_2, 2)
  108.                 count -= price_2
  109.                 price_2 *= 2
  110.         # Клик по кнопке bonus_3
  111.         elif bonus_3.collidepoint(pos):
  112.             bonus_3.y = 305
  113.             animate(bonus_3, tween='bounce_end', duration=0.5, y=300)
  114.             if count >= price_3:
  115.                 schedule_interval(for_bonus_3, 2)
  116.                 count -= price_3
  117.                 price_3 *= 2
  118.         elif cross.collidepoint(pos):
  119.             mode = 'menu'
  120.    
  121.     # Режим меню
  122.     elif mode == 'menu' and button == mouse.LEFT:
  123.         if play.collidepoint(pos):
  124.             mode = 'game'
  125.         elif shop.collidepoint(pos):
  126.             mode = 'shop'
  127.            
  128.     elif mode == 'shop' and button == mouse.LEFT:
  129.         if cross.collidepoint(pos):
  130.             mode = 'menu'
  131.         if crocodile.collidepoint(pos):
  132.             if crocodile in animals:
  133.                 animal.image = 'crocodile'
  134.                 crocodile.y = 205
  135.                 animate(crocodile, tween='bounce_end', duration=0.5, y=200)
  136.             else:
  137.                 if count >= 500:
  138.                     crocodile.y = 205
  139.                     count -= 500
  140.                     animate(crocodile, tween='bounce_end', duration=0.5, y=200)
  141.                     click = 2
  142.                     animal.image = 'crocodile'
  143.                     animals.append(crocodile)
  144.         if hippo.collidepoint(pos):
  145.             if hippo in animals:
  146.                 animal.image = 'hippo'
  147.                 hippo.y = 205
  148.                 animate(hippo, tween='bounce_end', duration=0.5, y=200)
  149.  
  150.             else:    
  151.                 if count >= 2500:
  152.                     hippo.y = 205
  153.                     count -= 2500
  154.                     animate(hippo, tween='bounce_end', duration=0.5, y=200)
  155.                     click = 4
  156.                     animal.image = 'hippo'
  157.                     animals.append(hippo)
  158.    
  159.     elif mode == 'collection' and button == mouse.LEFT:
  160.         if cross.collidepoint(pos):
  161.             mode = 'menu'
  162.         if crocodile.collidepoint(pos):
  163.             if crocodile in animals:
  164.                 animal.image = 'crocodile'
  165.                 crocodile.y = 205
  166.                 animate(crocodile, tween='bounce_end', duration=0.5, y=200)
  167.         if hippo.collidepoint(pos):
  168.             if hippo in animals:
  169.                 animal.image = 'hippo'
  170.                 hippo.y = 205
  171.                 animate(hippo, tween='bounce_end', duration=0.5, y=200)    
  172.            
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement