diff --git a/src/scenes/game.py b/src/scenes/game.py index 8bd7dfe..b31033c 100644 --- a/src/scenes/game.py +++ b/src/scenes/game.py @@ -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,12 +334,7 @@ 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 + return True def __bonus_touched(ball: Entity, bonus: Entity): @@ -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], [], )