Surface locking allows you to directly access the pixel data of accelerated surfaces. It's not so much about improving performance. Rather, an accelerated surface already has performance improvements, but it comes with a trade off of requiring locking & unlocking if you're going to directly change its data.
All of the built in Pygame functions will ...
The simplest system I can think of consists in testing the position of the new enemy before your screen.blit(), like so:
def distance_square(a, b):
return (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - b.y)
self.x = random.randrange(2, 502, 20)
self.y = random.randrange(2, 502, 20)
Finally I solved the issue and it was related to wrong image positioning as @Tyyppi_77 has mentionned in the comments.
The blit method of pygame.Surface turns out to blit a surface in the topleft corner if coordinates are passed to the 2nd parameter.
However, if we pass a Rect object, we would be able to position the image as we want.
Here is what the ...
The documentation for blits says that the syntax is
blits(blit_sequence=(source, dest), ...), doreturn=1)
I am not sure if there is intentionally an opening parenthesis missing there, but it's easy to deduce that the required syntax is blits(sequenceOfPairsOfSurfaceDestination), meaning that your second attempt is close, but missing the outer sequence, as ...
The method that most games use is a variant on 1 where there are multiple instances which get recycled. How many you pool depends on your game.
This way the CPU performance doesn't vary as more bullets are spawned.
You can do this by adding a field in your bullet data that lets you test whether the bullet is active (like a time to live that become negative).
The way you create your "rectangle mask" seems appropriate and roughly in line with the question you've linked to on StackOverflow:
self.mask = pygame.mask.Mask((50, 50), True)
Now that this is out of the way, it seems that the mask.overlap method that you use expects a Mask, not a rectangle. Since you have defined that "rectangle mask" ...
Swap the order of the variable changes. Minus it first, then increase it to show how exactly much the player will lose.
Here's the fixed else-clause:
score = score - crapscore
crapscore = crapscore + 10
hit = False