Alright, I'm learning C# and am trying to get the basics down by making a simple 2D game similar to mario. I got the moving don, and am currently trying to get it to jump smoothly, so I came up with the following code- But when I press the jump button, the sprite just moves up, and keeps moving up, and I cant figure out why 
Rich (BB code):
namespace mario_clone
{ public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
KeyboardState oldState;
SpriteBatch spriteBatch;
Boolean jumping;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
graphics.IsFullScreen = true;
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
oldState = Keyboard.GetState();
jumping = false;
// TODO: Add your initialization logic here
base.Initialize();
}
Texture2D myTexture;
Vector2 spritePosition = new Vector2(1.0f, 1.0f);
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
myTexture = Content.Load<Texture2D>("mario sprite");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
int MaxX =
graphics.GraphicsDevice.Viewport.Width - myTexture.Width;
int MinX = 0;
int MaxY =
graphics.GraphicsDevice.Viewport.Height - myTexture.Height;
int MinY = 0;
int gravity = 5;
var velocity = 15;
// keyboard logic
KeyboardState newState = Keyboard.GetState();
if (newState.IsKeyDown(Keys.Escape))
{
if (!oldState.IsKeyDown(Keys.Escape))
{
this.Exit();
}
}
if (newState.IsKeyDown(Keys.Left))
{
if (spritePosition.X > MinX)
{
spritePosition.X = spritePosition.X - 2.0f;
}
}
if (newState.IsKeyDown(Keys.Right))
{
if (spritePosition.X < MaxX)
{
spritePosition.X = spritePosition.X + 2.0f;
}
}
if (newState.IsKeyDown(Keys.Up) && spritePosition.Y >= MaxY && jumping == false)
{
jumping = true;
velocity = 15;
}
if (jumping == true)
{
spritePosition.Y = spritePosition.Y - velocity;
velocity = velocity - gravity;
}
if (spritePosition.Y == MaxY && jumping == true)
{
jumping = false;
velocity = 0;
}
if (spritePosition.Y < MaxY && jumping == false)
{
spritePosition.Y = spritePosition.Y + gravity;
}
if (spritePosition.Y >= MaxY)
{
spritePosition.Y = MaxY;
}
base.Update(gameTime);
oldState = newState;
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
spriteBatch.Draw(myTexture, spritePosition, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}