/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (outcome == -1) { lander.Update(gameTime); outcome = LandCheck(); rotationUI.Text = lander.Rotation.ToString(); vxUI.Text = lander.Vx.ToString(); vyUI.Text = lander.Vy.ToString(); } else if (outcome == 0) { resultUI.Text = "Success"; } else if (outcome == 1) { resultUI.Text = "Failure"; } base.Update(gameTime); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.Left)) { lander.angle -= 2; } if (Keyboard.GetState().IsKeyDown(Keys.Right)) { lander.angle += 2; } if (Keyboard.GetState().IsKeyDown(Keys.Up)) { lander.engineOn = true; float angle_radian = MathHelper.ToRadians(lander.angle); float angle_x = (float)Math.Cos(angle_radian) * lander.speed; float angle_y = (float)Math.Sin(angle_radian) * lander.speed; lander.velocity += new Vector2(angle_x, angle_y); } else { lander.engineOn = false; } if (lander.position.X < 0) { lander.position = new Vector2(0, lander.position.Y); lander.velocity = new Vector2(0 - lander.velocity.X, lander.velocity.Y); } if (lander.position.X > GraphicsDevice.Viewport.Width) { lander.position = new Vector2(GraphicsDevice.Viewport.Width, lander.position.Y); lander.velocity = new Vector2(0 - lander.velocity.X, lander.velocity.Y); } if (lander.position.Y > GraphicsDevice.Viewport.Height) { lander.position = new Vector2(lander.position.X, GraphicsDevice.Viewport.Height); lander.velocity = new Vector2(lander.velocity.X, 0 - lander.velocity.Y); } lander.Update(); base.Update(gameTime); }