示例#1
0
        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;
        }
示例#2
0
 public void Load(ContentManager Content)
 {
     Camera = new Camera();
     eele.CarObject.Load(Content);
     map = Content.Load<Texture2D>("map");
     mapRectangle = new Rectangle(0, 0, map.Width, map.Height);
 }
示例#3
0
        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));
        }