From f9d6f39dd66e79c8bb027ea7af91a4b55850173f Mon Sep 17 00:00:00 2001 From: Tipragot Date: Sun, 7 Jan 2024 11:27:53 +0100 Subject: [PATCH 1/3] Save unfinished work --- src/plugins/physics.py | 4 ++-- src/scenes/game.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/plugins/physics.py b/src/plugins/physics.py index 305aed2..52ef0e2 100644 --- a/src/plugins/physics.py +++ b/src/plugins/physics.py @@ -173,7 +173,7 @@ def move_entity(entity: Entity, movement: Vec2, disable_callback: bool = False): if normal.y != 0: movement.y *= -1 entity[Velocity].y *= -1 - movement /= entity[Velocity] + # movement /= entity.get(Velocity, Vec2(1)) if obstacle is not None and not disable_callback: if not entity.get( CollisionHandler, CollisionHandler(lambda e, o: True) @@ -183,7 +183,7 @@ def move_entity(entity: Entity, movement: Vec2, disable_callback: bool = False): CollisionHandler, CollisionHandler(lambda e, o: True) ).callback(obstacle, entity): break - movement *= entity[Velocity] + # movement *= entity[Velocity] counter += 1 diff --git a/src/scenes/game.py b/src/scenes/game.py index a7302fa..eb13b6c 100644 --- a/src/scenes/game.py +++ b/src/scenes/game.py @@ -537,11 +537,19 @@ def _update_bot(world: World): player = world.query(Player1).pop() # On trouve l'endroit ou la balle va arriver sur le mur de droite + for entity in world.query(RightWall): + entity[Position].x -= 122 + for entity in world.query(LeftWall): + entity[Position].x += 122 bot.remove(Solid) right_wall_ball = __simulate_wall_position(ball, RightWall) right_touch_height = right_wall_ball[Position].y right_wall_ball.destroy() bot.set(Solid()) + for entity in world.query(RightWall): + entity[Position].x += 122 + for entity in world.query(LeftWall): + entity[Position].x -= 122 # On teste différentes possitions pour voir laquelle la plus éloigné du joueur # Mais seulement si la balle vas vers la droite car sinon elle touchera le mur @@ -550,7 +558,10 @@ def _update_bot(world: World): bot_base_y = bot[Position].y target: float = right_touch_height better_distance = None - for offset in [-100, -50, 0, 50, 100]: + offsets = [-100, -50, 0, 50, 100] + if bot[Scale].y > 250: + offsets = [-200, -100, -50, 0, 50, 100, 200] + for offset in offsets: bot[Position].y = right_touch_height + offset __restrict_to_scene(world) player.remove(Solid) -- 2.43.4 From ee0fe070f8b5e873974268da6add7663a2827ac7 Mon Sep 17 00:00:00 2001 From: Tipragot Date: Sun, 7 Jan 2024 11:29:48 +0100 Subject: [PATCH 2/3] Save unfinished work --- src/plugins/physics.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/plugins/physics.py b/src/plugins/physics.py index 52ef0e2..038149c 100644 --- a/src/plugins/physics.py +++ b/src/plugins/physics.py @@ -173,7 +173,6 @@ def move_entity(entity: Entity, movement: Vec2, disable_callback: bool = False): if normal.y != 0: movement.y *= -1 entity[Velocity].y *= -1 - # movement /= entity.get(Velocity, Vec2(1)) if obstacle is not None and not disable_callback: if not entity.get( CollisionHandler, CollisionHandler(lambda e, o: True) @@ -183,7 +182,6 @@ def move_entity(entity: Entity, movement: Vec2, disable_callback: bool = False): CollisionHandler, CollisionHandler(lambda e, o: True) ).callback(obstacle, entity): break - # movement *= entity[Velocity] counter += 1 -- 2.43.4 From b55e7d7ec8d2c350f5114021c0a6d153ae3a3855 Mon Sep 17 00:00:00 2001 From: Tipragot Date: Sun, 7 Jan 2024 11:36:46 +0100 Subject: [PATCH 3/3] Save unfinished work --- src/plugins/physics.py | 10 ++++++++++ src/scenes/game.py | 16 ++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/plugins/physics.py b/src/plugins/physics.py index 038149c..15c3fb3 100644 --- a/src/plugins/physics.py +++ b/src/plugins/physics.py @@ -173,6 +173,11 @@ def move_entity(entity: Entity, movement: Vec2, disable_callback: bool = False): if normal.y != 0: movement.y *= -1 entity[Velocity].y *= -1 + if entity[Velocity].x == 0: + entity[Velocity].x = 0.01 + if entity[Velocity].y == 0: + entity[Velocity].y = 0.01 + movement /= entity[Velocity] if obstacle is not None and not disable_callback: if not entity.get( CollisionHandler, CollisionHandler(lambda e, o: True) @@ -182,6 +187,11 @@ def move_entity(entity: Entity, movement: Vec2, disable_callback: bool = False): CollisionHandler, CollisionHandler(lambda e, o: True) ).callback(obstacle, entity): break + if entity[Velocity].x == 0: + entity[Velocity].x = 0.01 + if entity[Velocity].y == 0: + entity[Velocity].y = 0.01 + movement *= entity[Velocity] counter += 1 diff --git a/src/scenes/game.py b/src/scenes/game.py index eb13b6c..bddaab7 100644 --- a/src/scenes/game.py +++ b/src/scenes/game.py @@ -263,9 +263,9 @@ def __spawn_ellements(world: World): SpriteBundle( "player_1.png", 0, - Vec2(100, render.HEIGHT / 2), + Vec2(125, render.HEIGHT / 2), Vec2(44, 250), - Vec2(0.5), + Vec2(1, 0.5), ), Solid(), Player1(), @@ -281,9 +281,9 @@ def __spawn_ellements(world: World): SpriteBundle( "player_2.png", 0, - Vec2(render.WIDTH - 100, render.HEIGHT / 2), + Vec2(render.WIDTH - 125, render.HEIGHT / 2), Vec2(44, 250), - Vec2(0.5), + Vec2(0, 0.5), ), Solid(), Player2(), @@ -538,18 +538,18 @@ def _update_bot(world: World): # On trouve l'endroit ou la balle va arriver sur le mur de droite for entity in world.query(RightWall): - entity[Position].x -= 122 + entity[Position].x -= 125 for entity in world.query(LeftWall): - entity[Position].x += 122 + entity[Position].x += 125 bot.remove(Solid) right_wall_ball = __simulate_wall_position(ball, RightWall) right_touch_height = right_wall_ball[Position].y right_wall_ball.destroy() bot.set(Solid()) for entity in world.query(RightWall): - entity[Position].x += 122 + entity[Position].x += 125 for entity in world.query(LeftWall): - entity[Position].x -= 122 + entity[Position].x -= 125 # On teste différentes possitions pour voir laquelle la plus éloigné du joueur # Mais seulement si la balle vas vers la droite car sinon elle touchera le mur -- 2.43.4