anarchie
2004.07.08, 04:20 AM
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 (http://jnrdev.weed-crew.net/jnrdev1/), and slopes here (http://jnrdev.weed-crew.net/jnrdev2/)) 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.
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 (http://jnrdev.weed-crew.net/jnrdev1/), and slopes here (http://jnrdev.weed-crew.net/jnrdev2/)) 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.