import sys, pygame pygame.init() import time size = width, height = 1280, 960 speed = [5, 5] black = 0, 0, 0 screen = pygame.display.set_mode(size) ball = pygame.image.load("intro_ball.gif") #ball = pygame.image.load("bird-animated-gif-26-665736874.gif") #ball = pygame.image.load("oiseau001.gif") ballrect = ball.get_rect() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() ballrect = ballrect.move(speed) if ballrect.left < 0 or ballrect.right > width: speed[0] = -speed[0] time.sleep(0.2) if ballrect.top < 0 or ballrect.bottom > height: speed[1] = -speed[1] time.sleep(0.2) screen.fill(black) screen.blit(ball, ballrect) pygame.display.flip()
Avant d'installer Pygame, nous devons avoir Python sur notre machine. Sur quelques systèmes d'exploitation, Python est installé par défaut. Ainsi, Pygame devrait être compatible avec toutes les versions de Python et il est importons à mentionner que nous aurons également besoin de la lirairie NumPy.
sudo apt-get install python-pygame
https://installati.one/install-python3-pygame-sdl2-debian-12/
Nous pouvons installer NumPy avec la commande suivante:
sudo apt-get install python-numpy
Le programme d'installation de Windows Python se trouve sur www.python.org/download. Sur ce site, nous pouvons également trouver un outil d’installation pour Mac OS X et archives tar sources pour Linux, Unix et Mac OS X.
Accédez à http://www.pygame.org/download.shtml, vous pouvez télécharger l’installateur binaire approprié pour la version Python que nous utilisons.
Depuis cmd
Pip install pygame Pip install numpy