You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
5.0 KiB

2 years ago
2 years ago
2 years ago
2 years ago
11 months ago
2 years ago
2 years ago
2 years ago
2 years ago
11 months ago
11 months ago
2 years ago
1 year ago
11 months ago
2 years ago
11 months ago
2 years ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
2 years ago
  1. import pygame, sys
  2. from pygame.locals import *
  3. import random
  4. pygame.init()
  5. SCREEN_WIDTH = 400
  6. FPS = 60
  7. FramePerSec = pygame.time.Clock()
  8. BLUE = (0, 0, 255)
  9. RED = (255, 0, 0)
  10. GREEN = (0, 255, 0)
  11. BLACK = (0, 0, 0)
  12. WHITE = (255, 255, 255)
  13. DISPLAYSURF = pygame.display.set_mode((600,600))
  14. DISPLAYSURF.fill(WHITE)
  15. pygame.display.set_caption("Game")
  16. class Pumpkin(pygame.sprite.Sprite):
  17. def __init__(self, x, y):
  18. super().__init__()
  19. self.image = pygame.image.load("pumpkin.png")
  20. self.rect = self.image.get_rect()
  21. self.rect.center=(x,y)
  22. self.liv = 1
  23. self.exploding = 0
  24. self.explosion_frames_nr = 0
  25. self.nuclear_button = 0
  26. def move(self, player):
  27. self.rect.move_ip(0,10)
  28. if (self.rect.bottom > 600):
  29. self.rect.top = 0
  30. self.rect.center = (random.randint(30, 370), 0)
  31. if self.rect.colliderect(player.rect):
  32. print("HIT")
  33. def draw(self, surface):
  34. surface.blit(self.image, self.rect)
  35. class Player(pygame.sprite.Sprite):
  36. def __init__(self, x, y):
  37. super().__init__()
  38. self.image = pygame.image.load("ghost.png")
  39. self.rect = self.image.get_rect()
  40. self.rect.center = (x, y)
  41. def update(self):
  42. pressed_keys = pygame.key.get_pressed()
  43. if pressed_keys[K_UP]:
  44. self.rect.move_ip(0, -5)
  45. if pressed_keys[K_DOWN]:
  46. self.rect.move_ip(0,5)
  47. if self.rect.left > 0:
  48. if pressed_keys[K_LEFT]:
  49. self.rect.move_ip(-5, 0)
  50. if self.rect.right < SCREEN_WIDTH:
  51. if pressed_keys[K_RIGHT]:
  52. self.rect.move_ip(5, 0)
  53. def draw(self, surface):
  54. surface.blit(self.image, self.rect)
  55. def get_pos(self):
  56. return self.rect.pos
  57. P1 = Player(185, 290)
  58. list_pumpkins = [Pumpkin(185, 290), Pumpkin(430, 290), Pumpkin(310, 260), Pumpkin(310, 190), Pumpkin(185, 370), Pumpkin(450, 370)]
  59. clicks = 0
  60. mus_nede = 0
  61. pygame.font.init()
  62. my_font = pygame.font.SysFont('Comic Sans MS', 30)
  63. text_surface = my_font.render('Clicks: ' + str(clicks), False, (255, 255, 255))
  64. bg = pygame.image.load("bg.png")
  65. nuclear_button = pygame.image.load("nuclear-bomb.png")
  66. nuclear_seconds = 0
  67. countdown = 10
  68. explosion_frames = []
  69. for i in range(64):
  70. explosion_frames.append(pygame.image.load("explosion/exp_frame_"+str(i)+".png"))
  71. explosion_frames_nr = 0
  72. explosion_on = 0
  73. ticks_seconds = 0
  74. while True:
  75. if random.randint(1, 50) == 25:
  76. for pumpkin in list_pumpkins:
  77. pumpkin.liv = 1
  78. for event in pygame.event.get():
  79. if event.type == QUIT:
  80. pygame.quit()
  81. sys.exit()
  82. P1.update()
  83. #E1.move(P1)
  84. #DISPLAYSURF.fill(WHITE)
  85. DISPLAYSURF.blit(bg, (0, 0))
  86. if nuclear_seconds > 0:
  87. DISPLAYSURF.blit(nuclear_button, (16, 32))
  88. #P1.draw(DISPLAYSURF)
  89. for pumpkin in list_pumpkins:
  90. if pumpkin.liv == 1:
  91. pumpkin.draw(DISPLAYSURF)
  92. if pumpkin.exploding == 1:
  93. DISPLAYSURF.blit(explosion_frames[pumpkin.explosion_frames_nr], (pumpkin.rect.x-96,pumpkin.rect.y-96))
  94. pumpkin.explosion_frames_nr = (pumpkin.explosion_frames_nr +1)
  95. if pumpkin.explosion_frames_nr == 64:
  96. pumpkin.exploding = 0
  97. pumpkin.explosion_frames_nr = 0
  98. DISPLAYSURF.blit(text_surface, (0,0))
  99. if event.type == MOUSEBUTTONDOWN:
  100. mouse_pos = event.pos # Now it will have the coordinates of click point.
  101. print('Click')
  102. for pumpkin in list_pumpkins:
  103. if pumpkin.rect.collidepoint(mouse_pos):
  104. if pumpkin.liv == 1:
  105. pumpkin.liv = 0
  106. if pumpkin.nuclear_button == 1:
  107. nuclear_seconds = 5
  108. pumpkin.nuclear_button = 0
  109. list_pumpkins[random_pumpkin-1].image = pygame.image.load("pumpkin.png")
  110. if mus_nede == 0:
  111. mus_nede = 1
  112. print('Touched')
  113. clicks = clicks + 1
  114. countdown = countdown - 1
  115. if countdown == 0:
  116. random_pumpkin = random.randint(1, len(list_pumpkins))
  117. list_pumpkins[random_pumpkin-1].nuclear_button = 1
  118. list_pumpkins[random_pumpkin-1].image = pygame.image.load("nuclear-bomb.png")
  119. if nuclear_seconds > 0:
  120. pumpkin.exploding = 1
  121. clicks = clicks + 79
  122. text_surface = my_font.render('Clicks: ' + str(clicks), False, (255, 255, 255))
  123. elif event.type == MOUSEBUTTONUP:
  124. mus_nede = 0
  125. ticks_seconds = ticks_seconds + 1
  126. if (ticks_seconds % 60) == 0:
  127. if nuclear_seconds > 0:
  128. nuclear_seconds = nuclear_seconds - 1
  129. countdown = 10
  130. pygame.display.update()
  131. FramePerSec.tick(FPS)