From e8fc974065099cce078642fd51223118928b7967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Thu, 4 Jan 2024 17:29:56 +0100 Subject: [PATCH] modification du placement des murs invisibles --- src/scenes/game.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/scenes/game.py b/src/scenes/game.py index ed062bc..28503a2 100644 --- a/src/scenes/game.py +++ b/src/scenes/game.py @@ -3,8 +3,7 @@ Le jeux principale. """ from enum import Enum -from math import e -import time +import math from engine import Plugin, Scene from engine.ecs import Entity, World from engine.math import Vec2 @@ -20,6 +19,7 @@ from plugins.render import ( TextSize, ) from plugins.timing import Delta, Time +import random class GameMode(Enum): @@ -140,7 +140,7 @@ def __spawn_elements(world: World): world.new_entity().set( Origin(Vec2(0, 0)), Scale(Vec2(render.WIDTH, 10)), - Position(Vec2(0, render.HEIGHT - 50)), + Position(Vec2(0, render.HEIGHT)), physics.Solid(), ) @@ -148,7 +148,7 @@ def __spawn_elements(world: World): world.new_entity().set( Origin(Vec2(0, 1)), Scale(Vec2(render.WIDTH, 10)), - Position(Vec2(0, 50)), + Position(Vec2(0, 0)), physics.Solid(), ) @@ -184,6 +184,7 @@ def __spawn_elements(world: World): else None, ) + __spawn_ball(world) __spawn_ball(world) # Initialisation des scores @@ -201,7 +202,22 @@ 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 x, y + + def __spawn_ball(world: World): + # random angle + angle = random.randint(0, 360) + velocity = __angle_to_vec2(angle, 200) + # Balle world.new_entity().set( SpriteBundle( @@ -212,7 +228,8 @@ def __spawn_ball(world: World): Vec2(0.5), ), Ball(), - physics.Velocity(Vec2(-200, -100)), + # + physics.Velocity(Vec2(velocity)), physics.CollisionHandler(__bounce_on_player), )