public static void CameraControlls(Camera Camera) { KeyboardState keyState = Keyboard.GetState(); //Camera movement if (keyState.IsKeyDown(Keys.D)) Camera.Move(new Vector2(-1, 0)); if (keyState.IsKeyDown(Keys.A)) Camera.Move(new Vector2(1, 0)); if (keyState.IsKeyDown(Keys.W)) Camera.Move(new Vector2(0, 1)); if (keyState.IsKeyDown(Keys.S)) Camera.Move(new Vector2(0, -1)); //Camera zoom if (keyState.IsKeyDown(Keys.Z)) Camera.Zoom += 0.1f; if (keyState.IsKeyDown(Keys.X)) Camera.Zoom -= 0.1f; //Camera rotation if (keyState.IsKeyDown(Keys.C)) Camera.Rotation += 0.1f; if (keyState.IsKeyDown(Keys.V)) Camera.Rotation -= 0.1f; }
public void Update(Camera cCamera) { rectangle = new Rectangle((int)position.X, (int)position.Y, texture[0].Width, texture[0].Height); origin = new Vector2(rectangle.Width / 2, rectangle.Height / 2); cCamera.Position = position; KeyboardState keyState = Keyboard.GetState(); // When pressing Up (gas) if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up)) { if (snelheid < maxSpeed) { snelheid = snelheid + versnelling; } else { snelheid = maxSpeed; } } else if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down)) { if (snelheid > 0) { snelheid = snelheid - versnelling; } else { snelheid = 0; } } // When pressing Down (Backwards) if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down)) { if (snelheid > minSpeed) { snelheid = snelheid - versnelling; } else { snelheid = minSpeed; } } else if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up)) { if (snelheid < 0) { snelheid = snelheid + versnelling; } else { snelheid = 0; } } // je kan niet sturen bij een speed van 0 if (snelheid != 0) { if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right)) { rotation += handling; cCamera.Rotation -= handling; } if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left)) { rotation -= handling; cCamera.Rotation += handling; } } posx = (float)Math.Cos(rotation + 1.5 * Math.PI) * 5 * snelheid; posy = (float)Math.Sin(rotation + 1.5 * Math.PI) * 5 * snelheid; // Update position of car and Camera position = new Vector2(position.X + posx, position.Y + posy); cCamera.Move(new Vector2(posx, posy)); }