1
0

main.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import pygame, sys
  2. from pygame.locals import * # Import des constantes de pygame
  3. from world import World
  4. from variables import *
  5. from player import *
  6. from farmer import *
  7. # Fonctions
  8. def main():
  9. """La fonction pricipale"""
  10. ### Initialmisation ###
  11. pygame.init() # La fonction secrète, on sait pas ce qu'elle fait mais elle doit être là
  12. display = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) # Taille de la fenêtre
  13. pygame.display.set_caption("VISI301") # Nom de la fenêtre, à changer à la fin TODO
  14. # Horloge du jeu
  15. clock = pygame.time.Clock()
  16. # Création du monde
  17. world = World(display, NB_COL, NB_ROW, GAP)
  18. player = Player(world.pos_list[1]["x"], world.pos_list[1]["y"], world, display) # On initialise le joueur sur la première tuile en dessous du nid
  19. ### Boucle principale ###
  20. while True:
  21. # On gère les évènements
  22. for event in pygame.event.get():
  23. # On gère les touches
  24. if event.type == pygame.KEYDOWN:
  25. # On gère la création et les actions des fermiers
  26. farmers_control(world, player, display)
  27. for farmer in world.farmers:
  28. farmer.action()
  29. if event.key == pygame.K_z:
  30. if player.moving:
  31. player.move("up")
  32. elif event.key == pygame.K_s:
  33. if player.moving:
  34. player.move("down")
  35. elif event.key == pygame.K_q:
  36. if player.moving:
  37. player.move("left")
  38. elif event.key == pygame.K_d:
  39. if player.moving:
  40. player.move("right")
  41. # Fermeture du jeup
  42. if event.type == QUIT:
  43. pygame.quit()
  44. sys.exit()
  45. # À chaque tick on fait ce qu'il y a là
  46. display.fill(BACKGROUND_COLOR)
  47. world.draw()
  48. player.draw()
  49. player.action()
  50. for farmer in world.farmers:
  51. farmer.draw()
  52. pygame.display.update()
  53. clock.tick(FPS)
  54. # On quitte pygame
  55. pygame.quit()
  56. # On lance la fonction principale
  57. main()