Skip to content

Hitbox rotate fix #1819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arcade/hitbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 0 additions & 29 deletions tests/unit/htibox/test_calculate_points.py

This file was deleted.

52 changes: 52 additions & 0 deletions tests/unit/htibox/test_hibox.py
Original file line number Diff line number Diff line change
@@ -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}"
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down