Bcp de changements !
BIN
Contribution Noham RIVOIRARD.odt
Normal file
BIN
V3/balle.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
V3/coeur.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
V3/joueur.png
Normal file
After Width: | Height: | Size: 91 KiB |
BIN
V3/terrain.png
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
V4/balle.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
V4/coeur.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
V4/coeurfaded.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
V4/joueur.png
Normal file
After Width: | Height: | Size: 91 KiB |
BIN
V4/terrain.png
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
V5/balle.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
V5/coeur.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
V5/coeurfaded.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
V5/joueur.png
Normal file
After Width: | Height: | Size: 91 KiB |
BIN
V5/terrain.png
Normal file
After Width: | Height: | Size: 72 KiB |
104
jeu V1.py
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
import pygame
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
game_over = False
|
||||||
|
game_over_time = None
|
||||||
|
|
||||||
|
WIDTH = 800
|
||||||
|
HEIGHT = 600
|
||||||
|
|
||||||
|
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
|
pygame.display.set_caption("Jeu V1")
|
||||||
|
|
||||||
|
# Couleurs
|
||||||
|
BLACK = (0, 0, 0)
|
||||||
|
WHITE = (255, 255, 255)
|
||||||
|
|
||||||
|
# Paramètres de la balle
|
||||||
|
BALL_RADIUS = 30
|
||||||
|
ball_pos = [WIDTH // 2, BALL_RADIUS] # Position initiale de la balle
|
||||||
|
|
||||||
|
# Paramètres du joueur
|
||||||
|
PLAYER_WIDTH = 80
|
||||||
|
PLAYER_HEIGHT = 20
|
||||||
|
player_pos = [WIDTH // 2 - PLAYER_WIDTH // 2, HEIGHT - PLAYER_HEIGHT - 60] # Position initiale du joueur
|
||||||
|
player_speed = 10 # Vitesse de déplacement du joueur
|
||||||
|
|
||||||
|
# Variables du jeu
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
running = True
|
||||||
|
|
||||||
|
ball_velocity_y = 0 # Vélocité verticale initiale
|
||||||
|
ball_velocity_x = 1 # Vélocité horizontale initiale
|
||||||
|
gravity = 0.1 # Accélération due à la gravité
|
||||||
|
|
||||||
|
score = 0 # Le score au début de la partie
|
||||||
|
font = pygame.font.Font(None, 36) # Crée une police pour le texte (taille 36)
|
||||||
|
|
||||||
|
|
||||||
|
while running:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
running = False
|
||||||
|
|
||||||
|
# Gestion des mouvements du joueur
|
||||||
|
mouse_pos = pygame.mouse.get_pos()
|
||||||
|
player_pos[0] = mouse_pos[0] - PLAYER_WIDTH // 2 # Met à jour la position du joueur en fonction de la position de la souris
|
||||||
|
|
||||||
|
# Mise à jour de la logique du jeu
|
||||||
|
|
||||||
|
|
||||||
|
#gravity
|
||||||
|
ball_velocity_y += gravity # Applique l'accélération due à la gravité à la vélocité
|
||||||
|
ball_pos[1] += ball_velocity_y # Met à jour la position verticale de la balle en fonction de la vélocité
|
||||||
|
|
||||||
|
# Si la balle touche le joueur
|
||||||
|
if ball_pos[1] + BALL_RADIUS >= player_pos[1] and ball_pos[0] >= player_pos[0] and ball_pos[0] <= player_pos[0] + PLAYER_WIDTH: # Si y'a collision avec le joueur
|
||||||
|
ball_pos[1] = player_pos[1] - BALL_RADIUS # Rétablit la position de la balle au-dessus du joueur
|
||||||
|
ball_velocity_y = -ball_velocity_y # Inverse la vélocité verticale pour simuler le rebond
|
||||||
|
score += 1 # Incrémente le score
|
||||||
|
ball_velocity_x += random.uniform(-2, 2) # Change la vélocité horizontale de la balle
|
||||||
|
print("Score :", score) # Affiche le score à la console (remplace par ton propre code d'affichage)
|
||||||
|
|
||||||
|
|
||||||
|
# Si la balle touche le sol
|
||||||
|
if ball_pos[1] + BALL_RADIUS >= HEIGHT:
|
||||||
|
game_over = True # Active l'état "game_over"
|
||||||
|
ball_pos[1] = HEIGHT + BALL_RADIUS # Déplace la balle hors de l'écran pour la cacher
|
||||||
|
player_pos[1] = HEIGHT + PLAYER_HEIGHT # Déplace le joueur hors de l'écran pour le cacher
|
||||||
|
print('game over')
|
||||||
|
|
||||||
|
|
||||||
|
elif ball_pos[1] <= BALL_RADIUS:
|
||||||
|
ball_pos[1] = BALL_RADIUS # Rétablit la position de la balle à l'intérieur de l'écran
|
||||||
|
ball_velocity_y = -ball_velocity_y # Inverse la vélocité pour simuler le rebond
|
||||||
|
|
||||||
|
|
||||||
|
# Partie pour faire en sorte que la balle se déplace de gauche à droite
|
||||||
|
# Mise à jour de la logique du jeu
|
||||||
|
ball_pos[0] += ball_velocity_x # Met à jour la position horizontale de la balle en fonction de la vélocité horizontale
|
||||||
|
|
||||||
|
# Vérifie la collision avec les bords gauche et droit de l'écran
|
||||||
|
if ball_pos[0] <= BALL_RADIUS or ball_pos[0] >= WIDTH - BALL_RADIUS:
|
||||||
|
ball_velocity_x = -ball_velocity_x # Inverse la vélocité horizontale pour changer la direction de la balle
|
||||||
|
|
||||||
|
|
||||||
|
# Dessiner les éléments
|
||||||
|
screen.fill(BLACK)
|
||||||
|
pygame.draw.circle(screen, WHITE, ball_pos, BALL_RADIUS)
|
||||||
|
pygame.draw.rect(screen, WHITE, (player_pos[0], player_pos[1], PLAYER_WIDTH, PLAYER_HEIGHT))
|
||||||
|
|
||||||
|
# Le score
|
||||||
|
text = font.render("Score: " + str(score), True, WHITE) # Convertit le score en chaîne de caractères et crée un objet de texte
|
||||||
|
text_rect = text.get_rect()
|
||||||
|
text_rect.center = (WIDTH // 2, 20) # Positionne le texte au centre en haut de l'écran
|
||||||
|
screen.blit(text, text_rect) # Affiche le texte sur l'écran
|
||||||
|
|
||||||
|
# Rafraîchissement de l'écran
|
||||||
|
pygame.display.flip()
|
||||||
|
clock.tick(60) # Limite le taux de rafraîchissement à 60 FPS
|
||||||
|
|
||||||
|
pygame.quit()
|
112
jeu V2.py
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
import pygame
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
# Paramètres de l'écran
|
||||||
|
WIDTH = 800
|
||||||
|
HEIGHT = 600
|
||||||
|
|
||||||
|
# Couleurs
|
||||||
|
BLACK = (0, 0, 0)
|
||||||
|
WHITE = (255, 255, 255)
|
||||||
|
|
||||||
|
# Paramètres de la balle
|
||||||
|
BALL_RADIUS = 30
|
||||||
|
|
||||||
|
# Paramètres du joueur
|
||||||
|
PLAYER_WIDTH = 80
|
||||||
|
PLAYER_HEIGHT = 20
|
||||||
|
|
||||||
|
# Variables du jeu
|
||||||
|
score = 0
|
||||||
|
font = pygame.font.Font(None, 36)
|
||||||
|
|
||||||
|
# Initialisation de l'écran de jeu
|
||||||
|
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
|
pygame.display.set_caption("Jeu V2")
|
||||||
|
|
||||||
|
def game():
|
||||||
|
global score
|
||||||
|
|
||||||
|
# Position initiale de la balle
|
||||||
|
ball_pos = [WIDTH // 2, BALL_RADIUS]
|
||||||
|
ball_velocity_y = 0
|
||||||
|
ball_velocity_x = 1
|
||||||
|
gravity = 0.1
|
||||||
|
|
||||||
|
# Position initiale du joueur
|
||||||
|
player_pos = [WIDTH // 2 - PLAYER_WIDTH // 2, HEIGHT - PLAYER_HEIGHT - 60]
|
||||||
|
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
running = True
|
||||||
|
|
||||||
|
while running:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Gestion des mouvements du joueur
|
||||||
|
mouse_pos = pygame.mouse.get_pos()
|
||||||
|
player_pos[0] = mouse_pos[0] - PLAYER_WIDTH // 2
|
||||||
|
|
||||||
|
# Mise à jour de la logique du jeu
|
||||||
|
ball_velocity_y += gravity
|
||||||
|
ball_pos[1] += ball_velocity_y
|
||||||
|
|
||||||
|
# Si la balle touche le joueur
|
||||||
|
if ball_pos[1] + BALL_RADIUS >= player_pos[1] and ball_pos[0] >= player_pos[0] and ball_pos[0] <= player_pos[0] + PLAYER_WIDTH:
|
||||||
|
ball_pos[1] = player_pos[1] - BALL_RADIUS
|
||||||
|
ball_velocity_y = -ball_velocity_y
|
||||||
|
score += 1
|
||||||
|
ball_velocity_x += random.uniform(-2, 2)
|
||||||
|
print("Score :", score)
|
||||||
|
|
||||||
|
# Si la balle touche le sol
|
||||||
|
if ball_pos[1] + BALL_RADIUS >= HEIGHT:
|
||||||
|
return False
|
||||||
|
|
||||||
|
elif ball_pos[1] <= BALL_RADIUS:
|
||||||
|
ball_pos[1] = BALL_RADIUS
|
||||||
|
ball_velocity_y = -ball_velocity_y
|
||||||
|
|
||||||
|
ball_pos[0] += ball_velocity_x
|
||||||
|
|
||||||
|
if ball_pos[0] <= BALL_RADIUS or ball_pos[0] >= WIDTH - BALL_RADIUS:
|
||||||
|
ball_velocity_x = -ball_velocity_x
|
||||||
|
|
||||||
|
screen.fill(BLACK)
|
||||||
|
pygame.draw.circle(screen, WHITE, ball_pos, BALL_RADIUS)
|
||||||
|
pygame.draw.rect(screen, WHITE, (player_pos[0], player_pos[1], PLAYER_WIDTH, PLAYER_HEIGHT))
|
||||||
|
|
||||||
|
text = font.render("Score: " + str(score), True, WHITE)
|
||||||
|
text_rect = text.get_rect()
|
||||||
|
text_rect.center = (WIDTH // 2, 20)
|
||||||
|
screen.blit(text, text_rect)
|
||||||
|
|
||||||
|
pygame.display.flip()
|
||||||
|
clock.tick(60)
|
||||||
|
|
||||||
|
def game_over_screen():
|
||||||
|
screen.fill(BLACK)
|
||||||
|
perdu_text = font.render("Perdu", True, WHITE)
|
||||||
|
perdu_text_rect = perdu_text.get_rect()
|
||||||
|
perdu_text_rect.centerx = WIDTH // 2
|
||||||
|
perdu_text_rect.centery = HEIGHT // 2
|
||||||
|
screen.blit(perdu_text, perdu_text_rect)
|
||||||
|
pygame.display.flip()
|
||||||
|
pygame.time.wait(3000)
|
||||||
|
|
||||||
|
# Boucle principale
|
||||||
|
running = True
|
||||||
|
while running:
|
||||||
|
score = 0
|
||||||
|
game_over = game()
|
||||||
|
print(game_over)
|
||||||
|
if game_over == False:
|
||||||
|
game_over_screen()
|
||||||
|
running = False
|
||||||
|
|
||||||
|
pygame.quit()
|
128
jeu V3.py
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
import pygame
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
# Paramètres de l'écran
|
||||||
|
WIDTH = 800
|
||||||
|
HEIGHT = 600
|
||||||
|
|
||||||
|
# Couleurs
|
||||||
|
BLACK = (0, 0, 0)
|
||||||
|
WHITE = (255, 255, 255)
|
||||||
|
|
||||||
|
# Paramètres de la balle
|
||||||
|
BALL_WIDTH = 50
|
||||||
|
BALL_HEIGHT = 50
|
||||||
|
BALL_RADIUS = 50//2
|
||||||
|
|
||||||
|
# Paramètres du joueur
|
||||||
|
PLAYER_WIDTH = 80
|
||||||
|
PLAYER_HEIGHT = 80
|
||||||
|
|
||||||
|
# Images choisies
|
||||||
|
player_image = pygame.image.load("V3/joueur.png")
|
||||||
|
player_image = pygame.transform.scale(player_image, (PLAYER_WIDTH, PLAYER_HEIGHT)) # Au cas où l'image fait pas la bonne taille
|
||||||
|
ball_image = pygame.image.load("V3/balle.png")
|
||||||
|
ball_image = pygame.transform.scale(ball_image, (BALL_WIDTH, BALL_HEIGHT)) # Au cas où l'image fait pas la bonne taille
|
||||||
|
background_image = pygame.image.load("V3/terrain.png")
|
||||||
|
background_image = pygame.transform.scale(background_image, (WIDTH, HEIGHT)) # Au cas où l'image fait pas la bonne taille
|
||||||
|
|
||||||
|
# Variables du jeu
|
||||||
|
score = 0
|
||||||
|
font = pygame.font.Font(None, 36)
|
||||||
|
|
||||||
|
# Initialisation de l'écran de jeu
|
||||||
|
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
|
pygame.display.set_caption("Jeu V3")
|
||||||
|
|
||||||
|
def game():
|
||||||
|
global score
|
||||||
|
|
||||||
|
# Position initiale de la balle
|
||||||
|
ball_pos = [WIDTH // 2, BALL_RADIUS]
|
||||||
|
ball_velocity_y = 0
|
||||||
|
ball_velocity_x = 1
|
||||||
|
gravity = 0.1
|
||||||
|
|
||||||
|
# Position initiale du joueur
|
||||||
|
player_pos = [WIDTH // 2 - PLAYER_WIDTH // 2, HEIGHT - PLAYER_HEIGHT - 60]
|
||||||
|
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
running = True
|
||||||
|
|
||||||
|
while running:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Gestion des mouvements du joueur
|
||||||
|
mouse_pos = pygame.mouse.get_pos()
|
||||||
|
player_pos[0] = mouse_pos[0] - PLAYER_WIDTH // 2
|
||||||
|
|
||||||
|
# Mise à jour de la logique du jeu
|
||||||
|
ball_velocity_y += gravity
|
||||||
|
ball_pos[1] += ball_velocity_y
|
||||||
|
|
||||||
|
# Si la balle touche le joueur
|
||||||
|
if ball_pos[1] + BALL_RADIUS >= player_pos[1] and ball_pos[0] >= player_pos[0] and ball_pos[0] <= player_pos[0] + PLAYER_WIDTH:
|
||||||
|
ball_pos[1] = player_pos[1] - BALL_RADIUS
|
||||||
|
ball_velocity_y = -ball_velocity_y
|
||||||
|
score += 1
|
||||||
|
ball_velocity_x += random.uniform(-3, 3)
|
||||||
|
print("Score :", score)
|
||||||
|
|
||||||
|
# Si la balle touche le sol
|
||||||
|
if ball_pos[1] + BALL_RADIUS >= HEIGHT:
|
||||||
|
return False
|
||||||
|
|
||||||
|
elif ball_pos[1] <= BALL_RADIUS:
|
||||||
|
ball_pos[1] = BALL_RADIUS
|
||||||
|
ball_velocity_y = -ball_velocity_y
|
||||||
|
|
||||||
|
ball_pos[0] += ball_velocity_x
|
||||||
|
|
||||||
|
# Si la balle touche les murs
|
||||||
|
if ball_pos[0] <= BALL_RADIUS or ball_pos[0]+BALL_RADIUS//2 >= WIDTH:
|
||||||
|
ball_velocity_x = -ball_velocity_x
|
||||||
|
|
||||||
|
# Dessiner les éléments
|
||||||
|
screen.blit(background_image, (0, 0)) # Le terrain
|
||||||
|
|
||||||
|
screen.blit(ball_image, (ball_pos[0] - BALL_RADIUS, ball_pos[1] - BALL_RADIUS)) # La balle
|
||||||
|
|
||||||
|
screen.blit(player_image, (player_pos[0], player_pos[1])) # Le joueur
|
||||||
|
|
||||||
|
text = font.render("Score: " + str(score), True, WHITE)
|
||||||
|
text_rect = text.get_rect()
|
||||||
|
text_rect.center = (WIDTH // 2, 20)
|
||||||
|
screen.blit(text, text_rect) # Le text
|
||||||
|
|
||||||
|
|
||||||
|
#_____________ Ne rien mettre en dessous _____________
|
||||||
|
pygame.display.flip()
|
||||||
|
clock.tick(60)
|
||||||
|
|
||||||
|
def game_over_screen():
|
||||||
|
screen.fill(BLACK)
|
||||||
|
perdu_text = font.render("Perdu", True, WHITE)
|
||||||
|
perdu_text_rect = perdu_text.get_rect()
|
||||||
|
perdu_text_rect.centerx = WIDTH // 2
|
||||||
|
perdu_text_rect.centery = HEIGHT // 2
|
||||||
|
screen.blit(perdu_text, perdu_text_rect)
|
||||||
|
pygame.display.flip()
|
||||||
|
pygame.time.wait(3000)
|
||||||
|
|
||||||
|
# Boucle principale
|
||||||
|
running = True
|
||||||
|
while running:
|
||||||
|
score = 0
|
||||||
|
game_over = game()
|
||||||
|
print(game_over)
|
||||||
|
if game_over == False:
|
||||||
|
game_over_screen()
|
||||||
|
running = False
|
||||||
|
|
||||||
|
pygame.quit()
|
180
jeu V4.py
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
import pygame
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
# Paramètres de l'écran
|
||||||
|
WIDTH = 800
|
||||||
|
HEIGHT = 600
|
||||||
|
|
||||||
|
# Paramètres de couleurs
|
||||||
|
BLACK = (0, 0, 0)
|
||||||
|
WHITE = (255, 255, 255)
|
||||||
|
|
||||||
|
# Paramètres de la balle
|
||||||
|
BALL_WIDTH = 50
|
||||||
|
BALL_HEIGHT = 50
|
||||||
|
BALL_RADIUS = 50//2
|
||||||
|
|
||||||
|
# Paramètres du joueur
|
||||||
|
PLAYER_WIDTH = 80
|
||||||
|
PLAYER_HEIGHT = 80
|
||||||
|
|
||||||
|
# Paramètres du coeur
|
||||||
|
COEUR_WIDTH = 75
|
||||||
|
COEUR_HEIGHT = COEUR_WIDTH*(440/512)
|
||||||
|
nbcoeur = 1
|
||||||
|
|
||||||
|
# Images choisies
|
||||||
|
player_image = pygame.image.load("V4/joueur.png")
|
||||||
|
player_image = pygame.transform.scale(player_image, (PLAYER_WIDTH, PLAYER_HEIGHT)) # Au cas où l'image fait pas la bonne taille
|
||||||
|
|
||||||
|
ball_image = pygame.image.load("V4/balle.png")
|
||||||
|
ball_image = pygame.transform.scale(ball_image, (BALL_WIDTH, BALL_HEIGHT))
|
||||||
|
|
||||||
|
coeur_image = pygame.image.load("V4/coeur.png")
|
||||||
|
coeur_image = pygame.transform.scale(coeur_image, (COEUR_WIDTH, COEUR_HEIGHT))
|
||||||
|
coeurfaded_image = pygame.image.load("V4/coeurfaded.png")
|
||||||
|
coeurfaded_image = pygame.transform.scale(coeurfaded_image, (COEUR_WIDTH, COEUR_HEIGHT))
|
||||||
|
|
||||||
|
background_image = pygame.image.load("V4/terrain.png")
|
||||||
|
background_image = pygame.transform.scale(background_image, (WIDTH, HEIGHT))
|
||||||
|
|
||||||
|
# Définir les dimensions et la position du rectangle
|
||||||
|
largeur_rectangle = 150
|
||||||
|
hauteur_rectangle = 40
|
||||||
|
x_rectangle = (WIDTH - largeur_rectangle) // 2 # Au milieu horizontalement
|
||||||
|
y_rectangle = 0 # En haut de l'écran
|
||||||
|
|
||||||
|
# Variables du jeu
|
||||||
|
score = 0
|
||||||
|
font = pygame.font.Font(None, 36)
|
||||||
|
dercolsol = 0
|
||||||
|
|
||||||
|
|
||||||
|
# Initialisation de l'écran de jeu
|
||||||
|
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
|
pygame.display.set_caption("Jeu V4")
|
||||||
|
|
||||||
|
|
||||||
|
def game():
|
||||||
|
global score, nbcoeur
|
||||||
|
|
||||||
|
# Position initiale de la balle
|
||||||
|
ball_pos = [WIDTH // 2, BALL_RADIUS]
|
||||||
|
ball_velocity_y = 0
|
||||||
|
ball_velocity_x = 1
|
||||||
|
gravity = 0.1
|
||||||
|
|
||||||
|
# Position initiale du joueur
|
||||||
|
player_pos = [WIDTH // 2 - PLAYER_WIDTH // 2, HEIGHT - PLAYER_HEIGHT - 60]
|
||||||
|
|
||||||
|
nbcoeur = 1
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
running = True
|
||||||
|
dercolsol = 0
|
||||||
|
|
||||||
|
while running:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Gestion des mouvements du joueur
|
||||||
|
mouse_pos = pygame.mouse.get_pos()
|
||||||
|
player_pos[0] = mouse_pos[0] - PLAYER_WIDTH // 2
|
||||||
|
|
||||||
|
# Mise à jour de la logique du jeu
|
||||||
|
ball_velocity_y += gravity
|
||||||
|
ball_pos[1] += ball_velocity_y
|
||||||
|
|
||||||
|
# Si la balle touche le joueur
|
||||||
|
if ball_pos[1] + BALL_RADIUS >= player_pos[1] and ball_pos[0] >= player_pos[0] and ball_pos[0] <= player_pos[0] + PLAYER_WIDTH:
|
||||||
|
ball_pos[1] = player_pos[1] - BALL_RADIUS
|
||||||
|
ball_velocity_y = -ball_velocity_y
|
||||||
|
score += 1
|
||||||
|
ball_velocity_x += random.uniform(-3, 3)
|
||||||
|
print("Score :", score)
|
||||||
|
|
||||||
|
# Si la balle touche le sol
|
||||||
|
if ball_pos[1] + BALL_RADIUS >= HEIGHT:
|
||||||
|
current_time = pygame.time.get_ticks()
|
||||||
|
if current_time - dercolsol >= 1000 :
|
||||||
|
if nbcoeur >= 1:
|
||||||
|
nbcoeur -= 1 # Décrémenter le nombre de vies
|
||||||
|
dercolsol = current_time
|
||||||
|
ball_velocity_y = -ball_velocity_y
|
||||||
|
|
||||||
|
else:
|
||||||
|
print(nbcoeur)
|
||||||
|
return False
|
||||||
|
pass
|
||||||
|
|
||||||
|
if current_time - dercolsol <= 1000:
|
||||||
|
print(nbcoeur)
|
||||||
|
|
||||||
|
else:
|
||||||
|
nbcoeur = nbcoeur
|
||||||
|
print(nbcoeur)
|
||||||
|
|
||||||
|
# Si la balle touche le plafond
|
||||||
|
elif ball_pos[1] <= BALL_RADIUS:
|
||||||
|
ball_pos[1] = BALL_RADIUS
|
||||||
|
ball_velocity_y = -ball_velocity_y
|
||||||
|
|
||||||
|
ball_pos[0] += ball_velocity_x
|
||||||
|
|
||||||
|
# Si la balle touche les murs
|
||||||
|
if ball_pos[0] <= BALL_RADIUS or ball_pos[0]+BALL_RADIUS//2 >= WIDTH:
|
||||||
|
ball_velocity_x = -ball_velocity_x
|
||||||
|
|
||||||
|
# Dessiner les éléments
|
||||||
|
screen.blit(background_image, (0, 0)) # Le terrain
|
||||||
|
|
||||||
|
screen.blit(ball_image, (ball_pos[0] - BALL_RADIUS, ball_pos[1] - BALL_RADIUS)) # La balle
|
||||||
|
|
||||||
|
screen.blit(player_image, (player_pos[0], player_pos[1])) # Le joueur
|
||||||
|
|
||||||
|
# Afficher le nombre de coeur(s)
|
||||||
|
if nbcoeur == 1 :
|
||||||
|
screen.blit(coeur_image, (25, 25)) # Le coeur
|
||||||
|
|
||||||
|
if nbcoeur == 0:
|
||||||
|
screen.blit(coeurfaded_image, (25,25)) # Le coeur plus transparent
|
||||||
|
|
||||||
|
# Afficher le score
|
||||||
|
pygame.draw.rect(screen, BLACK, (x_rectangle, y_rectangle, largeur_rectangle, hauteur_rectangle))
|
||||||
|
|
||||||
|
text = font.render("Score: " + str(score), True, WHITE)
|
||||||
|
text_rect = text.get_rect()
|
||||||
|
text_rect.center = (WIDTH // 2, 20)
|
||||||
|
screen.blit(text, text_rect) # Le score
|
||||||
|
|
||||||
|
#_____________ Ne rien mettre en dessous _____________
|
||||||
|
pygame.display.flip()
|
||||||
|
clock.tick(60)
|
||||||
|
|
||||||
|
def game_over_screen():
|
||||||
|
screen.fill(BLACK)
|
||||||
|
perdu_text = font.render("Perdu", True, WHITE)
|
||||||
|
perdu_text_rect = perdu_text.get_rect()
|
||||||
|
perdu_text_rect.centerx = WIDTH // 2
|
||||||
|
perdu_text_rect.centery = HEIGHT // 2
|
||||||
|
screen.blit(perdu_text, perdu_text_rect)
|
||||||
|
pygame.display.flip()
|
||||||
|
pygame.time.wait(3000)
|
||||||
|
|
||||||
|
# Boucle principale
|
||||||
|
running = True
|
||||||
|
while running:
|
||||||
|
score = 0
|
||||||
|
nbcoeur = 1
|
||||||
|
dercolsol = 0
|
||||||
|
game_over = game()
|
||||||
|
print(game_over)
|
||||||
|
if game_over == False:
|
||||||
|
game_over_screen()
|
||||||
|
running = False
|
||||||
|
|
||||||
|
pygame.quit()
|
188
jeu V5.py
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
import pygame
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
# Paramètres de l'écran
|
||||||
|
WIDTH = 800
|
||||||
|
HEIGHT = 600
|
||||||
|
|
||||||
|
# Paramètres de couleurs
|
||||||
|
BLACK = (0, 0, 0)
|
||||||
|
WHITE = (255, 255, 255)
|
||||||
|
|
||||||
|
# Paramètres de la balle
|
||||||
|
BALL_WIDTH = 50
|
||||||
|
BALL_HEIGHT = 50
|
||||||
|
BALL_RADIUS = 50//2
|
||||||
|
|
||||||
|
# Paramètres du joueur
|
||||||
|
PLAYER_WIDTH = 80
|
||||||
|
PLAYER_HEIGHT = 80
|
||||||
|
|
||||||
|
# Paramètres du coeur
|
||||||
|
COEUR_WIDTH = 75
|
||||||
|
COEUR_HEIGHT = COEUR_WIDTH*(440/512)
|
||||||
|
nbcoeur = 1
|
||||||
|
|
||||||
|
# Images choisies
|
||||||
|
player_image = pygame.image.load("V5/joueur.png")
|
||||||
|
player_image = pygame.transform.scale(player_image, (PLAYER_WIDTH, PLAYER_HEIGHT)) # Au cas où l'image fait pas la bonne taille
|
||||||
|
|
||||||
|
ball_image = pygame.image.load("V5/balle.png")
|
||||||
|
ball_image = pygame.transform.scale(ball_image, (BALL_WIDTH, BALL_HEIGHT))
|
||||||
|
|
||||||
|
coeur_image = pygame.image.load("V5/coeur.png")
|
||||||
|
coeur_image = pygame.transform.scale(coeur_image, (COEUR_WIDTH, COEUR_HEIGHT))
|
||||||
|
coeurfaded_image = pygame.image.load("V5/coeurfaded.png")
|
||||||
|
coeurfaded_image = pygame.transform.scale(coeurfaded_image, (COEUR_WIDTH, COEUR_HEIGHT))
|
||||||
|
|
||||||
|
background_image = pygame.image.load("V5/terrain.png")
|
||||||
|
background_image = pygame.transform.scale(background_image, (WIDTH, HEIGHT))
|
||||||
|
|
||||||
|
# Définir les dimensions et la position du rectangle
|
||||||
|
largeur_rectangle = 150
|
||||||
|
hauteur_rectangle = 40
|
||||||
|
x_rectangle = (WIDTH - largeur_rectangle) // 2 # Au milieu horizontalement
|
||||||
|
y_rectangle = 0 # En haut de l'écran
|
||||||
|
|
||||||
|
# Variables du jeu
|
||||||
|
score = 0
|
||||||
|
font = pygame.font.Font(None, 36)
|
||||||
|
dercolsol = 0
|
||||||
|
nbrotation = 0
|
||||||
|
|
||||||
|
|
||||||
|
# Initialisation de l'écran de jeu
|
||||||
|
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
|
pygame.display.set_caption("Jeu V5")
|
||||||
|
|
||||||
|
|
||||||
|
def game():
|
||||||
|
global score, nbcoeur
|
||||||
|
|
||||||
|
# Position initiale de la balle
|
||||||
|
ball_pos = [WIDTH // 2, BALL_RADIUS]
|
||||||
|
ball_velocity_y = 0
|
||||||
|
ball_velocity_x = 1
|
||||||
|
gravity = 0.1
|
||||||
|
|
||||||
|
# Position initiale du joueur
|
||||||
|
player_pos = [WIDTH // 2 - PLAYER_WIDTH // 2, HEIGHT - PLAYER_HEIGHT - 60]
|
||||||
|
|
||||||
|
nbcoeur = 1
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
running = True
|
||||||
|
dercolsol = 0
|
||||||
|
nbrotation = 0
|
||||||
|
while running:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Gestion des mouvements du joueur
|
||||||
|
mouse_pos = pygame.mouse.get_pos()
|
||||||
|
player_pos[0] = mouse_pos[0] - PLAYER_WIDTH // 2
|
||||||
|
|
||||||
|
# Mise à jour de la logique du jeu
|
||||||
|
ball_velocity_y += gravity
|
||||||
|
ball_pos[1] += ball_velocity_y
|
||||||
|
|
||||||
|
# Si la balle touche le joueur
|
||||||
|
if ball_pos[1] + BALL_RADIUS >= player_pos[1] and ball_pos[0] >= player_pos[0] and ball_pos[0] <= player_pos[0] + PLAYER_WIDTH:
|
||||||
|
ball_pos[1] = player_pos[1] - BALL_RADIUS
|
||||||
|
ball_velocity_y = -ball_velocity_y
|
||||||
|
score += 1
|
||||||
|
ball_velocity_x += random.uniform(-3, 3)
|
||||||
|
print("Score :", score)
|
||||||
|
nbrotation+=5
|
||||||
|
|
||||||
|
# Si la balle touche le sol
|
||||||
|
if ball_pos[1] + BALL_RADIUS >= HEIGHT:
|
||||||
|
current_time = pygame.time.get_ticks()
|
||||||
|
if current_time - dercolsol >= 1000 :
|
||||||
|
if nbcoeur >= 1:
|
||||||
|
nbcoeur -= 1 # Décrémenter le nombre de vies
|
||||||
|
dercolsol = current_time
|
||||||
|
ball_velocity_y = -ball_velocity_y
|
||||||
|
nbrotation+=5
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
print(nbcoeur)
|
||||||
|
return False
|
||||||
|
pass
|
||||||
|
|
||||||
|
if current_time - dercolsol <= 1000:
|
||||||
|
print(nbcoeur)
|
||||||
|
|
||||||
|
else:
|
||||||
|
nbcoeur = nbcoeur
|
||||||
|
print(nbcoeur)
|
||||||
|
|
||||||
|
# Si la balle touche le plafond
|
||||||
|
elif ball_pos[1] <= BALL_RADIUS:
|
||||||
|
ball_pos[1] = BALL_RADIUS
|
||||||
|
ball_velocity_y = -ball_velocity_y
|
||||||
|
nbrotation+=5
|
||||||
|
|
||||||
|
ball_pos[0] += ball_velocity_x
|
||||||
|
|
||||||
|
# Si la balle touche les murs
|
||||||
|
if ball_pos[0] <= BALL_RADIUS or ball_pos[0]+BALL_RADIUS//2 >= WIDTH:
|
||||||
|
ball_velocity_x = -ball_velocity_x
|
||||||
|
nbrotation+=5
|
||||||
|
|
||||||
|
# Dessiner les éléments
|
||||||
|
screen.blit(background_image, (0, 0)) # Le terrain
|
||||||
|
|
||||||
|
nbrotation+=1
|
||||||
|
screen.blit(pygame.transform.rotate(ball_image, nbrotation), (ball_pos[0] - BALL_RADIUS, ball_pos[1] - BALL_RADIUS)) # La balle
|
||||||
|
|
||||||
|
screen.blit(player_image, (player_pos[0], player_pos[1])) # Le joueur
|
||||||
|
|
||||||
|
# Afficher le nombre de coeur(s)
|
||||||
|
if nbcoeur == 1 :
|
||||||
|
screen.blit(coeur_image, (25, 25)) # Le coeur
|
||||||
|
|
||||||
|
if nbcoeur == 0:
|
||||||
|
screen.blit(coeurfaded_image, (25,25)) # Le coeur plus transparent
|
||||||
|
|
||||||
|
# Afficher le score
|
||||||
|
pygame.draw.rect(screen, BLACK, (x_rectangle, y_rectangle, largeur_rectangle, hauteur_rectangle))
|
||||||
|
|
||||||
|
text = font.render("Score : " + str(score), True, WHITE)
|
||||||
|
text_rect = text.get_rect()
|
||||||
|
text_rect.center = (WIDTH // 2, 20)
|
||||||
|
screen.blit(text, text_rect) # Le score
|
||||||
|
|
||||||
|
#_____________ Ne rien mettre en dessous _____________
|
||||||
|
pygame.display.flip()
|
||||||
|
clock.tick(60)
|
||||||
|
|
||||||
|
def game_over_screen():
|
||||||
|
screen.fill(BLACK)
|
||||||
|
perdu_text = font.render("Perdu", True, WHITE)
|
||||||
|
perdu_text_rect = perdu_text.get_rect()
|
||||||
|
perdu_text_rect.centerx = WIDTH // 2
|
||||||
|
perdu_text_rect.centery = HEIGHT // 2
|
||||||
|
screen.blit(perdu_text, perdu_text_rect)
|
||||||
|
pygame.display.flip()
|
||||||
|
pygame.time.wait(3000)
|
||||||
|
|
||||||
|
# Boucle principale
|
||||||
|
running = True
|
||||||
|
while running:
|
||||||
|
score = 0
|
||||||
|
nbcoeur = 1
|
||||||
|
dercolsol = 0
|
||||||
|
nbrotation = 0
|
||||||
|
game_over = game()
|
||||||
|
print(game_over)
|
||||||
|
if game_over == False:
|
||||||
|
game_over_screen()
|
||||||
|
running = False
|
||||||
|
|
||||||
|
pygame.quit()
|
BIN
sprites/balle.png
Normal file
After Width: | Height: | Size: 99 KiB |
BIN
sprites/balle1.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
sprites/big_terrain.PNG
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
sprites/coeur.jpg
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
sprites/coeur.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
sprites/coeur.psd
Normal file
BIN
sprites/joueur.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
sprites/terrain.png
Normal file
After Width: | Height: | Size: 143 KiB |
BIN
sprites/terrain.psd
Normal file
BIN
sprites/terrain2.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
sprites/vecteezy/arbitre.png
Normal file
After Width: | Height: | Size: 266 KiB |
BIN
sprites/vecteezy/asme.png
Normal file
After Width: | Height: | Size: 202 KiB |
BIN
sprites/vecteezy/avocat.png
Normal file
After Width: | Height: | Size: 360 KiB |
BIN
sprites/vecteezy/détourée/arbitre.jpg
Normal file
After Width: | Height: | Size: 89 KiB |
BIN
sprites/vecteezy/détourée/arbitre.png
Normal file
After Width: | Height: | Size: 266 KiB |
BIN
sprites/vecteezy/détourée/arbitre.psd
Normal file
BIN
sprites/vecteezy/détourée/asme.jpg
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
sprites/vecteezy/détourée/asme.png
Normal file
After Width: | Height: | Size: 202 KiB |
BIN
sprites/vecteezy/détourée/asme.psd
Normal file
BIN
sprites/vecteezy/détourée/avocat.jpg
Normal file
After Width: | Height: | Size: 118 KiB |
BIN
sprites/vecteezy/détourée/avocat.png
Normal file
After Width: | Height: | Size: 360 KiB |
BIN
sprites/vecteezy/détourée/avocat.psd
Normal file
BIN
sprites/vecteezy/détourée/explorer.jpg
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
sprites/vecteezy/détourée/explorer.png
Normal file
After Width: | Height: | Size: 115 KiB |
BIN
sprites/vecteezy/détourée/explorer.psd
Normal file
BIN
sprites/vecteezy/détourée/fou.jpg
Normal file
After Width: | Height: | Size: 91 KiB |
BIN
sprites/vecteezy/détourée/fou.png
Normal file
After Width: | Height: | Size: 280 KiB |
BIN
sprites/vecteezy/détourée/fou.psd
Normal file
BIN
sprites/vecteezy/détourée/lampe.jpg
Normal file
After Width: | Height: | Size: 137 KiB |
BIN
sprites/vecteezy/détourée/lampe.png
Normal file
After Width: | Height: | Size: 216 KiB |
BIN
sprites/vecteezy/détourée/lampe.psd
Normal file
BIN
sprites/vecteezy/détourée/muscu.jpg
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
sprites/vecteezy/détourée/muscu.png
Normal file
After Width: | Height: | Size: 119 KiB |
BIN
sprites/vecteezy/détourée/muscu.psd
Normal file
BIN
sprites/vecteezy/détourée/plage.jpg
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
sprites/vecteezy/détourée/plage.png
Normal file
After Width: | Height: | Size: 120 KiB |
BIN
sprites/vecteezy/détourée/plage.psd
Normal file
BIN
sprites/vecteezy/détourée/ski.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
sprites/vecteezy/détourée/vacances.jpg
Normal file
After Width: | Height: | Size: 39 KiB |
BIN
sprites/vecteezy/détourée/vacances.png
Normal file
After Width: | Height: | Size: 91 KiB |
BIN
sprites/vecteezy/détourée/vacances.psd
Normal file
BIN
sprites/vecteezy/explorer.png
Normal file
After Width: | Height: | Size: 115 KiB |
BIN
sprites/vecteezy/fou.png
Normal file
After Width: | Height: | Size: 280 KiB |
BIN
sprites/vecteezy/lampe.png
Normal file
After Width: | Height: | Size: 216 KiB |
BIN
sprites/vecteezy/muscu.png
Normal file
After Width: | Height: | Size: 119 KiB |
BIN
sprites/vecteezy/plage.png
Normal file
After Width: | Height: | Size: 120 KiB |
BIN
sprites/vecteezy/ski.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
sprites/vecteezy/vacances.png
Normal file
After Width: | Height: | Size: 91 KiB |