Domanda

I'm making a simple game, something like mario, with a character fixed in one position, and the ground moving left, giving the illusion of character movement. The ground is made of rectangular blocks defined by top-left and bottom-right coordinates:

private int surfaceMatrix[][] = {
   {0, 100, 300, 0} // block having 100 height and 300 width
};

Jumping is just changing character's y coordinate while moving the surface left, so the jump looks like reversed V letter.

The rest of the code - animation, moving sprites - is very similar to http://zetcode.com/tutorials/javagamestutorial/movingsprites/


I want jumping to be more real, so my question is - how can I implement gravity here? I'd have to use dx of the ground, and dy of the character to do it, is that ok?

What would be the velocity here? Pixels per second...?

How to do that?

È stato utile?

Soluzione

Let's see:

g = 9.8 meters/second

Take height of your character in pixels and match it to an average man height, say 1.7 meters tall.

Then use gravitation formula:

y = y0 - g * t^2 / 2

where g is in pixels/second.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top