Outils pour utilisateurs

Outils du site


start:preparation:python:balle

Ceci est une ancienne révision du document !


Table des matières

Balle qui rebondit avec pygame

exemple001.py
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()
/home/chanteri/www/fablab37110/data/attic/start/preparation/python/balle.1741167978.txt.gz · Dernière modification : 2025/03/05 10:46 de admin