Adaptation au nouvel ecs #3

Merged
tipragot merged 6 commits from ecs-friendly into main 2024-01-05 16:26:33 +00:00
Showing only changes of commit e8fc974065 - Show all commits

View file

@ -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),
)