1
0

main.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. 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. nest = Nest(0, display)
  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. if event.key == pygame.K_z:
  26. player.move("up")
  27. elif event.key == pygame.K_s:
  28. player.move("down")
  29. elif event.key == pygame.K_q:
  30. player.move("left")
  31. elif event.key == pygame.K_d:
  32. player.move("right")
  33. # Fermeture du jeu
  34. if event.type == QUIT:
  35. pygame.quit()
  36. sys.exit()
  37. # À chaque tick on fait ce qu'il y a là
  38. display.fill(BACKGROUND_COLOR)
  39. world.draw()
  40. nest.draw(world.pos_list[0], 0)
  41. player.draw()
  42. pygame.display.update()
  43. clock.tick(FPS)
  44. # On quitte pygame
  45. pygame.quit()
  46. # On lance la fonction principale
  47. main()