player.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import pygame
  2. from tiles import *
  3. from variables import *
  4. class Player:
  5. def __init__(self, x: int, y: int, display: pygame.display):
  6. """Un joueur, avec ses coordonnées (x, y)"""
  7. self.display = display
  8. self.x: int = x
  9. self.y: int = y
  10. self.width: int = self.player_size()
  11. self.height: int = self.player_size()
  12. self.picture: str = "player"
  13. def draw(self, tile: dict):
  14. """Affiche le joueur"""
  15. image = pygame.transform.scale(PLAYER, (self.player_size(), self.player_size()))
  16. tile_size = self.tile_size()
  17. 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
  18. def player_size(self):
  19. """Renvoie la taille que fera le joueur (sa hauteur et sa largeur sont similaires)"""
  20. width = (WINDOW_WIDTH - NB_COL * GAP) // NB_COL
  21. height = (WINDOW_HEIGHT - NB_ROW * GAP) // NB_ROW
  22. #Réutilisation du calcul de la taille des tuilles pour calculer la taille du joueur
  23. if height < 0.86 * width:
  24. width = height // 0.86
  25. else:
  26. height = round(width * 0.86)
  27. return int(width) // 1.8
  28. def tile_size(self):
  29. """Renvoie la taille d'une tuille CECI EST UNE FONCTION TEST QUI POURRAS SUREMENT ETRE ENLEVEE"""
  30. width = (WINDOW_WIDTH - NB_COL * GAP) // NB_COL
  31. height = (WINDOW_HEIGHT - NB_ROW * GAP) // NB_ROW
  32. #Réutilisation du calcul de la taille des tuilles pour calculer la taille du joueur
  33. if height < 0.86 * width:
  34. width = height // 0.86
  35. else:
  36. height = round(width * 0.86)
  37. return int(width)