1
votes

First off, I am not after any instructions on logic for collision detection; I get it.

What I am trying to work out is the least complicated way to do this with Pygame using Sprites & Rects. I want to be able to check collisions for the Player against ground, walls & slopes. In theory it is quite straight forward, but I'm having difficulty because it seems like you cannot do this with one Rect.

One Rect is simple enough to get you collisions in the X plane against walls. The same Rect could be used also be used in the Y plane against solids, but not with slopes - since with the collision routines in Pygame it checks the whole Rect (or mask), rather than perhaps just the bottom middle of the Rect. It seems in addition you need to have a number of "sprites" to check collisions with, that are 1x1 pixel in various places around the Player.

What's the easiest way to do this, without having a bunch of 3, 4, or more separate "collision pixels" to check against slopes?

Geoff

2

2 Answers

1
votes

It sound to me like you want pixel perfect collision detection. Here you can find a premade function that seems to me to be what you want/need.

0
votes

You could use pygame.mask, which provides pixel perfect collision detection in C:

http://www.pygame.org/docs/ref/mask.html