[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Some Platforms



Manuel wrote:
Hello Matt

Of course, ANY help is welcome, i've recently changed my code from:
	sprite always asking; I'm on the platform??
for:
	platfom sayig, you are not on me, so start falling

This adds more complexity, but could be used for some games.
For example, if you want a sprite to always be on the platform, the simpler version is well, but what happens if a platform just disappear or rapidly change it's position?? the sprites on it have to start falling.
Of course this is ugly for elevators, like in Abuse, when it does not matter how the elevator falls, the player should always be on it.

I haven't played enough with collisions in Pygame to give advice on what commands to use, but this is the method I think I used elsewhere, once:


Give each object an X speed and a Y speed.
Every so often, have the world run this code:
--For each object in the world:
----object.Y_speed -= GRAVITY
----If object.Y_Speed > MAX_FALLING_SPEED: set it to MAX_FALLING_SPEED.
----Change object's X and Y position by [speed] units.
----If object's new position is inside another object: Move it back. (Really you'd want to only move it back until it's no longer overlapping. You could even send the object a message that's it's hit something, so it can take damage or play a sound.)


This is a simple but fairly realistic simulation of real physics. All objects' vertical speed in reality is constantly getting tugged downward. If you simulate motion this way, you get some cool effects "for free." For instance, if you create a ball with a certain X and Y speed, it will automatically move in an arc just like a real one. If you can make an elevator fall so fast the hero gets slammed against the ceiling, players will think that's cool!

With your "moment of science,"
Kris