Adaptation au nouvel ecs #3
|
@ -3,8 +3,7 @@ Le jeux principale.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from math import e
|
import math
|
||||||
import time
|
|
||||||
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
|
||||||
|
@ -20,6 +19,7 @@ from plugins.render import (
|
||||||
TextSize,
|
TextSize,
|
||||||
)
|
)
|
||||||
from plugins.timing import Delta, Time
|
from plugins.timing import Delta, Time
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
class GameMode(Enum):
|
class GameMode(Enum):
|
||||||
|
@ -140,7 +140,7 @@ def __spawn_elements(world: World):
|
||||||
world.new_entity().set(
|
world.new_entity().set(
|
||||||
Origin(Vec2(0, 0)),
|
Origin(Vec2(0, 0)),
|
||||||
Scale(Vec2(render.WIDTH, 10)),
|
Scale(Vec2(render.WIDTH, 10)),
|
||||||
Position(Vec2(0, render.HEIGHT - 50)),
|
Position(Vec2(0, render.HEIGHT)),
|
||||||
physics.Solid(),
|
physics.Solid(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ def __spawn_elements(world: World):
|
||||||
world.new_entity().set(
|
world.new_entity().set(
|
||||||
Origin(Vec2(0, 1)),
|
Origin(Vec2(0, 1)),
|
||||||
Scale(Vec2(render.WIDTH, 10)),
|
Scale(Vec2(render.WIDTH, 10)),
|
||||||
Position(Vec2(0, 50)),
|
Position(Vec2(0, 0)),
|
||||||
physics.Solid(),
|
physics.Solid(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -184,6 +184,7 @@ def __spawn_elements(world: World):
|
||||||
else None,
|
else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
__spawn_ball(world)
|
||||||
__spawn_ball(world)
|
__spawn_ball(world)
|
||||||
|
|
||||||
# Initialisation des scores
|
# Initialisation des scores
|
||||||
|
@ -201,7 +202,22 @@ def __spawn_elements(world: World):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def __angle_to_vec2(angle_degrees: float, magnitude: float):
|
||||||
raphael marked this conversation as resolved
Outdated
|
|||||||
|
# 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):
|
def __spawn_ball(world: World):
|
||||||
|
# random angle
|
||||||
|
angle = random.randint(0, 360)
|
||||||
|
velocity = __angle_to_vec2(angle, 200)
|
||||||
|
|
||||||
# Balle
|
# Balle
|
||||||
raphael marked this conversation as resolved
Outdated
tipragot
commented
Manque de doc Manque de doc
|
|||||||
world.new_entity().set(
|
world.new_entity().set(
|
||||||
SpriteBundle(
|
SpriteBundle(
|
||||||
|
@ -212,7 +228,8 @@ def __spawn_ball(world: World):
|
||||||
Vec2(0.5),
|
Vec2(0.5),
|
||||||
),
|
),
|
||||||
Ball(),
|
Ball(),
|
||||||
physics.Velocity(Vec2(-200, -100)),
|
#
|
||||||
|
physics.Velocity(Vec2(velocity)),
|
||||||
raphael marked this conversation as resolved
Outdated
tipragot
commented
Manque de doc Manque de doc
|
|||||||
physics.CollisionHandler(__bounce_on_player),
|
physics.CollisionHandler(__bounce_on_player),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue
Manque de doc