MCPcopy
hub / github.com/yenchenlin/DeepLearningFlappyBird / pixelCollision

Function pixelCollision

game/wrapped_flappy_bird.py:211–225  ·  view source on GitHub ↗

Checks if two objects collide and not just their rects

(rect1, rect2, hitmask1, hitmask2)

Source from the content-addressed store, hash-verified

209 return False
210
211def 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

Callers 1

checkCrashFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected