コード例 #1
0
        public void Update(GameTime time)
        {
            if (!FullSim)
            {
                UpdatePhysics(time);
                return;
            }

            var keyboardState = Keyboard.GetState();
            var mouseState    = Mouse.GetState();

            var isForward     = GetKeyState(keyboardState, ForwardKeys);
            var isBackward    = GetKeyState(keyboardState, BackwardKeys);
            var isTurnLeft    = GetKeyState(keyboardState, TurnLeftKeys);
            var isTurnRight   = GetKeyState(keyboardState, TurnRightKeys);
            var isStrafeLeft  = GetKeyState(keyboardState, StrafeLeftKeys);
            var isStrafeRight = GetKeyState(keyboardState, StrafeRightKeys);
            var isWalk        = GetKeyState(keyboardState, WalkKeys);
            var isJump        = GetKeyState(keyboardState, JumpKeys);

            var wasForward     = GetKeyState(PrevKeyboardState, ForwardKeys);
            var wasBackward    = GetKeyState(PrevKeyboardState, BackwardKeys);
            var wasTurnLeft    = GetKeyState(PrevKeyboardState, TurnLeftKeys);
            var wasTurnRight   = GetKeyState(PrevKeyboardState, TurnRightKeys);
            var wasStrafeLeft  = GetKeyState(PrevKeyboardState, StrafeLeftKeys);
            var wasStrafeRight = GetKeyState(PrevKeyboardState, StrafeRightKeys);
            var wasWalk        = GetKeyState(PrevKeyboardState, WalkKeys);
            var wasJump        = GetKeyState(PrevKeyboardState, JumpKeys);

            var isLeftClick  = mouseState.LeftButton == ButtonState.Pressed;
            var wasLeftClick = PrevMouseState.LeftButton == ButtonState.Pressed;

            var isRightClick  = mouseState.RightButton == ButtonState.Pressed;
            var wasRightClick = PrevMouseState.RightButton == ButtonState.Pressed;

            if (isForward && !wasForward)
            {
                RunForward(Speed, true);
            }

            if (!isForward && wasForward)
            {
                RunForward(Speed, false);
            }

            if (isBackward && !wasBackward)
            {
                WalkBackward(Speed);
            }

            if (!isBackward && wasBackward)
            {
                WalkBackward(Speed, false);
            }

            if (isTurnLeft && !wasTurnLeft /*|| isMouseLookLeft && !wasMouseLookLeft*/)
            {
                TurnLeft();
            }

            if (!isTurnLeft && wasTurnLeft /*|| !isMouseLookLeft && !isMouseLookRight && wasMouseLookLeft*/)
            {
                TurnLeft(false);
            }

            if (isTurnRight && !wasTurnRight /* || isMouseLookRight && !wasMouseLookRight*/)
            {
                TurnRight();
            }

            if (!isTurnRight && wasTurnRight /* || !isMouseLookRight && !isMouseLookLeft && wasMouseLookRight*/)
            {
                TurnRight(false);
            }

            if (isStrafeLeft && !wasStrafeLeft)
            {
                StrafeLeft();
            }

            if (!isStrafeLeft && wasStrafeLeft)
            {
                StrafeLeft(false);
            }

            if (isStrafeRight && !wasStrafeRight)
            {
                StrafeRight();
            }

            if (!isStrafeRight && wasStrafeRight)
            {
                StrafeRight(false);
            }

            /*if (keyboardState.IsKeyDown(Keys.OemOpenBrackets) && !PrevKeyboardState.IsKeyDown(Keys.OemOpenBrackets))
             * {
             *  CurrentHeightFactor -= 0.025f;
             *
             *  Console.WriteLine($"CurrentHeightFactor: {CurrentHeightFactor}");
             * }
             *
             * if (keyboardState.IsKeyDown(Keys.OemCloseBrackets) && !PrevKeyboardState.IsKeyDown(Keys.OemCloseBrackets))
             * {
             *  CurrentHeightFactor += 0.025f;
             *
             *  Console.WriteLine($"CurrentHeightFactor: {CurrentHeightFactor}");
             * }*/

            if (keyboardState.IsKeyDown(Keys.I) && !PrevKeyboardState.IsKeyDown(Keys.I))
            {
                var ethereal = PhysicsObj.State.HasFlag(PhysicsState.Ethereal);

                ethereal = !ethereal;

                PhysicsObj.set_ethereal(ethereal, true);

                MainWindow.Instance.AddStatusText($"Ethereal: {ethereal}");
            }

            if (isWalk && !wasWalk)
            {
                SetHoldKey(HoldKey.None);
                ApplyRawState();
            }

            if (!isWalk && wasWalk)
            {
                SetHoldKey(HoldKey.Run);
                ApplyRawState();
            }

            if (isRightClick)
            {
                if (wasRightClick)
                {
                    MouseEx.GetCursorPos(out var cursorPos);

                    var diffX = cursorPos.X - (int)LastSetPoint.X;
                    var diffY = cursorPos.Y - (int)LastSetPoint.Y;

                    if (ConfigManager.Config.Mouse.AltMethod)
                    {
                        diffX = mouseState.X - PrevMouseState.X;
                        diffY = mouseState.Y - PrevMouseState.Y;
                    }

                    if (diffX != 0)
                    {
                        var heading = PhysicsObj.get_heading();
                        heading += diffX * MouseSpeedBase * ConfigManager.Config.Mouse.Speed;
                        PhysicsObj.set_heading(heading, false);
                    }

                    if (diffY > 0)
                    {
                        CurrentAngle -= diffY * MouseSpeedBase * ConfigManager.Config.Mouse.Speed;

                        if (CurrentAngle < MaxAngleDown)
                        {
                            CurrentAngle = MaxAngleDown;
                        }

                        //Console.WriteLine($"CurrentAngle: {CurrentAngle}");
                    }
                    else if (diffY < 0)
                    {
                        CurrentAngle -= diffY * MouseSpeedBase * ConfigManager.Config.Mouse.Speed;

                        if (CurrentAngle > MaxAngleUp)
                        {
                            CurrentAngle = MaxAngleUp;
                        }

                        //Console.WriteLine($"CurrentAngle: {CurrentAngle}");
                    }
                }
                else
                {
                    System.Windows.Input.Mouse.OverrideCursor = System.Windows.Input.Cursors.None;
                }

                if (!ConfigManager.Config.Mouse.AltMethod)
                {
                    LastSetPoint = MouseEx.SetCursor(GameView.Instance, Camera.centerX, Camera.centerY);
                }
            }
            else if (wasRightClick)
            {
                if (ConfigManager.Config.Mouse.AltMethod)
                {
                    Mouse.SetCursor(Camera.centerX, Camera.centerY);
                }

                System.Windows.Input.Mouse.OverrideCursor = null;
            }

            if (mouseState.ScrollWheelValue != PrevMouseState.ScrollWheelValue)
            {
                var diff = mouseState.ScrollWheelValue - PrevMouseState.ScrollWheelValue;

                if (diff >= 0)
                {
                    CurrentDist -= 0.5f;
                }
                else
                {
                    CurrentDist += 0.5f;
                }

                //Console.WriteLine($"CurrentDist: {CurrentDist}");
            }

            UpdatePhysics(time);

            if (isLeftClick && !wasLeftClick)
            {
                Picker.HandleLeftClick(mouseState.X, mouseState.Y);
            }

            if (isJump && !wasJump)
            {
                // check if grounded?
                if (PhysicsObj.TransientState.HasFlag(TransientStateFlags.OnWalkable))
                {
                    JumpMeter.Start();

                    var minterp = PhysicsObj.get_minterp();

                    if (PhysicsObj.TransientState.HasFlag(TransientStateFlags.Contact | TransientStateFlags.OnWalkable) && minterp.InterpretedState.ForwardCommand == (uint)MotionCommand.Ready &&
                        minterp.InterpretedState.SideStepCommand == 0 && minterp.InterpretedState.TurnCommand == 0)
                    {
                        minterp.StandingLongJump = true;
                    }
                }
            }

            if (!isJump && wasJump)
            {
                JumpMeter.Stop();

                // check if grounded?
                if (PhysicsObj.TransientState.HasFlag(TransientStateFlags.OnWalkable))
                {
                    // calc velocity
                    PhysicsObj.WeenieObj.InqJumpVelocity(JumpMeter.Percent, out var jumpVelocityZ);

                    var minterp = PhysicsObj.get_minterp();

                    var jumpVelocity = minterp.get_leave_ground_velocity();
                    jumpVelocity.Z = jumpVelocityZ;

                    // perform physics jump
                    PhysicsObj.TransientState &= ~(TransientStateFlags.Contact | TransientStateFlags.WaterContact);
                    PhysicsObj.calc_acceleration();
                    PhysicsObj.set_on_walkable(false);
                    PhysicsObj.set_local_velocity(jumpVelocity, false);
                    minterp.StandingLongJump = false;
                }
            }

            if (JumpMeter.IsCharging)
            {
                JumpMeter.Update();
            }
        }
コード例 #2
0
ファイル: WorldViewer.cs プロジェクト: OptimShi/ACViewer
        public void Update(GameTime time)
        {
            var keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.M) && !PrevKeyboardState.IsKeyDown(Keys.M))
            {
                MapViewer.Instance.Init();
            }

            if (keyboardState.IsKeyDown(Keys.H) && !PrevKeyboardState.IsKeyDown(Keys.H))
            {
                MainMenu.ToggleHUD();
            }

            if (keyboardState.IsKeyDown(Keys.L) && !PrevKeyboardState.IsKeyDown(Keys.L))
            {
                ShowLocation();
            }

            if (!keyboardState.IsKeyDown(Keys.LeftControl) && keyboardState.IsKeyDown(Keys.C) && !PrevKeyboardState.IsKeyDown(Keys.C))
            {
                Picker.ClearSelection();
            }

            if (GameView.ViewMode == ViewMode.World && (keyboardState.IsKeyDown(Keys.P) && !PrevKeyboardState.IsKeyDown(Keys.P) || InitPlayerMode))
            {
                if (!PlayerMode)
                {
                    EnterPlayerMode();
                }
                else
                {
                    ExitPlayerMode();
                }

                InitPlayerMode = false;
            }

            if (keyboardState.IsKeyDown(Keys.D1) && !PrevKeyboardState.IsKeyDown(Keys.D1))
            {
                ACViewer.Render.Buffer.drawTerrain = !ACViewer.Render.Buffer.drawTerrain;
            }

            if (keyboardState.IsKeyDown(Keys.D2) && !PrevKeyboardState.IsKeyDown(Keys.D2))
            {
                ACViewer.Render.Buffer.drawEnvCells = !ACViewer.Render.Buffer.drawEnvCells;
            }

            if (keyboardState.IsKeyDown(Keys.D3) && !PrevKeyboardState.IsKeyDown(Keys.D3))
            {
                ACViewer.Render.Buffer.drawStaticObjs = !ACViewer.Render.Buffer.drawStaticObjs;
            }

            if (keyboardState.IsKeyDown(Keys.D4) && !PrevKeyboardState.IsKeyDown(Keys.D4))
            {
                ACViewer.Render.Buffer.drawBuildings = !ACViewer.Render.Buffer.drawBuildings;
            }

            if (keyboardState.IsKeyDown(Keys.D5) && !PrevKeyboardState.IsKeyDown(Keys.D5))
            {
                ACViewer.Render.Buffer.drawScenery = !ACViewer.Render.Buffer.drawScenery;
            }

            if (keyboardState.IsKeyDown(Keys.D6) && !PrevKeyboardState.IsKeyDown(Keys.D6))
            {
                MainMenu.ToggleParticles();
            }

            if (keyboardState.IsKeyDown(Keys.D7) && !PrevKeyboardState.IsKeyDown(Keys.D7))
            {
                ACViewer.Render.Buffer.drawInstances = !ACViewer.Render.Buffer.drawInstances;
            }

            if (keyboardState.IsKeyDown(Keys.D8) && !PrevKeyboardState.IsKeyDown(Keys.D8))
            {
                ACViewer.Render.Buffer.drawEncounters = !ACViewer.Render.Buffer.drawEncounters;
            }

            if (keyboardState.IsKeyDown(Keys.D0) && !PrevKeyboardState.IsKeyDown(Keys.D0))
            {
                ACViewer.Render.Buffer.drawAlpha = !ACViewer.Render.Buffer.drawAlpha;
            }

            if (keyboardState.IsKeyDown(Keys.LeftControl) && keyboardState.IsKeyDown(Keys.V) && !PrevKeyboardState.IsKeyDown(Keys.V))
            {
                Picker.AddVisibleCells();
            }

            if (keyboardState.IsKeyDown(Keys.LeftControl) && keyboardState.IsKeyDown(Keys.C) && !PrevKeyboardState.IsKeyDown(Keys.C))
            {
                Picker.ShowCollision();
            }

            if (GameView.ViewMode == ViewMode.World && PlayerMode && Player != null)
            {
                Player.Update(time);
            }
            else if (Camera != null)
            {
                Camera.Update(time);
            }

            Render.UpdateEmitters();

            Server.Update();

            if (PerfTimer.Update())
            {
                //Console.WriteLine($"NumParticles: {ACViewer.Render.Render.NumParticlesThisFrame}, ParticleTextures: {ACViewer.Render.Render.ParticleTexturesThisFrame.Count}");
            }
        }