Jumping Vs. Gravity
- by PhaDaPhunk
Hi i'm working on my first XNA 2D game and I have a little problem.
If I jump, my sprite jumps but does not fall down.
And I also have another problem, the user can hold spacebar to jump as high as he wants and I don't know how to keep him from doing that. Here's my code:
The Jump :
if (FaKeyboard.IsKeyDown(Keys.Space))
{
Jumping = true;
xPosition -= new Vector2(0, 5);
}
if (xPosition.Y >= 10)
{
Jumping = false;
Grounded = false;
}
The really simple basic Gravity:
if (!Grounded && !Jumping)
{
xPosition += new Vector2(1, 3) * speed;
}
Here's where's the grounded is set to True or False with a Collision
Rectangle MegamanRectangle = new Rectangle((int)xPosition.X, (int)xPosition.Y, FrameSizeDraw.X, FrameSizeDraw.Y);
Rectangle Block1Rectangle = new Rectangle((int)0, (int)73, Block1.Width, Block1.Height);
Rectangle Block2Rectangle = new Rectangle((int)500, (int)73, Block2.Width, Block2.Height);
if ((MegamanRectangle.Intersects(Block1Rectangle) || (MegamanRectangle.Intersects(Block2Rectangle))))
{
Grounded = true;
}
else
{
Grounded = false;
}
The grounded bool and The gravity have been tested and are working.
Any ideas why?
Thanks in advance and don't hesitate to ask if you need another Part of the Code.