-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathEntityCollider.py
29 lines (25 loc) · 1 KB
/
EntityCollider.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
class EntityCollider:
def __init__(self, entity):
self.entity = entity
def check(self, target):
if self.entity.rect.colliderect(target.rect):
return self.determineSide(target.rect, self.entity.rect)
return CollisionState(False, False)
def determineSide(self, rect1, rect2):
if (
rect1.collidepoint(rect2.bottomleft)
or rect1.collidepoint(rect2.bottomright)
or rect1.collidepoint(rect2.midbottom)
):
if rect2.collidepoint(
(rect1.midleft[0] / 2, rect1.midleft[1] / 2)
) or rect2.collidepoint((rect1.midright[0] / 2, rect1.midright[1] / 2)):
return CollisionState(True, False)
else:
if self.entity.vel.y > 0:
return CollisionState(True, True)
return CollisionState(True, False)
class CollisionState:
def __init__(self, _isColliding, _isTop):
self.isColliding = _isColliding
self.isTop = _isTop