Esempio n. 1
0
        public override void Act(KeyboardState ks, MouseState ms)
        {
            bool runs = false;

            if (CurrentWorld.IsFirstPersonMode && CurrentWorld.GetFirstPersonObject().Equals(this))
            {
                float forward = 0;
                float strafe  = 0;
                if (ks[Key.A])
                {
                    strafe -= 1;
                    runs    = true;
                }
                if (ks[Key.D])
                {
                    strafe += 1;
                    runs    = true;
                }
                if (ks[Key.W])
                {
                    forward += 1;
                    runs     = true;
                }
                if (ks[Key.S])
                {
                    forward -= 1;
                    runs     = true;
                }
                MoveFPSCamera(ms);
                MoveAndStrafeFirstPerson(forward, strafe, 0.1f * KWEngine.DeltaTimeFactor);
                FPSEyeOffset = 5;
                if (ks[Key.Q])
                {
                    MoveOffset(0, -0.2f, 0);
                }
                if (ks[Key.E])
                {
                    MoveOffset(0, +0.2f, 0);
                }
            }
            else
            {
                TurnTowardsXZ(GetMouseIntersectionPoint(ms, Plane.Y));
                Vector3 cameraLookAt = CurrentWorld.GetCameraLookAtVector();
                cameraLookAt.Y = 0;
                cameraLookAt.NormalizeFast();

                Vector3 strafe = HelperRotation.RotateVector(cameraLookAt, 90, Plane.Y);

                if (ks[Key.A])
                {
                    MoveAlongVector(strafe, 0.1f * KWEngine.DeltaTimeFactor);
                    runs = true;
                }
                if (ks[Key.D])
                {
                    MoveAlongVector(strafe, -0.1f * KWEngine.DeltaTimeFactor);
                    runs = true;
                }
                if (ks[Key.W])
                {
                    MoveAlongVector(cameraLookAt, 0.1f * KWEngine.DeltaTimeFactor);
                    runs = true;
                }
                if (ks[Key.S])
                {
                    MoveAlongVector(cameraLookAt, -0.1f * KWEngine.DeltaTimeFactor);
                    runs = true;
                }

                if (ks[Key.T])
                {
                    MoveOffset(0, 0.2f * KWEngine.DeltaTimeFactor, 0);
                }

                if (ks[Key.Q])
                {
                    _height += 0.5f;
                }
                if (ks[Key.E])
                {
                    _height -= 0.5f;
                }
            }

            if (IsMouseCursorInsideMyHitbox(ms))
            {
                SetColorOutline(0, 1, 0, 0.2f);
            }
            else
            {
                SetColorOutline(0, 1, 0, 0);
            }

            /*
             * if (ms.LeftButton == ButtonState.Pressed)
             * {
             *  GameObject o = PickGameObject(ms);
             *  Console.WriteLine(o);
             * }
             */

            MoveOffset(0, -0.1f * KWEngine.DeltaTimeFactor, 0);
            List <Intersection> intersections = GetIntersections();

            foreach (Intersection i in intersections)
            {
                if (i.IsTerrain)
                {
                    Position += i.MTVUp;
                }
                else
                {
                    Position += i.MTV;
                }
            }

            AdjustFlashlight();
            AdjustAnimation(runs, KWEngine.DeltaTimeFactor);

            Vector3 camPos = this.Position + new Vector3(50, _height, 50);

            camPos.Y = _height;
            CurrentWorld.SetCameraPosition(camPos);
            CurrentWorld.SetCameraTarget(Position.X, 0, Position.Z);
        }