clicker.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import pygame
  2. import sys
  3. import GUI
  4. pygame.init()
  5. screen = pygame.display.set_mode((300, 400))
  6. save = {
  7. 'money': 0,
  8. 'click': 1,
  9. 'upgrade': {
  10. 1: 10
  11. }
  12. }
  13. i = []
  14. i.append(GUI.Button(screen, text = 'CLICK', width = 300, height = 200, x = 0, y = 200, hover_color = (255, 255, 200))) # 0
  15. i.append(GUI.Button(screen, text = '', width = 300, height = 50, bg_color = (200, 200, 200), hover_color = (200, 200, 200))) # 1
  16. i[1].set_text(str(save['money']) + ' COIN')
  17. i.append(GUI.Button(screen, text = '', width = 150, height = 150, x = 0, y = 50, bg_color = (255, 150, 150))) # 2
  18. i.append(GUI.Button(screen, text = 'CLICK: 1', width = 150, height = 150, x = 150, y = 50, bg_color = (150, 225, 150))) # 3
  19. i[3].set_text('CLICK: '+str(save['click']))
  20. i[2].set_text('UP: '+str(save['upgrade'][1])+' COIN')
  21. while True:
  22. for value in range(len(i)):
  23. i[value].update()
  24. for event in pygame.event.get():
  25. if event.type == pygame.QUIT:
  26. sys.exit()
  27. elif event.type == pygame.MOUSEBUTTONDOWN:
  28. if i[0].active(key = event.button):
  29. save['money'] += save['click']
  30. i[1].set_text(str(save['money']) + ' COIN')
  31. elif i[2].active(key = event.button):
  32. if save['upgrade'][1] <= save['money']:
  33. save['money'] -= save['upgrade'][1]
  34. save['click'] += 1
  35. i[1].set_text(str(save['money']))
  36. i[3].set_text('CLICK: '+str(save['click']))
  37. pygame.display.update()