diff --git a/arcade/hitbox/base.py b/arcade/hitbox/base.py index 43a49883b..c0543aba6 100644 --- a/arcade/hitbox/base.py +++ b/arcade/hitbox/base.py @@ -257,7 +257,7 @@ def get_adjusted_points(self) -> PointList: if not self._adjusted_cache_dirty: return self._adjusted_points - rad = radians(self._angle) + rad = radians(-self._angle) rad_cos = cos(rad) rad_sin = sin(rad) diff --git a/tests/unit/htibox/test_calculate_points.py b/tests/unit/htibox/test_calculate_points.py deleted file mode 100644 index 69e1d9c6a..000000000 --- a/tests/unit/htibox/test_calculate_points.py +++ /dev/null @@ -1,29 +0,0 @@ -# from uuid import uuid4 -# from PIL import Image -# import arcade - - -# def test_calculate_points(): -# texture = arcade.load_texture(":resources:images/items/coinGold.png") -# result = arcade.calculate_hit_box_points_detailed(texture.image) -# print(result) -# assert result == ((-32, 7), (-17, 28), (7, 32), (29, 15), (32, -7), (17, -28), (-8, -32), (-28, -17)) - -# texture = arcade.load_texture(":resources:images/animated_characters/female_person/femalePerson_idle.png") -# result = arcade.calculate_hit_box_points_detailed(texture.image) -# print(result) -# assert result == ((-32, -31), (-22, -18), (-27, -14), (-21, 21), (-8, 31), (10, 31), (25, 17), (29, -16), (22, -18), -# (32, -31), (32, -52), (29, -59), (17, -57), (22, -39), (15, -28), (19, -63), (4, -64), (-2, -46), -# (-3, -63), (-18, -64), (-15, -30), (-22, -39), (-16, -47), (-18, -59), (-31, -56)) - - -# def test_empty_image(): -# texture = arcade.Texture(name=str(uuid4()), image=Image.new("RGBA", (50, 50))) - -# result = arcade.calculate_hit_box_points_simple(texture.image) -# print(result) -# assert result == () - -# result = arcade.calculate_hit_box_points_detailed(texture.image) -# print(result) -# assert result == () diff --git a/tests/unit/htibox/test_hibox.py b/tests/unit/htibox/test_hibox.py new file mode 100644 index 000000000..7c6e1c3c8 --- /dev/null +++ b/tests/unit/htibox/test_hibox.py @@ -0,0 +1,52 @@ +import pytest +from arcade import hitbox + +points = [(0.0, 0.0), (0.0, 10.0), (10.0, 10.0), (10.0, 0.0)] +rot_90 = [(0.0, 0.0), (10.0, 0), (10.0, -10.0), (0.0, -10.0)] + + +def test_module(): + # Make sure the module is loaded + assert hitbox.algo_default + assert hitbox.algo_detailed + assert hitbox.algo_simple + assert hitbox.algo_bounding_box + + +def test_create(): + hb = hitbox.HitBox(points) + assert hb.points == points + assert hb.get_adjusted_points() == points + assert hb.position == (0.0, 0.0) + assert hb.scale == (1.0, 1.0) + assert hb.bottom == 0.0 + assert hb.top == 10.0 + assert hb.left == 0.0 + assert hb.right == 10.0 + + +def test_scale(): + hb = hitbox.HitBox(points) + hb.scale = (2.0, 2.0) + assert hb.scale == (2.0, 2.0) + assert hb.get_adjusted_points() == [(0.0, 0.0), (0.0, 20.0), (20.0, 20.0), (20.0, 0.0)] + + +def test_position(): + hb = hitbox.HitBox(points) + hb.position = (10.0, 10.0) + assert hb.position == (10.0, 10.0) + assert hb.get_adjusted_points() == [(10.0, 10.0), (10.0, 20.0), (20.0, 20.0), (20.0, 10.0)] + + +def test_create_rotatable(): + hb = hitbox.HitBox(points) + rot = hb.create_rotatable() + assert rot.angle == 0.0 + assert rot.position == (0.0, 0.0) + rot.angle = 90.0 + assert rot.angle == 90.0 + + rot_p = rot.get_adjusted_points() + for i, (a, b) in enumerate(zip(rot_90, rot_p)): + assert a == pytest.approx(b), f"[{i}] {a} != {b}" diff --git a/tests/unit/htibox/test_hitbox.py b/tests/unit/htibox/test_hitbox_algo_legacy.py similarity index 89% rename from tests/unit/htibox/test_hitbox.py rename to tests/unit/htibox/test_hitbox_algo_legacy.py index fe3fc5490..7b4ed49de 100644 --- a/tests/unit/htibox/test_hitbox.py +++ b/tests/unit/htibox/test_hitbox_algo_legacy.py @@ -3,14 +3,6 @@ from PIL import Image -def test_module(): - # Make sure the module is loaded - assert hitbox.algo_default - assert hitbox.algo_detailed - assert hitbox.algo_simple - assert hitbox.algo_bounding_box - - def test_calculate_hit_box_points_simple(): # Completely filled RGBA image image = Image.new("RGBA", (100, 100), (255, 255, 255, 255))