Skip to content

Commit 83f94ed

Browse files
authored
Fix #2658: Use is not None for boundary_left and boundary_right. (#2659)
Like was already done for `boundary_top` and `boundary_bottom`.
1 parent 069861b commit 83f94ed

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

arcade/physics_engines.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -792,12 +792,18 @@ def update(self) -> list[BasicSprite]:
792792
for platform in platform_list:
793793
if platform.change_x != 0 or platform.change_y != 0:
794794
# Check x boundaries and move the platform in x direction
795-
if platform.boundary_left and platform.left <= platform.boundary_left:
795+
if (
796+
platform.boundary_left is not None
797+
and platform.left <= platform.boundary_left
798+
):
796799
platform.left = platform.boundary_left
797800
if platform.change_x < 0:
798801
platform.change_x *= -1
799802

800-
if platform.boundary_right and platform.right >= platform.boundary_right:
803+
if (
804+
platform.boundary_right is not None
805+
and platform.right >= platform.boundary_right
806+
):
801807
platform.right = platform.boundary_right
802808
if platform.change_x > 0:
803809
platform.change_x *= -1

tests/unit/physics_engine/test_physics_engine_platformer.py

+29-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,22 @@ def test_physics_engine(window):
2626
sprite.center_y = 32
2727
wall_list.append(sprite)
2828

29+
platform_list = arcade.SpriteList[arcade.Sprite]()
30+
platform = arcade.Sprite(
31+
":resources:images/tiles/boxCrate_double.png",
32+
scale=CHARACTER_SCALING,
33+
center_x=64,
34+
center_y=256,
35+
)
36+
platform.boundary_left = 0 # 0 in particular was problematic, see #2658
37+
platform.boundary_right = 128
38+
platform.change_x = 8
39+
platform_list.append(platform)
40+
2941
physics_engine = arcade.PhysicsEnginePlatformer(
3042
character_sprite,
31-
wall_list,
43+
walls=wall_list,
44+
platforms=platform_list,
3245
gravity_constant=GRAVITY,
3346
)
3447

@@ -48,10 +61,23 @@ def update(td):
4861
assert physics_engine.can_jump() is True
4962
character_sprite.change_y = 15
5063
physics_engine.increment_jump_counter()
51-
window.test()
64+
65+
window.test(frames=7)
66+
5267
assert physics_engine.can_jump() is True
68+
assert platform.center_x == 80 # it bounced against the boundary_right
69+
assert platform.change_x == -8
5370
character_sprite.change_y = 15
5471
physics_engine.increment_jump_counter()
55-
window.test()
72+
73+
window.test(frames=6)
74+
5675
assert physics_engine.can_jump() is False
76+
assert platform.center_x == 32 # right at the boundary
77+
assert platform.change_x == -8 # still going left
5778
physics_engine.disable_multi_jump()
79+
80+
window.test(frames=3)
81+
82+
assert platform.center_x == 32 + 24 # it bounced against the boundary_left
83+
assert platform.change_x == +8

0 commit comments

Comments
 (0)