nest.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import pygame
  2. from tiles import *
  3. from variables import *
  4. class Nest:
  5. def __init__(self, eggs: int, display: pygame.display):
  6. """Un joueur, avec ses coordonnées (x, y)"""
  7. self.display = display
  8. self.eggs: int = eggs
  9. def draw(self, tile: dict, eggs: int):
  10. """Affiche le nid"""
  11. image = pygame.transform.scale(NEST, (self.nest_size(), self.nest_size()))
  12. tile_size = self.tile_size()
  13. self.display.blit(image, (tile['x'] - tile_size // 3.7, tile['y'] - tile_size // 3.7)) #la valeur ici est arbitraire mais marche. elle est la pour centrer l'affichage du joueur sur une tuile, a changer dans le futur
  14. def nest_size(self):
  15. """Renvoie la taille que fera le joueur (sa hauteur et sa largeur sont similaires)"""
  16. width = (WINDOW_WIDTH - NB_COL * GAP) // NB_COL
  17. height = (WINDOW_HEIGHT - NB_ROW * GAP) // NB_ROW
  18. #Réutilisation du calcul de la taille des tuilles pour calculer la taille du joueur
  19. if height < 0.86 * width:
  20. width = height // 0.86
  21. else:
  22. height = round(width * 0.86)
  23. return int(width) // 1.8
  24. def tile_size(self):
  25. """Renvoie la taille d'une tuille CECI EST UNE FONCTION TEST QUI POURRAS SUREMENT ETRE ENLEVEE"""
  26. width = (WINDOW_WIDTH - NB_COL * GAP) // NB_COL
  27. height = (WINDOW_HEIGHT - NB_ROW * GAP) // NB_ROW
  28. #Réutilisation du calcul de la taille des tuilles pour calculer la taille du joueur
  29. if height < 0.86 * width:
  30. width = height // 0.86
  31. else:
  32. height = round(width * 0.86)
  33. return int(width)