Amélioration du bot pour qu'il tire dans la zone la plus éloigné du joueur #4

Merged
raphael merged 10 commits from smart-bot into main 2024-01-05 17:03:16 +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 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):
# 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
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)),
physics.CollisionHandler(__bounce_on_player), physics.CollisionHandler(__bounce_on_player),
) )