Exemplo n.º 1
0
        public void Update(object sender, UpdateData data)
        {
            MultiState
                newState = new MultiState(),
                oldState = _inputState;

            List <GameInputs> gameInputs = Util.GetValues <GameInputs>();

            for (int i = 0; i < gameInputs.Count; ++i)
            {
                GameInputs
                    gameInput = gameInputs[i];

                if (!_inputMap.Keys.Contains(gameInput))
                {
                    continue;
                }

                MultiInput input = _inputMap[gameInput];

                bool
                    isDown  = newState.IsDown(input),
                    wasDown = oldState.IsDown(input);

                if (isDown && !wasDown)
                {
                    if (PressedEvent != null)
                    {
                        PressedEvent(this, new InputData(gameInput));
                    }
                }
                else if (!isDown && wasDown)
                {
                    if (ReleasedEvent != null)
                    {
                        ReleasedEvent(this, new InputData(gameInput));
                    }
                }

                if (isDown)
                {
                    if (HeldEvent != null)
                    {
                        HeldEvent(this, new InputData(gameInput));
                    }
                }
            }

            _inputState = newState;
        }
Exemplo n.º 2
0
        public void Update(object sender, UpdateData data)
        {
            MultiState
                newState = new MultiState(),
                oldState = _inputState;

            List<GameInputs> gameInputs = Util.GetValues<GameInputs>();

            for (int i = 0; i < gameInputs.Count; ++i)
            {
                GameInputs
                    gameInput = gameInputs[i];

                if (!_inputMap.Keys.Contains(gameInput))
                    continue;

                MultiInput input = _inputMap[gameInput];

                bool
                    isDown = newState.IsDown(input),
                    wasDown = oldState.IsDown(input);

                if (isDown && !wasDown)
                {
                    if (PressedEvent != null)
                        PressedEvent(this, new InputData(gameInput));
                }
                else if (!isDown && wasDown)
                {
                    if (ReleasedEvent != null)
                        ReleasedEvent(this, new InputData(gameInput));
                }

                if (isDown)
                {
                    if (HeldEvent != null)
                        HeldEvent(this, new InputData(gameInput));
                }
            }

            _inputState = newState;
        }