def overlap(self, other): offset = sub_vector(other.pos, self.pos) overlap = sub_vector(other.pos, self.pos) rect1 = pygame.Rect((0,0), self.get_size()) rect2 = pygame.Rect(offset, other.get_size()) rect=rect1.clip(rect2) if rect.width==0 or rect.height==0: return False x1,y1,x2,y2 = rect.x-rect1.x,rect.y-rect1.y,rect.x-rect2.x,rect.y-rect2.y hm1 = self.data hm2 = other.data for x in xrange(rect.width): for y in xrange(rect.height): if hm1[x1+x][y1+y] and hm2[x2+x][y2+y]:return True else:continue return False
def overlap_area(self, other): offset = sub_vector(other.pos, self.pos) rect1 = pygame.Rect((0,0), self.get_size()) rect2 = pygame.Rect(offset, other.get_size()) rect=rect1.clip(rect2) if rect.width==0 or rect.height==0: return 0 x1,y1,x2,y2 = rect.x-rect1.x,rect.y-rect1.y,rect.x-rect2.x,rect.y-rect2.y hm1 = self.data hm2 = other.data num = 0 for x in xrange(rect.width): for y in xrange(rect.height): if hm1[x1+x][y1+y] and hm2[x2+x][y2+y]: num += 1 return num
def overlap(self, other): return Mask.overlap(self, other, sub_vector(other.pos, self.pos))