Game Development Reference
In-Depth Information
public void Update(double elapsedTime)
{
if (_input.Keyboard.IsKeyHeld(Keys.Left))
{
_velocity.X -= _speed;
}
else if (_input.Keyboard.IsKeyHeld(Keys.Right))
{
_velocity.X += _speed;
}
if (_input.Keyboard.IsKeyPressed(Keys.Up) && !_jumping)
{
_velocity.Y += 500;
_jumping = true;
}
_velocity.Y -= _gravity;
_velocity.X = _velocity.X * _friction;
Vector newPosition = _pc.GetPosition();
newPosition += _velocity * elapsedTime;
if (newPosition.Y < 0)
{
newPosition.Y = 0;
_velocity.Y = 0;
_jumping = false;
}
_pc.SetPosition(newPosition);
}
public void Render()
{
Gl.glDisable(Gl.GL_TEXTURE_2D);
Gl.glClearColor(1, 1, 1, 0);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
Gl.glEnable(Gl.GL_LINE_SMOOTH);
Gl.glLineWidth(2.0f);
Search WWH ::




Custom Search