-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_collide.py
55 lines (40 loc) · 1.33 KB
/
test_collide.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import pygame
from sappho import animate
from sappho import collide
# this sprite is 10x10
testpath = os.path.realpath(__file__)
path = os.path.abspath(os.path.join(testpath,
"..",
"resources",
"animatedsprite.gif"))
animsprite_mask_20_20 = animate.AnimatedSprite.from_gif(
path,
mask_threshold=254
)
animsprite_mask_20_20.rect.topleft = (20, 20)
animsprite_mask_40_40 = animate.AnimatedSprite.from_gif(
path,
mask_threshold=254
)
animsprite_mask_40_40.rect.topleft = (40, 40)
animsprite_group_sans_one = pygame.sprite.Group(animsprite_mask_40_40)
def test_move_close_as_possible():
"""
Move `animsprite_mask_20_20` to (60, 60), which should collide
with both `animsprite_mask_40_40` and `animsprite_35_40`.
"""
closest_to_goal, collided_with = collide.move_as_close_as_possible(
animsprite_mask_20_20,
(60, 60),
animsprite_group_sans_one
)
assert closest_to_goal == (30, 30)
assert collided_with is animsprite_mask_40_40
closest_to_goal, collided_with = collide.move_as_close_as_possible(
animsprite_mask_20_20,
(10, 10),
animsprite_group_sans_one
)
assert closest_to_goal == (10, 10)
assert collided_with is None