main.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 nest import *
  7. from farmer import *
  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. nest = Nest(0, display)
  20. random_border_tile_example = world.random_border_tile(world.border_tiles(world.tiles_list))
  21. farmer = Farmer(random_border_tile_example.x, random_border_tile_example.y, world, display)
  22. farmer.draw()
  23. ### Boucle principale ###
  24. while True:
  25. # On gère les évènements
  26. for event in pygame.event.get():
  27. # On gère les touches
  28. if event.type == pygame.KEYDOWN:
  29. farmer.x, farmer.y = farmer.next_tuile(world)
  30. farmer.neighbors_list = farmer.neighbors(farmer.x, farmer.y, farmer.world)
  31. print("FARMER FARMER FARMER FARMER FARMER FARMER FARMER FARMER FARMER FARMER FARMER ")
  32. print(farmer.x, farmer.y)
  33. print("LISTE LISTE LISTE LISTE LISTE LISTE LISTE LISTE LISTE LISTE LISTE ")
  34. farmer.way_to_follow(world)
  35. if event.key == pygame.K_z:
  36. player.move("up")
  37. elif event.key == pygame.K_s:
  38. player.move("down")
  39. # Fermeture du jeu
  40. if event.type == QUIT:
  41. pygame.quit()
  42. sys.exit()
  43. # À chaque tick on fait ce qu'il y a là
  44. display.fill(BACKGROUND_COLOR)
  45. world.draw()
  46. player.draw()
  47. nest.draw(world.pos_list[0], 0)
  48. farmer.draw()
  49. pygame.display.update()
  50. clock.tick(FPS)
  51. # On quitte pygame
  52. pygame.quit()
  53. # On lance la fonction principale
  54. main()