Wednesday, October 22, 2008

Second Chance Banks In Belleville Il

Dev - The platforms

is one of the first additions I made (after the parts, enemies and a wrench). Unfortunately, I have not thought about working on graphics, so I made a big red square, and I'm happy for the moment.
I decided to manage the platform as collisions with the ground: to detect if the hero touche la plateforme, et si elle se trouve sous ses "pieds". Cette méthode a été reprise du
wiki de la PAlib
:





if (héros après le côté gauche) && (héros avant le côté droit){
héros.y-=1

Ensuite on recherche une plateforme en dessous :
<<8;}
if (héros après le côté gauche) &amp;&amp; (Hero before the right side) {
if (point at the bottom of a hero
) & & (speed> = 0) {
vertical speed of the hero = 0;}

With that, the hero can walk on the platform
stopped
. Because if you put the platform in motion, he just dropped once he is in a vacuum.
platforms all have a variable that defines the direction in which they move (-1 for left, 1 right), and their horizontal speed is 2 pixels / frame.

So when the platform is on the hero, is added to the position of the hero of the platform speed, multiplied by the variable that contains the direction. And we get it this:

if (hero after the left side) & & (heroes before the right side) {
if (point at the bottom of a hero
) & , & (speed> = 0) {
vertical speed of the hero = 0;

héros.x + = (* variable speed horizontal direction of movement)
}
We come to the last important point for the platforms, the change of direction. Indeed, if a platform keeps moving and never stop, it will not help much (except for a level with a horizontal scorlling forced).
<<8;
If like me you use a map of collision, the rest is very simple: detect the collision of a tile platform with specific, dedicated solely to that. Then, simply multiply the variable direction by -1, which has the effect of changing the direction of the platform.
And voila, my first REAL article on development. I'm not particularly good at explaining my theory of operation, but I have not seen a tutorial dedicated to creating a platform, so I tried to explain as best I could how I am taken, hoping that I can help someone.

Note:

-
As explained on the wiki PAlib
, I use the fixed points for my variables. That's where come the
-I noticed that the hero was moving systematically (* Variable speed horizontal direction of travel)
pixels when the platform comes into collision with the tile that allows it to change direction (and it's over, of course). So I fiddled a bit by adding the inverse of this value when the hero is on the platform and that it bumps against one of the famous tiles. It worked, so I stopped there. If someone finds another solution, he makes me share in the comments.

-No image for this tutorial: a static image is useless, and make a GIF I am not gone through his mind (it does, but no).

No such either, but you'll have if I release the source code one day of WTN.
<<8".

0 comments:

Post a Comment