Collision Detection (Ground & Slopes) in 2D Platform Game using Pygame Rects

Posted by RedCap on Stack Overflow See other posts from Stack Overflow or by RedCap
Published on 2010-11-05T01:03:01Z Indexed on 2010/12/25 11:54 UTC
Read the original article Hit count: 162

Filed under:
|
|

Hi,

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

© Stack Overflow or respective owner

Related posts about 2d

Related posts about collision-detection