mirror of
https://github.com/Fare-spec/cours.git
synced 2025-12-07 10:50:36 +00:00
Auto urgent commit.
This commit is contained in:
42
learning_pygame/bouncing_ball/ball.py
Normal file
42
learning_pygame/bouncing_ball/ball.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import sys, pygame
|
||||
import balle
|
||||
##########Definitions des constantes
|
||||
# Taille de la fenetre
|
||||
LARGEUR_ECRAN = 600
|
||||
HAUTEUR_ECRAN = 800
|
||||
# Couleur
|
||||
BLANC = (255, 255, 255)
|
||||
NOIR = (0, 0, 0)
|
||||
|
||||
pygame.init() #initialisation des modules de pygame
|
||||
|
||||
# Creation de la fenetre
|
||||
ecran = pygame.display.set_mode((LARGEUR_ECRAN, HAUTEUR_ECRAN))
|
||||
ecran.fill(BLANC)
|
||||
|
||||
pygame.display.set_caption('Balle rebondissante')
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
b1 = balle.Balle()
|
||||
|
||||
bouge = False
|
||||
|
||||
while True: #Demarrage de la boucle infinie
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT: #Evt de sortie de boucle
|
||||
sys.exit()
|
||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||
bouge = not bouge
|
||||
elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
|
||||
bouge = not bouge
|
||||
|
||||
|
||||
ecran.fill(BLANC)
|
||||
if bouge:
|
||||
b1.deplace()
|
||||
b1.affiche(ecran)
|
||||
|
||||
pygame.display.update() #rafraichissement
|
||||
clock.tick(60)
|
||||
|
||||
23
learning_pygame/bouncing_ball/balle.py
Normal file
23
learning_pygame/bouncing_ball/balle.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import pygame
|
||||
|
||||
class Balle :
|
||||
"""
|
||||
Definie une balle qui se deplace dans la fenetre ecran
|
||||
Attributs : rayon , xpos , ypos , xvit , yvit
|
||||
Methodes : deplace , affiche
|
||||
"""
|
||||
|
||||
def __init__ ( self ) :
|
||||
self.rayon = 10
|
||||
self.xpos = 300.0
|
||||
self.ypos = 400.0
|
||||
self.xvit = 4.5
|
||||
self.yvit = 3.0
|
||||
|
||||
def deplace ( self ) :
|
||||
self.xpos += self.xvit
|
||||
self.ypos += self.yvit
|
||||
if self.xpos + self.rayon > 600 or self.xpos - self.rayon < 0:
|
||||
self.xvit = - self.xvit
|
||||
elif self.ypos + self.rayon > 800 or self.ypos - self.rayon < 0:
|
||||
self.yvit = - self.yvit
|
||||
Reference in New Issue
Block a user