Tuesday, May 11, 2010

Jump Code

// Up top

bool jump = false;
bool falling = false;
bool ready = true;

// In Update

if (keystate.IsKeyDown(Keys.Space) && oldKeyState.IsKeyUp(Keys.Space) && !jump && ready)
{
jump = true;
ready = false;
velocity = new Vector2(0f, -5f);
playerPos.Y--;
}

if (jump)
{
playerPos += velocity;
if (playerPos.Y <= 440)
falling = true;
}

if (playerPos.Y <>
{
jump = false;
velocity += new Vector2(0f, (float)(13.8 * gameTime.ElapsedGameTime.TotalSeconds));
playerPos += velocity;
if (playerPos.Y > 450)
{
jump = false;
falling = false;
ready = true;
playerPos.Y = 450;
}
}

No comments: