private void FireKeyboardEvents()
        {
            foreach (Keys key in KeyList)
            {
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    if (OnKeyDown != null)
                    {
                        OnKeyDown(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }

                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    if (OnKeyUp != null)
                    {
                        OnKeyUp(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }

                if (PrevKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key))
                {
                    if (OnKeyPressed != null)
                    {
                        OnKeyPressed(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }
            }
        }
Example #2
0
        private void FireKeyboardEvents()
        {
            foreach (var key in KeyList)
            {
                // Is the key currently down?
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    // Fire the OnKeyDown event
                    if (OnKeyDown != null)
                    {
                        OnKeyDown(this, new KeyboardEventArgs(key, CurrentKeyboardState,
                                                              PrevKeyboardState));
                    }
                }

                // Has the key been released? (Was down and is now up)
                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    // Fire the OnKeyUp event
                    if (OnKeyUp != null)
                    {
                        OnKeyUp(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }

                // Has the key been pressed? (Was up and is now down)
                if (PrevKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key))
                {
                    if (OnKeyPressed != null)
                    {
                        OnKeyPressed(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }
            }
        }
Example #3
0
        private void FireKeyboardEvents()
        {
            // Check through each key in the key list
            foreach (Keys key in KeyList)
            {
                // Is the key currently down?
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    // Fire the OnKeyDown event
                    OnKeyDown?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                }

                // Has the key been released? (Was down and is now up)
                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    OnKeyUp?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                }

                // Has the key been pressed? (Was up and is now down)
                if (PrevKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key))
                {
                    OnKeyPressed?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                }
            }
        }
Example #4
0
        private void FireKeyboardEvents(GameTime gameTime)
        {
            foreach (var key in _keyList)
            {
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    OnKeyDown?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState, gameTime));
                }

                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    OnKeyUp?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState, gameTime));
                }
            }
        }
Example #5
0
        //
        // Events that should be fired based on the interaction/input received

        private void FireKeyboardEvents()
        {
            foreach (Keys key in KeyList)
            {
                // Is key currently down?
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    OnKeyDown?.Invoke(key);
                }

                // Has the key been released?
                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    OnKeyUp?.Invoke(key);
                }

                // Key has been held
                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyDown(key))
                {
                    OnKeyPressed?.Invoke(key);
                }
            }
        }
Example #6
0
        public void Update(GameTime time)
        {
            if (ViewObject != null)
            {
                ViewObject.Update(time);
            }

            if (Camera != null)
            {
                Camera.Update(time);
            }

            var keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.OemPeriod) && !PrevKeyboardState.IsKeyDown(Keys.OemPeriod))
            {
                PolyIdx++;
                Console.WriteLine($"PolyIdx: {PolyIdx}");
            }
            if (keyboardState.IsKeyDown(Keys.OemComma) && !PrevKeyboardState.IsKeyDown(Keys.OemComma))
            {
                PolyIdx--;
                Console.WriteLine($"PolyIdx: {PolyIdx}");
            }

            if (keyboardState.IsKeyDown(Keys.OemQuestion) && !PrevKeyboardState.IsKeyDown(Keys.OemQuestion))
            {
                PartIdx++;
                Console.WriteLine($"PartIdx: {PartIdx}");
            }
            if (keyboardState.IsKeyDown(Keys.M) && !PrevKeyboardState.IsKeyDown(Keys.M))
            {
                PartIdx--;
                Console.WriteLine($"PartIdx: {PartIdx}");
            }
        }
        /// <summary>
        /// Update the camera's physics
        /// </summary>
        /// <param name="gameTime">GameTime from the main game.</param>
        public void Update(GameTime gameTime)
        {
            //Delta time
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

            CurrentMouseState    = Mouse.GetState();
            CurrentKeyboardState = Keyboard.GetState();

            Vector3 moveVector = Vector3.Zero;

            if (CurrentKeyboardState.IsKeyUp(Keys.Escape) && PrevKeyboardState.IsKeyDown(Keys.Escape))
            {
                Client.Paused = !Client.Paused;
            }

            if (!Client.Paused)
            {
                if (CurrentKeyboardState.IsKeyDown(Keys.W))
                {
                    moveVector.Z = 1; //cameraSpeed * dt;
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.S))
                {
                    moveVector.Z = -1; //cameraSpeed * dt;
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.A))
                {
                    moveVector.X = 1;// cameraSpeed* dt;
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.D))
                {
                    moveVector.X = -1;//cameraSpeed * dt;
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.R))
                {
                    MoveTo(Client.MainWorld.Spawn.ToRenderCoords(), Vector3.Zero);
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.Q))
                {
                    moveVector.Y = 1;
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.E))
                {
                    moveVector.Y = -1;
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.Space) && !IsJumping)
                {
                    moveVector.Y = 12;
                    IsJumping    = true;
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.Enter))
                {
                    Client.MainWorld[Vector3I.Zero] = Client.MainWorld[Vector3I.Zero];
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.NumPad3))
                {
                    PluginManager.Reload();
                }
                if (CurrentKeyboardState.IsKeyUp(Keys.F) && PrevKeyboardState.IsKeyDown(Keys.F))
                {
                    DistanceIndex++;
                    if (DistanceIndex >= Distances.Length)
                    {
                        DistanceIndex = 0;
                    }

                    FarDistance      = Distances[DistanceIndex];
                    ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                        MathHelper.PiOver4,
                        Client.Viewport.AspectRatio,
                        NearDistance,
                        FarDistance);
                }
            }


            // Gravity
            //UpdateGravity(gameTime);

            if (moveVector != Vector3.Zero) // If we moved
            {
                // We must normalize the vector (make it of unit length (1))
                //moveVector.Normalize();
                // Now add in our camera speed and delta time
                moveVector *= MovementSpeed * dt;
                Move(moveVector);
                //Vector3 testVector = moveVector;
                //testVector.Normalize();
                //testVector = testVector * (moveVector.Length() + 0.3f);

                //Vector3I testPos = PreviewMove(testVector).ToBlockCoords();
                //Vector3I bodyPos = PreviewMove(testVector - new Vector3(0, Player.Height, 0)).ToBlockCoords();

                //if (!Client.MainWorld[testPos].Solid() || !Client.MainWorld[bodyPos].Solid())
                //{
                //    Vector3I newLoc = PreviewMove(moveVector).ToBlockCoords();
                //    if (Client.MainWorld.InBounds(newLoc))
                //    {
                //        if (!Client.MainWorld[newLoc].Solid())
                //            Move(moveVector); // Now we move the camera using that movement vector
                //    }
                //}
            }

            // Now try applying gravity
            Vector3 gravityVector = Vector3.Zero;

            gravityVector.Y += Gravity;

            gravityVector *= dt;

            // Add the player's eye level.
            Vector3  vectorWithFeet = new Vector3(gravityVector.X, gravityVector.Y - Player.EyeLevel, gravityVector.Z);
            Vector3  gravLoc        = PreviewMove(vectorWithFeet);
            Vector3I worldLoc       = gravLoc.ToBlockCoords();

            if (Client.MainWorld.InBounds(worldLoc))
            {
                if (Client.MainWorld[worldLoc].Solid())
                {
                    if (IsJumping)
                    {
                        IsJumping = false;
                    }
                }
                else
                {
                    Move(gravityVector);
                }
            }
            if (!Client.Paused)
            {
                //Change in mouse position
                //x and y
                float deltaX;
                float deltaY;

                //Handle mouse movement
                if (CurrentMouseState != PrevMouseState)
                {
                    //Get the change in mouse position
                    deltaX = CurrentMouseState.X - (Client.Viewport.Width / 2);
                    deltaY = CurrentMouseState.Y - (Client.Viewport.Height / 2);

                    //This is used to buffer against use input.
                    MouseRotationBuffer.X -= MouseSpeed * deltaX * dt;
                    MouseRotationBuffer.Y -= MouseSpeed * deltaY * dt;
                    if (MouseRotationBuffer.Y < MathHelper.ToRadians(-75.0f))
                    {
                        MouseRotationBuffer.Y = MouseRotationBuffer.Y - (MouseRotationBuffer.Y - MathHelper.ToRadians(-75.0f));
                    }
                    if (MouseRotationBuffer.Y > MathHelper.ToRadians(90.0f))
                    {
                        MouseRotationBuffer.Y = MouseRotationBuffer.Y - (MouseRotationBuffer.Y - MathHelper.ToRadians(90.0f));
                    }


                    Rotation = new Vector3(-MathHelper.Clamp(MouseRotationBuffer.Y, MathHelper.ToRadians(-75.0f),
                                                             MathHelper.ToRadians(90.0f)), MathHelper.WrapAngle(MouseRotationBuffer.X), 0);

                    deltaX = 0;
                    deltaY = 0;
                }

                Mouse.SetPosition(Client.GameWindow.ClientBounds.Width / 2, Client.GameWindow.ClientBounds.Height / 2);
            }
            PrevMouseState    = CurrentMouseState;
            PrevKeyboardState = CurrentKeyboardState;
        }
Example #8
0
 public bool KeyReleased(Keys i_Key)
 {
     return(PrevKeyboardState.IsKeyDown(i_Key) && KeyboardState.IsKeyUp(i_Key));
 }
Example #9
0
 public bool KeyHeld(Keys i_Key)
 {
     return(KeyboardState.IsKeyDown(i_Key) && PrevKeyboardState.IsKeyDown(i_Key));
 }
Example #10
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();
            }
        }
Example #11
0
 /// <summary>
 /// Checks if the key is released this tick but not the last.
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static bool IsKeyReleased(Keys key)
 {
     return(KeyboardState.IsKeyUp(key) && PrevKeyboardState.IsKeyDown(key));
 }
Example #12
0
        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}");
            }
        }
Example #13
0
        public void Update()
        {
            //Update keyboard states
            PrevKeyboardState    = CurrentKeyboardState;
            CurrentKeyboardState = Keyboard.GetState();
            //Update mouse states
            PrevMouseState    = CurrentMouseState;
            CurrentMouseState = Mouse.GetState();

            foreach (var key in KeySet)
            {
                var isDown  = CurrentKeyboardState.IsKeyDown(key);
                var wasDown = PrevKeyboardState.IsKeyDown(key);

                if (isDown)//Key is down
                {
                    //Key is currently held
                    OnKeyHeld?.Invoke(this, new KeyEventArgs(key));

                    if (!wasDown)//Key has just been pressed
                    {
                        OnKeyDown?.Invoke(this, new KeyEventArgs(key));
                    }
                }
                else  //Key is not down
                {
                    if (wasDown)//Key has just been released
                    {
                        OnKeyUp?.Invoke(this, new KeyEventArgs(key));
                    }
                }
            }

            foreach (var button in ButtonSet)
            {
                bool isDown  = false;
                bool wasDown = false;

                switch (button)
                {
                case MouseButton.left:
                {
                    isDown  = CurrentMouseState.LeftButton == ButtonState.Pressed;
                    wasDown = PrevMouseState.LeftButton == ButtonState.Pressed;
                }
                break;

                case MouseButton.right:
                {
                    isDown  = CurrentMouseState.RightButton == ButtonState.Pressed;
                    wasDown = PrevMouseState.RightButton == ButtonState.Pressed;
                }
                break;

                default:
                    break;
                }

                if (isDown)//Button is down
                {
                    OnMouseButtonHeld?.Invoke(this, new MouseEventArgs(button, CurrentMouseState));

                    if (!wasDown)//Button has just been pressed
                    {
                        OnMouseButtonDown?.Invoke(this, new MouseEventArgs(button, CurrentMouseState));
                    }
                }
                else
                {                //Button is not down
                    if (wasDown) //Button has just been released
                    {
                        OnMouseButtonUp?.Invoke(this, new MouseEventArgs(button, CurrentMouseState));
                    }
                }
            }
        }
Example #14
0
 public bool WasKeyPressed(Keys key)
 {
     return(PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key));
 }