Skip to content

Commit

Permalink
Use list for get_adjusted_points instead of tuple (#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cleptomania committed Mar 18, 2023
1 parent 26ecde0 commit 5c1ddbf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions arcade/hitbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _adjust_point(point) -> Point:

return (x + self.position[0], y + self.position[1])

self._adjusted_points = tuple([_adjust_point(point) for point in self.points])
self._adjusted_points = [_adjust_point(point) for point in self.points]
self._adjusted_cache_dirty = False
return self._adjusted_points

Expand Down Expand Up @@ -171,6 +171,6 @@ def _adjust_point(point) -> Point:
y + self.position[1],
)

self._adjusted_points = tuple([_adjust_point(point) for point in self.points])
self._adjusted_points = [_adjust_point(point) for point in self.points]
self._adjusted_cache_dirty = False
return self._adjusted_points
34 changes: 17 additions & 17 deletions tests/unit/sprite/test_sprite_hitbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_1():
my_sprite = arcade.Sprite(
arcade.make_soft_square_texture(20, arcade.color.RED, 0, 255)
)
hit_box = arcade.hitbox.HitBox(([-10, -10], [-10, 10], [10, 10], [10, -10]))
hit_box = arcade.hitbox.HitBox(((-10, -10), (-10, 10), (10, 10), (10, -10)))
my_sprite.hit_box = hit_box
my_sprite.scale = 1.0
my_sprite.angle = 0
Expand All @@ -17,27 +17,27 @@ def test_1():
print()
hitbox = my_sprite.hit_box.get_adjusted_points()
print(f"Hitbox: {my_sprite.scale} -> {my_sprite.hit_box.points} -> {hitbox}")
assert hitbox == ((90.0, 90.0), (90.0, 110.0), (110.0, 110.0), (110.0, 90.0))
assert hitbox == [(90.0, 90.0), (90.0, 110.0), (110.0, 110.0), (110.0, 90.0)]

my_sprite.scale = 0.5
hitbox = my_sprite.hit_box.get_adjusted_points()
print(f"Hitbox: {my_sprite.scale} -> {my_sprite.hit_box.points} -> {hitbox}")
assert hitbox == ((95.0, 95.0), (95.0, 105.0), (105.0, 105.0), (105.0, 95.0))
assert hitbox == [(95.0, 95.0), (95.0, 105.0), (105.0, 105.0), (105.0, 95.0)]

my_sprite.scale = 1
hitbox = my_sprite.hit_box.get_adjusted_points()
print(f"Hitbox: {my_sprite.scale} -> {my_sprite.hit_box.points} -> {hitbox}")
assert hitbox == ((90.0, 90.0), (90.0, 110.0), (110.0, 110.0), (110.0, 90.0))
assert hitbox == [(90.0, 90.0), (90.0, 110.0), (110.0, 110.0), (110.0, 90.0)]

my_sprite.scale = 2.0
hitbox = my_sprite.hit_box.get_adjusted_points()
print(f"Hitbox: {my_sprite.scale} -> {my_sprite.hit_box.points} -> {hitbox}")
assert hitbox == ((80.0, 80.0), (80.0, 120.0), (120.0, 120.0), (120.0, 80.0))
assert hitbox == [(80.0, 80.0), (80.0, 120.0), (120.0, 120.0), (120.0, 80.0)]

my_sprite.scale = 2.0
hitbox = my_sprite.hit_box.get_adjusted_points()
print(f"Hitbox: {my_sprite.scale} -> {my_sprite.hit_box.points} -> {hitbox}")
assert hitbox == ((80.0, 80.0), (80.0, 120.0), (120.0, 120.0), (120.0, 80.0))
assert hitbox == [(80.0, 80.0), (80.0, 120.0), (120.0, 120.0), (120.0, 80.0)]


def test_2():
Expand Down Expand Up @@ -98,14 +98,14 @@ def test_2():
wall = arcade.Sprite(texture)
wall.position = 0, 0

hit_box = wall.hit_box.points
assert hit_box == (
(-32, 7),
(-17, 28),
(7, 32),
(29, 15),
(32, -7),
(17, -28),
(-8, -32),
(-28, -17),
)
hit_box = list(wall.hit_box.points)
assert hit_box == [
(-32.0, 7.0),
(-17.0, 28.0),
(7.0, 32.0),
(29.0, 15.0),
(32.0, -7.0),
(17.0, -28.0),
(-8.0, -32.0),
(-28.0, -17.0),
]

0 comments on commit 5c1ddbf

Please sign in to comment.