コード例 #1
0
        private void HandleInput(GameTime dt)
        {
            if (KeyboardManager.IsKeyPressed(_toggleCamera))
            {
                ToggleCameraMode();
                UpdateDetails();
            }
            if (KeyboardManager.IsKeyPressed(_exit))
            {
                Environment.Exit(0);
            }
            if (KeyboardManager.IsKeyPressed(_generateMaze))
            {
                // clear old
                Remove(GetComponents <CollisionEngine>().First());
                Remove(GetComponents <ChunkManager>().First());

                var pl = GetComponents <Player>().First();
                GenerateMaze(pl);

                // player must be updated after the other components, therefore remove it and add it again
                Remove(pl);
                Add(pl);
            }
            var time  = (float)dt.ElapsedGameTime.TotalMilliseconds / 1000f;
            var delta = MouseManager.PositionDelta;

            float       rotationY = 0, rotationX = 0;
            const float rotateDelta = 150f;

            if (delta.X != 0)
            {
                rotationY = delta.X * rotateDelta * time;
            }
            if (delta.Y != 0)
            {
                rotationX = delta.Y * rotateDelta * time;
            }
            _camera.AddHorizontalRotation(rotationY * time / 50f);
            _camera.AddVerticalRotation(rotationX * time / 50f);

            float stepsX = 0, stepsZ = 0, stepsY = 0;
            var   move = KeyboardManager.IsKeyDown(_sprint) ? 1.5f : 0.5f;

            if (KeyboardManager.IsKeyDown(_left))
            {
                stepsX -= move;
            }
            if (KeyboardManager.IsKeyDown(_right))
            {
                stepsX += move;
            }
            if (KeyboardManager.IsKeyDown(_forward))
            {
                stepsZ -= move;
            }
            if (KeyboardManager.IsKeyDown(_backward))
            {
                stepsZ += move;
            }
            if (_camera.Mode == FirstPersonCamera.FirstPersonMode.Plane)
            {
                if (KeyboardManager.IsKeyDown(_up))
                {
                    stepsY += move;
                }
                if (KeyboardManager.IsKeyDown(_down))
                {
                    stepsY -= move;
                }
            }
            _camera.Move(new Vector3(stepsX, stepsY, stepsZ) * time * 30f);

            _camera.Update(dt);
        }