Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from enum import Enum
- class SIDE(Enum):
- LEFT = 1
- TOP = 2
- RIGHT = 3
- BOT = 4
- class Collider:
- #Type = 0 Solid everypixel
- #Type = 1 Around
- def __init__(self, object_attached, size, type_c=1):
- self.size = size
- self.type_c = type_c
- self.object_attached = object_attached
- def iscollision(self, other, side=None):
- #1 left
- #2 top
- #3 right
- #4 bot
- if isinstance(other, Collider):
- loc_self = self.object_attached.location
- loc_other = other.object_attached.location
- if self.object_attached.distance(other.object_attached) > self.size[0] + self.size[1] and self.object_attached.distance(other.object_attached) > other.size[0] + other.size[1]:
- #print("time saved by collision")
- return None
- if side is None:
- #left
- if self.linecollide(loc_self[0], loc_other[0]+other.size[0], loc_self[1], self.size[1], loc_other[1], other.size[1]):
- return SIDE.LEFT.value
- #top
- if self.linecollide(loc_self[1], loc_other[1]+other.size[1], loc_self[0], self.size[0], loc_other[0], other.size[0]):
- return SIDE.TOP.value
- #right
- if self.linecollide(loc_other[0], loc_self[0]+self.size[0], loc_other[1], other.size[1], loc_self[1], self.size[1]):
- return SIDE.RIGHT.value
- #bot
- if self.linecollide(loc_other[1], loc_self[1]+self.size[1], loc_other[0], other.size[0], loc_self[0], self.size[0]):
- return SIDE.BOT.value
- elif side is SIDE.LEFT.value:
- if self.linecollide(loc_self[0], loc_other[0]+other.size[0], loc_self[1], self.size[1], loc_other[1], other.size[1]):
- return True
- return False
- elif side is SIDE.TOP.value:
- if self.linecollide(loc_self[1], loc_other[1]+other.size[1], loc_self[0], self.size[0], loc_other[0], other.size[0]):
- return True
- return False
- elif side is SIDE.RIGHT.value:
- if self.linecollide(loc_other[0], loc_self[0]+self.size[0], loc_other[1], other.size[1], loc_self[1], self.size[1]):
- return True
- return False
- elif side is SIDE.BOT.value:
- if self.linecollide(loc_other[1], loc_self[1]+self.size[1], loc_other[0], other.size[0], loc_self[0], self.size[0]):
- return True
- return False
- return None
- #add for more ez call
- def linecollide(self, value, valuevalue, mini, endi, minii, endii):
- for v2 in range(mini, mini+endi):
- for v2v2 in range(minii, minii+endii):
- if value == valuevalue and v2 == v2v2:
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement