From a6f74977c64ee3ef3f78cddae8b890931b770939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Thu, 4 Jan 2024 17:55:42 +0100 Subject: [PATCH] correction des reviews --- src/scenes/game.py | 51 +++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/scenes/game.py b/src/scenes/game.py index 960d266..1f4dbff 100644 --- a/src/scenes/game.py +++ b/src/scenes/game.py @@ -3,7 +3,6 @@ Le jeux principale. """ from enum import Enum -import math from engine import Plugin, Scene from engine.ecs import Entity, World from engine.math import Vec2 @@ -87,29 +86,29 @@ class Speed(int): class Player1Score(int): """ - Composant qui represente le score du joueur 1. + Ressource qui represente le score du joueur 1. """ class Player2Score(int): """ - Composant qui represente le score du joueur 2. + Ressource qui represente le score du joueur 2. """ class Score: """ - Composant qui represente les scores affichés a l'ecran. + Composant qui marque l'entité comme étant l'affichage du score. """ class StartAnimation(float): """ - Composant qui represente un le moment auxquel on a lancé l'animation + Composant qui represente un le moment auxquel on a lancé l'animation du compte a rebours """ -def __spawn_elements(world: World): +def __spawn_ellements(world: World): """ La fonction permet de initializer les ellements de la scene. """ @@ -184,7 +183,6 @@ def __spawn_elements(world: World): else None, ) - __spawn_ball(world) __spawn_ball(world) # Initialisation des scores @@ -202,21 +200,12 @@ def __spawn_elements(world: World): ) -def __angle_to_vec2(angle_degrees: float, magnitude: float): - # Convertir l'angle de degrés à radians - angle_radians = math.radians(angle_degrees) - - # Calculer les coordonnées x et y - x = magnitude * math.cos(angle_radians) - y = magnitude * math.sin(angle_radians) - - return Vec2(x, y) - - def __spawn_ball(world: World): - # random angle - angle = random.randint(0, 360) - velocity = __angle_to_vec2(angle, 200) + """ + Fonction qui fait apparaitre une balle avec une velocitée aleatoire + """ + # random velocité + velocity = Vec2(2 * random.randint(100, 200), random.randint(100, 200)) # mouvement a droite ou a gauche if random.randint(0, 1) == 0: @@ -239,6 +228,9 @@ def __spawn_ball(world: World): def __bounce_on_player(a: Entity, b: Entity): + """ + Fonction qui decrit se qui se passe lorque la ball entre en collision avec un joueur + """ if Player1 in b or Player2 in b: speed = a[physics.Velocity].length a[physics.Velocity] = a[physics.Velocity].normalized @@ -250,11 +242,17 @@ def __bounce_on_player(a: Entity, b: Entity): def __bounce_on_player_simul(a: Entity, b: Entity): + """ + Fonction qui fait une simulation de la balle + """ __bounce_on_player(a, b) return RightWall not in b def __bounce_on_left_wall(a: Entity, b: Entity): + """ + Fonction qui decrit se qui se passe lorque la ball entre en collision avec le mur de gauche + """ if Ball in b: world = a.world world[Player2Score] += 1 @@ -264,6 +262,9 @@ def __bounce_on_left_wall(a: Entity, b: Entity): def __bounce_on_right_wall(a: Entity, b: Entity): + """ + Fonction qui decrit se qui se passe lorque la ball entre en collision avec le mur de droite + """ if Ball in b: world = a.world world[Player1Score] += 1 @@ -308,7 +309,7 @@ def __update_move(world: World): def _update_bot(world: World): """ - Test. + Fonction qui update les mouvement du bot """ ball_query = world.query(Position, physics.Velocity, physics.CollisionHandler) if ball_query == set(): @@ -366,6 +367,10 @@ def __animation(world: World, number: int): def __update_animation(world: World): + """ + Fonction qui permet de mettre a jour l'animation du compte a rebours. + """ + for animation in world.query(StartAnimation): time = world[Time] - animation[StartAnimation] @@ -383,7 +388,7 @@ def __update_animation(world: World): __SCENE = Scene( - [__spawn_elements], + [__spawn_ellements], [__update_move, __update_animation], [], )