PyGame: Jump-and-run Collision Response

anarchie
Unregistered
 
Post: #1
I am trying to implement a two dimensional sidescroller of the Megaman/Abuse genre. My platform is python with Pygame and OpenGL. I am not using fixed-size tiles for my terrain. My latest problem is resolving collisions between the player (or other non-volatile object) and any static or moving terrain. For now, the terrain is non-moving and both player and terrain are represented by rectangles.

I use the pygame method pygame.rect.collidelistall() to seek collisions between the player and terrain. Once a collision is found, I subtract the player's velocity from his location to find his position last frame, which should be non-colliding. Using an intimidating cascade of ifs, I at one point managed to properly move the player to the correct location along the terrain according to where he had previously been.

When I tried to add sloped or free-form terrain to the mix, I nearly had an aneurysm and ended up deleting all related code.

Does anyone have any experience with solving this sort of problem? I came across one solution (here, and slopes here) which involved scanning the terrain map for collisions only along the X axis first and adjusting for only those, then doing the same for Y axis collisions, however, the examples assumed fixed-size tiles. I'm sure my variable-size terrain shouldn't pose a problem, as long as I ensure a tile's size is at least as large as the player's maximum velocities, but having spent days pounding my head (and axe) against cecropia trees over this, I thought I'd ask for advice.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #2
I could give you a powerful(ly messy) circle to circle, circle to quad, quad to quad collision system Smile Don't if it would solve your problem of terrain, but you could easily build the terrain out of quads.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #3
It seems to me that bounding box collision response always gets messy because of the if's involved. If you want sloped surfaces and such, have you considered using BSP?

DevMaster Article

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #4
I'm not using the bounding box... I'm using bounding quads Wink subtle but importance difference.

such as the ability to have an arbitrary shaped quad
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #5
skyhawk Wrote:I'm not using the bounding box... I'm using bounding quads Wink subtle but importance difference.

such as the ability to have an arbitrary shaped quad

He's not though. A poly based approach can be a lot simpler because you don't base the collisions on special if cases as much. That's what my experience is anyway.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #6
I'm finishing such a game as we speak. ;-) The way I've done it is to create the environment completely from polylines. This works surprisingly well. Tell me if you want some source.
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #7
Fenris Wrote:The way I've done it is to create the environment completely from polylines. This works surprisingly well. Tell me if you want some source.
I'd certainly be interested in seeing your code! I want to improve the scenery collision detection in Yoink shortly, so I'm keen to look at as much relevant code as possible.

Skyhawk, I'd like to see your code too, if that's OK. Smile

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  pygame or lingo? hertzcastle 6 4,258 Mar 19, 2008 01:13 AM
Last Post: hertzcastle
  pygame framework foosh 0 2,271 Feb 29, 2008 02:09 AM
Last Post: foosh
  So... anyone doing any stuff in Python/Pygame...? Malarkey 12 6,441 Aug 23, 2007 12:09 PM
Last Post: Malarkey
  Animation help in pygame suplexx 3 3,665 Mar 13, 2007 01:51 PM
Last Post: suplexx
  Python and Pygame. bronxbomber92 10 4,731 Dec 31, 2006 11:00 AM
Last Post: bronxbomber92