Advertisement
ada1711

Untitled

Jan 10th, 2025
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. def handle_play(self):
  2.  
  3. self.screen.fill((0, 0, 0))
  4.  
  5. # Wypisanie wyniku i czasu
  6. font = pygame.font.Font(None, 36)
  7. text = font.render(f"Wynik: {self.score_manager.score}", True, (255, 255, 255))
  8. self.screen.blit(text, (10, 10))
  9.  
  10. font_time = pygame.font.Font(None, 36)
  11. text_time = font_time.render(f"Czas: {self.game_time:.2f}", True, (255, 255, 255))
  12. self.screen.blit(text_time, (650, 10))
  13.  
  14. # Odliczanie czasu
  15. self.game_time -= 1 / 60
  16. if self.game_time <= 0:
  17. self.game_state = GameState.GAME_OVER
  18.  
  19. for event in pygame.event.get():
  20. if event.type == pygame.QUIT:
  21. self.running = False
  22.  
  23. mouse_buttons = pygame.mouse.get_pressed()
  24. is_clicked = mouse_buttons[0]
  25.  
  26. # Rysowanie miecza
  27. self.sword.update()
  28. self.sword.draw(self.screen, is_clicked)
  29.  
  30. # Generacja owoców od 1 do 3 sekund
  31. current_time = pygame.time.get_ticks()
  32. if current_time - self.last_fruit_time > random.randint(1000, 3000):
  33. self.sliceables.append(Sliceable())
  34. self.last_fruit_time = current_time
  35.  
  36. slashed_bomb = False
  37. for sliceable in self.sliceables:
  38. slashed_bomb = sliceable.check_collision(self.score_manager, is_clicked)
  39. sliceable.update()
  40. sliceable.draw(self.screen)
  41.  
  42. # Usunięcie obiektów które spadają poza planszę
  43. if sliceable.is_off_screen(self.screen.get_height()):
  44. self.sliceables.remove(sliceable)
  45.  
  46. if slashed_bomb:
  47. self.game_state = GameState.GAME_OVER
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement