La balle ne rebondis plus sur les bonus

This commit is contained in:
Tipragot 2024-01-06 15:17:50 +01:00
parent 8342157598
commit 24d57d6321

View file

@ -16,7 +16,6 @@ from plugins.render import (
TextBundle,
Text,
TextSize,
Texture,
)
from plugins.timing import Delta, Time
import random
@ -299,7 +298,6 @@ def __spawn_bonus(world: World):
Vec2(70),
Vec2(0.5),
),
physics.Solid(),
bonus,
)
@ -336,11 +334,6 @@ def __collision_with_ball(a: Entity, b: Entity):
del player[LastPlayerTurn]
b.set(LastPlayerTurn())
return __bounce_on_player(a, b)
elif Bonus in b:
if Ball in a:
return __bonus_touched(a, b)
return False
else:
return True
@ -513,6 +506,34 @@ def _update_bot(world: World):
bot[Position].y += (diff / abs(diff)) * bot[Speed] * world[Delta]
def __check_bonus_collision(world: World):
"""
Fonction qui permet de voir si un bonus est entrée en collision avec une entité.
"""
def __collision_handler(a: Entity, b: Entity):
if Bonus in b:
__bonus_touched(a, b)
return False
return True
for entity in world.query(Bonus):
entity.set(physics.Solid())
for entity in world.query(Ball):
simulated_ball = world.new_entity()
simulated_ball.set(
Position(entity[Position]),
Scale(entity[Scale]),
physics.Velocity(entity[physics.Velocity]),
Origin(entity[Origin]),
physics.CollisionHandler(__collision_handler),
)
physics.move_entity(simulated_ball, entity[physics.Velocity] * world[Delta])
simulated_ball.destroy()
for entity in world.query(Bonus):
entity.remove(physics.Solid)
def __update_scores(world: World, ball: Entity):
"""
La fontion permet de mettre a jour les scores.
@ -580,7 +601,7 @@ def __update_bonus_time(world: World):
__SCENE = Scene(
[__spawn_ellements],
[__update_move, __update_animation, __update_bonus_time],
[__update_move, __check_bonus_collision, __update_animation, __update_bonus_time],
[],
)