main.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. def main():
  8. """La fonction pricipale"""
  9. ### Initialmisation ###
  10. pygame.init() # La fonction secrète, on sait pas ce qu'elle fait mais elle doit être là
  11. display = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) # Taille de la fenêtre
  12. pygame.display.set_caption("VISI301") # Nom de la fenêtre, à changer à la fin TODO
  13. # Horloge du jeu
  14. clock = pygame.time.Clock()
  15. # Création du monde
  16. world = World(display, NB_COL, NB_ROW, GAP)
  17. 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
  18. random_border_tile_example = world.random_border_tile(world.border_tiles(world.tiles_list))
  19. farmer = Farmer(random_border_tile_example.x, random_border_tile_example.y, world, display)
  20. farmer.draw()
  21. ### Boucle principale ###
  22. while True:
  23. # On gère les évènements
  24. for event in pygame.event.get():
  25. # On gère les touches
  26. if event.type == pygame.KEYDOWN:
  27. farmer.change_destination()
  28. farmer.x, farmer.y = farmer.next_tuile()
  29. farmer.neighbors_list = farmer.neighbors(farmer.x, farmer.y, farmer.world)
  30. farmer.find_current_tile()
  31. if event.key == pygame.K_z:
  32. if player.moving:
  33. player.move("up")
  34. elif event.key == pygame.K_s:
  35. if player.moving:
  36. player.move("down")
  37. elif event.key == pygame.K_q:
  38. if player.moving:
  39. player.move("left")
  40. elif event.key == pygame.K_d:
  41. if player.moving:
  42. player.move("right")
  43. # Fermeture du jeup
  44. if event.type == QUIT:
  45. pygame.quit()
  46. sys.exit()
  47. # À chaque tick on fait ce qu'il y a là
  48. display.fill(BACKGROUND_COLOR)
  49. world.draw()
  50. player.draw()
  51. player.action()
  52. farmer.draw()
  53. pygame.display.update()
  54. clock.tick(FPS)
  55. # On quitte pygame
  56. pygame.quit()
  57. # On lance la fonction principale
  58. main()