I am trying to create a platform game where a player jumps between platforms horizontally (using a projectile curve). Currently, I have a class that blits platforms and a background, as well as the player. However, I cannot get it to detect when a platform and the player collide. I have used actual images and then done self.rect = self.image.get_rect() for both the platform and the character. My question is have I done something wrong with my theory or have I just not coded it correctly.
1 Answer
if the level is just an image then you should use masks mask tutorial
mask1 = pygame.mask.from_surface(surf1)
mask2 = pygame.mask.from_surface(surf2)
m = mask1.overlap(mask2,(level.x-player.x,level.y-player.y))
-
1\$\begingroup\$ Did you intend for the text "mask tutorial" to be a link to a tutorial about this topic? \$\endgroup\$– DMGregory ♦Apr 29, 2022 at 18:45
self.rect = self.image.get_rect()
I suppose this makes it so that you know where the player and the platform rectangles are. Did you actually used those rectangles to check if the player's rect's overlaps the paltforms? \$\endgroup\$pygame.Rect()
has functions likeone_rect.colliderect(other_rect)
to check collision between two rectangles. Maybe better see Program Arcade Games With Python And Pygame and platform examples especially platform_jumper.py \$\endgroup\$