I'm currently working on a game on Pygame, Python 3 and one of the essential parts of the game is the collision of Rects in a bullet-target situation.
This is fairly easy to achieve using the colliderect
function but it is necessary for the pixels that are the same color as the colorkey to not be counted.
For example, if one of the sprites (the character) is in the form of a large equilateral triangle with its base being horizontal and a bullet is coming from the top-left, colliderect
would detect the collision right away even though the pixels in the top-left are of the player's sprite are transparent.
I need to make a function that will detect to collision only when the bullet has reached pixels that are of a different color than the colorkey. This is easy enough if the bullet is only one pixel:
if player.get_at((bullet[0] - player.left, bullet[1] - player.top)) != player.get_colorkey():
I tried iterating the above statement for every pixel in the bullet, but, of course, that caused extensive lag. Is there a different, more efficient, way?
Thanks in advance!!