Adaptation au nouvel ecs #3
|
@ -3,7 +3,6 @@ Le jeux principale.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import math
|
|
||||||
from engine import Plugin, Scene
|
from engine import Plugin, Scene
|
||||||
from engine.ecs import Entity, World
|
from engine.ecs import Entity, World
|
||||||
from engine.math import Vec2
|
from engine.math import Vec2
|
||||||
|
@ -87,29 +86,29 @@ class Speed(int):
|
||||||
|
|
||||||
class Player1Score(int):
|
class Player1Score(int):
|
||||||
"""
|
"""
|
||||||
Composant qui represente le score du joueur 1.
|
Ressource qui represente le score du joueur 1.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raphael marked this conversation as resolved
|
|||||||
|
|
||||||
class Player2Score(int):
|
class Player2Score(int):
|
||||||
"""
|
"""
|
||||||
Composant qui represente le score du joueur 2.
|
Ressource qui represente le score du joueur 2.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raphael marked this conversation as resolved
tipragot
commented
C'est une ressource C'est une ressource
|
|||||||
|
|
||||||
class Score:
|
class Score:
|
||||||
"""
|
"""
|
||||||
Composant qui represente les scores affichés a l'ecran.
|
Composant qui marque l'entité comme étant l'affichage du score.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raphael marked this conversation as resolved
tipragot
commented
Plutot: marque l'entité comme étant l'affichage du score Plutot: marque l'entité comme étant l'affichage du score
|
|||||||
|
|
||||||
class StartAnimation(float):
|
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
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raphael marked this conversation as resolved
tipragot
commented
Préciser de quel animation on parle Préciser de quel animation on parle
|
|||||||
|
|
||||||
def __spawn_elements(world: World):
|
def __spawn_ellements(world: World):
|
||||||
"""
|
"""
|
||||||
La fonction permet de initializer les ellements de la scene.
|
La fonction permet de initializer les ellements de la scene.
|
||||||
"""
|
"""
|
||||||
|
@ -184,7 +183,6 @@ def __spawn_elements(world: World):
|
||||||
else None,
|
else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
__spawn_ball(world)
|
|
||||||
__spawn_ball(world)
|
__spawn_ball(world)
|
||||||
|
|
||||||
# Initialisation des scores
|
# 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):
|
def __spawn_ball(world: World):
|
||||||
# random angle
|
"""
|
||||||
angle = random.randint(0, 360)
|
Fonction qui fait apparaitre une balle avec une velocitée aleatoire
|
||||||
velocity = __angle_to_vec2(angle, 200)
|
"""
|
||||||
|
# random velocité
|
||||||
|
velocity = Vec2(2 * random.randint(100, 200), random.randint(100, 200))
|
||||||
|
|
||||||
# mouvement a droite ou a gauche
|
# mouvement a droite ou a gauche
|
||||||
if random.randint(0, 1) == 0:
|
if random.randint(0, 1) == 0:
|
||||||
|
@ -239,6 +228,9 @@ def __spawn_ball(world: World):
|
||||||
|
|
||||||
|
|
||||||
def __bounce_on_player(a: Entity, b: Entity):
|
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:
|
if Player1 in b or Player2 in b:
|
||||||
speed = a[physics.Velocity].length
|
speed = a[physics.Velocity].length
|
||||||
a[physics.Velocity] = a[physics.Velocity].normalized
|
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):
|
def __bounce_on_player_simul(a: Entity, b: Entity):
|
||||||
|
"""
|
||||||
|
Fonction qui fait une simulation de la balle
|
||||||
|
"""
|
||||||
__bounce_on_player(a, b)
|
__bounce_on_player(a, b)
|
||||||
return RightWall not in b
|
return RightWall not in b
|
||||||
|
|
||||||
|
|
||||||
def __bounce_on_left_wall(a: Entity, b: Entity):
|
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:
|
if Ball in b:
|
||||||
world = a.world
|
world = a.world
|
||||||
world[Player2Score] += 1
|
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):
|
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:
|
if Ball in b:
|
||||||
world = a.world
|
world = a.world
|
||||||
world[Player1Score] += 1
|
world[Player1Score] += 1
|
||||||
|
@ -308,7 +309,7 @@ def __update_move(world: World):
|
||||||
|
|
||||||
def _update_bot(world: World):
|
def _update_bot(world: World):
|
||||||
"""
|
"""
|
||||||
Test.
|
Fonction qui update les mouvement du bot
|
||||||
"""
|
"""
|
||||||
ball_query = world.query(Position, physics.Velocity, physics.CollisionHandler)
|
ball_query = world.query(Position, physics.Velocity, physics.CollisionHandler)
|
||||||
if ball_query == set():
|
if ball_query == set():
|
||||||
|
@ -366,6 +367,10 @@ def __animation(world: World, number: int):
|
||||||
|
|
||||||
|
|
||||||
def __update_animation(world: World):
|
def __update_animation(world: World):
|
||||||
|
"""
|
||||||
|
Fonction qui permet de mettre a jour l'animation du compte a rebours.
|
||||||
|
"""
|
||||||
|
|
||||||
for animation in world.query(StartAnimation):
|
for animation in world.query(StartAnimation):
|
||||||
time = world[Time] - animation[StartAnimation]
|
time = world[Time] - animation[StartAnimation]
|
||||||
|
|
||||||
|
@ -383,7 +388,7 @@ def __update_animation(world: World):
|
||||||
|
|
||||||
|
|
||||||
__SCENE = Scene(
|
__SCENE = Scene(
|
||||||
[__spawn_elements],
|
[__spawn_ellements],
|
||||||
[__update_move, __update_animation],
|
[__update_move, __update_animation],
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue
C'est une ressource