public Input() { _inputState = new MultiState(); Core.UpdateEvent += new UpdateEventHandler(Update); _inputMap = new Dictionary <GameInputs, MultiInput>(); //_inputMap.Add(GameInputs.Exit, new MultiInput(Buttons.Back)); // //_inputMap.Add(GameInputs.Up, new MultiInput(Buttons.DPadUp)); //_inputMap.Add(GameInputs.Left, new MultiInput(Buttons.DPadLeft)); //_inputMap.Add(GameInputs.Down, new MultiInput(Buttons.DPadDown)); //_inputMap.Add(GameInputs.Right, new MultiInput(Buttons.DPadRight)); // //_inputMap.Add(GameInputs.Jump, new MultiInput(Buttons.A)); // //_inputMap.Add(GameInputs.Fire, new MultiInput(Buttons.LeftShoulder)); _inputMap.Add(GameInputs.Exit, new MultiInput(Keys.Escape)); _inputMap.Add(GameInputs.Up, new MultiInput(Keys.W)); _inputMap.Add(GameInputs.Left, new MultiInput(Keys.A)); _inputMap.Add(GameInputs.Down, new MultiInput(Keys.S)); _inputMap.Add(GameInputs.Right, new MultiInput(Keys.D)); _inputMap.Add(GameInputs.Jump, new MultiInput(Keys.Space)); _inputMap.Add(GameInputs.Fire, new MultiInput(MouseButtons.Left)); _inputMap.Add(GameInputs.Debug1, new MultiInput(Keys.D1)); _inputMap.Add(GameInputs.Debug2, new MultiInput(Keys.D2)); _inputMap.Add(GameInputs.Debug3, new MultiInput(Keys.D3)); }
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; }
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; }
public Input() { _inputState = new MultiState(); Core.UpdateEvent += new UpdateEventHandler(Update); _inputMap = new Dictionary<GameInputs, MultiInput>(); //_inputMap.Add(GameInputs.Exit, new MultiInput(Buttons.Back)); // //_inputMap.Add(GameInputs.Up, new MultiInput(Buttons.DPadUp)); //_inputMap.Add(GameInputs.Left, new MultiInput(Buttons.DPadLeft)); //_inputMap.Add(GameInputs.Down, new MultiInput(Buttons.DPadDown)); //_inputMap.Add(GameInputs.Right, new MultiInput(Buttons.DPadRight)); // //_inputMap.Add(GameInputs.Jump, new MultiInput(Buttons.A)); // //_inputMap.Add(GameInputs.Fire, new MultiInput(Buttons.LeftShoulder)); _inputMap.Add(GameInputs.Exit, new MultiInput(Keys.Escape)); _inputMap.Add(GameInputs.Up, new MultiInput(Keys.W)); _inputMap.Add(GameInputs.Left, new MultiInput(Keys.A)); _inputMap.Add(GameInputs.Down, new MultiInput(Keys.S)); _inputMap.Add(GameInputs.Right, new MultiInput(Keys.D)); _inputMap.Add(GameInputs.Jump, new MultiInput(Keys.Space)); _inputMap.Add(GameInputs.Fire, new MultiInput(MouseButtons.Left)); _inputMap.Add(GameInputs.Debug1, new MultiInput(Keys.D1)); _inputMap.Add(GameInputs.Debug2, new MultiInput(Keys.D2)); _inputMap.Add(GameInputs.Debug3, new MultiInput(Keys.D3)); }