0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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\$
    – Vaillancourt
    Apr 13, 2021 at 20:23
  • 1
    \$\begingroup\$ you didn't show code so we can't say if you coded it correctly. This problem is broad and without code it is useless. You should check pygame documentation. pygame.Rect() has functions like one_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\$
    – furas
    Apr 22, 2021 at 5:03

1 Answer 1

0
\$\begingroup\$

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))
\$\endgroup\$
1
  • 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .