Esempio n. 1
0
        public void UpdatePosition(GameTime time)
        {
            soundPlayer.UpdateVolume();

            colChecker.CheckDistance(avatarPosition);
            #region Camera Rotation
            if (input.IsKeyDown(Keys.Left))
            {
                avatarYaw += rotationSpeed;                            // Rotate left.
            }
            if (input.IsKeyDown(Keys.Right))
            {
                avatarYaw -= rotationSpeed;                             // Rotate right.
            }
            if (input.RightStick.X != 0)
            {
                avatarYaw -= input.RightStick.X * rotationSpeed;
            }
            if (input.RightStick.Y != 0)
            {
                avatarPitch += input.RightStick.Y * rotationSpeed;
                if (Math.Abs(avatarPitch) > 0.3)
                {
                    avatarPitch = currentavatarPitch;
                }

                currentavatarPitch = avatarPitch;
            }
            #endregion

            if (input.IsKeyDown(Keys.W) || input.LeftStick.Y > 0.5f)
            {
                Matrix forwardMovement = Matrix.CreateRotationZ(avatarYaw);
                v = new Vector3(0, forwardSpeed, 0);
                v = Vector3.Transform(v, forwardMovement);

                avatarPosition.Y += v.Y;
                avatarPosition.X += v.X;
                if (XrayMode)
                {
                    if (colChecker.CheckCollision(avatarPosition))
                    {
                        avatarPosition.Y -= v.Y;
                        avatarPosition.X -= v.X;
                        soundPlayer.PlaySoundEffect("collideins");
                    }
                }
            }
            if (input.IsKeyDown(Keys.S) || input.LeftStick.Y < 0f)
            {
                Matrix forwardMovement = Matrix.CreateRotationZ(avatarYaw);
                v = new Vector3(0, -forwardSpeed, 0);
                v = Vector3.Transform(v, forwardMovement);


                avatarPosition.Y += v.Y;
                avatarPosition.X += v.X;
                if (XrayMode)
                {
                    if (colChecker.CheckCollision(avatarPosition))
                    {
                        avatarPosition.Y -= v.Y;
                        avatarPosition.X -= v.X;
                        soundPlayer.PlaySoundEffect("collideins");
                    }
                }
            }
            if (input.IsKeyDown(Keys.A) || input.LeftStick.X < 0f)
            {
                Matrix forwardMovement = Matrix.CreateRotationZ(avatarYaw);
                v = new Vector3(-forwardSpeed, 0, 0);
                v = Vector3.Transform(v, forwardMovement);

                avatarPosition.Y += v.Y;
                avatarPosition.X += v.X;

                if (XrayMode)
                {
                    if (colChecker.CheckCollision(avatarPosition))
                    {
                        avatarPosition.Y -= v.Y;
                        avatarPosition.X -= v.X;
                        soundPlayer.PlaySoundEffect("collideins");
                    }
                }
            }
            if (input.IsKeyDown(Keys.D) || input.LeftStick.X > 0f)
            {
                Matrix forwardMovement = Matrix.CreateRotationZ(avatarYaw);
                v = new Vector3(forwardSpeed, 0, 0);
                v = Vector3.Transform(v, forwardMovement);
                avatarPosition.Y += v.Y;
                avatarPosition.X += v.X;

                if (XrayMode)
                {
                    if (colChecker.CheckCollision(avatarPosition))
                    {
                        avatarPosition.Y -= v.Y;
                        avatarPosition.X -= v.X;
                        soundPlayer.PlaySoundEffect("collideins");
                    }
                }
            }

            if (input.IsKeyDown(Keys.W) || input.IsKeyDown(Keys.S) || input.IsKeyDown(Keys.D) || input.IsKeyDown(Keys.A) ||
                input.LeftStick.Y > 0.5f || input.LeftStick.Y < 0f || input.LeftStick.X < 0f || input.LeftStick.X > 0f)
            {
                stepCounter += (int)(Math.Sqrt(Math.Pow(v.Y, 2) + Math.Pow(v.X, 2)) * 100);
            }

            if (input.IsKeyTapped(Keys.X) || input.IsButtonTapped(Buttons.Y))
            {
                XrayMode = !XrayMode;
            }


            if (input.IsKeyDown(Keys.Z) || input.IsButtonDown(Buttons.B))
            {
                if (view.ZoomFactor > 0.1)
                {
                    view.ZoomFactor -= 0.1f;
                }
            }
            else if ((input.IsKeyDown(Keys.Z) && input.IsKeyDown(Keys.LeftShift)) || input.IsKeyDown(Keys.C) || input.IsButtonDown(Buttons.A))
            {
                if (view.ZoomFactor < 2)
                {
                    view.ZoomFactor += 0.1f;
                }
            }
            if (input.IsKeyDown(Keys.Home) || input.IsButtonTapped(Buttons.Start))
            {
                avatarPosition  = new Vector3(-3, 2, 0);
                view.ZoomFactor = MathHelper.PiOver4;
                avatarYaw       = -1.6f;
                avatarPitch     = 0;
            }

            if (input.IsKeyTapped(Keys.L) || input.IsButtonTapped(Buttons.LeftShoulder))
            {
                night = !night;
                if (night)
                {
                    soundPlayer.StopMusic();
                    soundPlayer.LoopMusic("BG2");
                }
                else
                {
                    soundPlayer.StopMusic();
                    soundPlayer.LoopMusic("BG1");
                }
            }

            if (input.IsKeyTapped(Keys.G) || input.IsButtonTapped(Buttons.RightShoulder))
            {
                fog = !fog;

                effect.Parameters["FogEnabled"].SetValue(!effect.Parameters["FogEnabled"].GetValueBoolean());
            }

            if (input.IsKeyTapped(Keys.F) || input.IsButtonTapped(Buttons.RightTrigger))
            {
                effect.Parameters["FlashLightOn"].SetValue(!effect.Parameters["FlashLightOn"].GetValueBoolean());
            }

            if (input.IsKeyTapped(Keys.M) || input.IsButtonTapped(Buttons.LeftTrigger))
            {
                soundPlayer.PauseMusic();
            }
            if (stepCounter % 13 <= 0 && stepCounter > 10)
            {
                soundPlayer.PlaySoundEffect("footstepins");
            }
        }