Checks if two objects collide and not just their rects
(rect1, rect2, hitmask1, hitmask2)
| 209 | return False |
| 210 | |
| 211 | def pixelCollision(rect1, rect2, hitmask1, hitmask2): |
| 212 | """Checks if two objects collide and not just their rects""" |
| 213 | rect = rect1.clip(rect2) |
| 214 | |
| 215 | if rect.width == 0 or rect.height == 0: |
| 216 | return False |
| 217 | |
| 218 | x1, y1 = rect.x - rect1.x, rect.y - rect1.y |
| 219 | x2, y2 = rect.x - rect2.x, rect.y - rect2.y |
| 220 | |
| 221 | for x in range(rect.width): |
| 222 | for y in range(rect.height): |
| 223 | if hitmask1[x1+x][y1+y] and hitmask2[x2+x][y2+y]: |
| 224 | return True |
| 225 | return False |