main.py 2.0 KB

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