def SATCollision(self,boundingbox): #generate an axis that is perpendicular to each edge of each object #since rectangles are used, 4 axis axes are needed and not 8 A_TR = self.Rect.topright #Top right corner A_TL = self.Rect.topleft #Top left corner A_BR = self.Rect.bottomright A_BL = self.Rect.bottomleft #not used in axis B_TL = boundingbox.Rect.topleft B_TR = boundingbox.Rect.topright B_BL = boundingbox.Rect.bottomleft B_BR = boundingbox.Rect.bottomright #not used in axis Axis1 = [ -(A_TR[1] - A_TL[1]), A_TR[0] - A_TL[0] ] Axis2 = [ -(A_TR[1] - A_BR[1]), A_TR[0] - A_BR[0] ] Axis3 = [ -(B_TL[1] - B_BL[1]), B_TL[0] - B_BL[0] ] Axis4 = [- (B_TL[1] - B_TR[1]), B_TL[0] - B_TR[0] ] axes = (Axis1, Axis2, Axis3, Axis4) for axis in axes: #get the min and max values, ignore # negatives and get their absolute value a_min = 0 a_max = 0 b_min = 0 b_max = 0 A_Projections = [ getProjection(A_TL, axis), getProjection(A_TR, axis), getProjection(A_BL, axis), getProjection(A_BR, axis), ] B_Projections = [ getProjection(B_TL, axis), getProjection(B_TR, axis), getProjection(B_BL, axis), getProjection(B_BR, axis), ] for i in xrange(4): for j in xrange(i+1,4): line = math.sqrt( (A_Projections[j][0] - A_Projections[i][0]) ** 2 + (A_Projections[j][1] - A_Projections[i][1]) **2) if line > a_max: a_max = line if line > a_max: a_max = line elif line < a_min: a_min = line for i in xrange(4): for j in xrange(i+1,4): line = math.sqrt((B_Projections[j][0] - B_Projections[i][0]) ** 2 + (B_Projections[j][1] - B_Projections[i][1]) **2) if line > b_max: b_max = line elif line < b_min: b_min = line # print B_Scalars if not ( b_min <= a_max and b_max >= a_min ): #no overlap so no collision return 0 Debugger.debugPrint('SAT Detected collided') return 1